summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorMartin Bielik <martin.bielik@instea.sk>2024-12-17 18:43:51 +0100
committerMartin Bielik <martin.bielik@instea.sk>2024-12-17 18:43:51 +0100
commit8402371e6af33dcf6962ffbc8cd73be0e36f6812 (patch)
tree21086a322a0901e9b3ea66e1da318377960808dd /py
parent44625c9d77f6c44f1a4623402cada772dfaf6f9f (diff)
downloadvim-ai-8402371e6af33dcf6962ffbc8cd73be0e36f6812.tar.gz
introduced pre-defined default roles
Diffstat (limited to 'py')
-rw-r--r--py/context.py7
-rw-r--r--py/roles.py8
-rw-r--r--py/utils.py11
3 files changed, 13 insertions, 13 deletions
diff --git a/py/context.py b/py/context.py
index 50fa170..2644bae 100644
--- a/py/context.py
+++ b/py/context.py
@@ -74,12 +74,7 @@ def parse_role_section(role):
return result
def load_role_config(role):
- roles_config_path = os.path.expanduser(vim.eval("g:vim_ai_roles_config_file"))
- if not os.path.exists(roles_config_path):
- raise Exception(f"Role config file does not exist: {roles_config_path}")
-
- roles = configparser.ConfigParser()
- roles.read(roles_config_path)
+ roles = read_role_files()
roles = dict(roles)
enhance_roles_with_custom_function(roles)
diff --git a/py/roles.py b/py/roles.py
index 692ac6c..94bcdb4 100644
--- a/py/roles.py
+++ b/py/roles.py
@@ -7,13 +7,7 @@ if "PYTEST_VERSION" in os.environ:
roles_py_imported = True
def load_ai_role_names(command_type):
- roles_config_path = os.path.expanduser(vim.eval("g:vim_ai_roles_config_file"))
- if not os.path.exists(roles_config_path):
- raise Exception(f"Role config file does not exist: {roles_config_path}")
-
- roles = configparser.ConfigParser()
- roles.read(roles_config_path)
-
+ roles = read_role_files()
enhance_roles_with_custom_function(roles)
role_names = set()
diff --git a/py/utils.py b/py/utils.py
index ce95ed6..89bef3e 100644
--- a/py/utils.py
+++ b/py/utils.py
@@ -317,3 +317,14 @@ def make_chat_text_chunks(messages, config_options):
map_chunk = map_chunk_stream if openai_options['stream'] else map_chunk_no_stream
return map(map_chunk, response)
+
+def read_role_files():
+ plugin_root = vim.eval("s:plugin_root")
+ default_roles_config_path = str(os.path.join(plugin_root, "roles-default.ini"))
+ roles_config_path = os.path.expanduser(vim.eval("g:vim_ai_roles_config_file"))
+ if not os.path.exists(roles_config_path):
+ raise Exception(f"Role config file does not exist: {roles_config_path}")
+
+ roles = configparser.ConfigParser()
+ roles.read([default_roles_config_path, roles_config_path])
+ return roles