Skip to content

Commit 411fae3

Browse files
committed
doc: lua-ify the init_options object in nvim example
1 parent d75b0d6 commit 411fae3

File tree

1 file changed

+79
-27
lines changed

1 file changed

+79
-27
lines changed

examples/nvim/init.lua

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,95 @@ vim.g.mapleader = " "
33
vim.g.maplocalleader = "\\"
44

55
-- The init_options
6-
-- It is important we parse it as json or `"file_store": {}` will be interpreted as an array when it should be an object
7-
local lsp_ai_init_options_json = [[
8-
{
9-
"memory": {
10-
"file_store": {}
6+
local lsp_ai_init_options = {
7+
memory = {
8+
file_store = vim.fn.empty_dict()
119
},
12-
"models": {
13-
"model1": {
14-
"type": "anthropic",
15-
"chat_endpoint": "https://api.anthropic.com/v1/messages",
16-
"model": "claude-3-5-sonnet-20240620",
17-
"auth_token_env_var_name": "ANTHROPIC_API_KEY"
10+
models = {
11+
model1 = {
12+
type = "anthropic",
13+
chat_endpoint = "https://api.anthropic.com/v1/messages",
14+
model = "claude-3-5-sonnet-20240620",
15+
auth_token_env_var_name = "ANTHROPIC_API_KEY"
1816
}
1917
},
20-
"actions": [
18+
actions = {
2119
{
22-
"trigger": "!C",
23-
"action_display_name": "Chat",
24-
"model": "model1",
25-
"parameters": {
26-
"max_context": 4096,
27-
"max_tokens": 4096,
28-
"system": "You are an AI coding assistant. Your task is to complete code snippets. The user's cursor position is marked by \"<CURSOR>\". Follow these steps:\n\n1. Analyze the code context and the cursor position.\n2. Provide your chain of thought reasoning, wrapped in <reasoning> tags. Include thoughts about the cursor position, what needs to be completed, and any necessary formatting.\n3. Determine the appropriate code to complete the current thought, including finishing partial words or lines.\n4. Replace \"<CURSOR>\" with the necessary code, ensuring proper formatting and line breaks.\n5. Wrap your code solution in <answer> tags.\n\nYour response should always include both the reasoning and the answer. Pay special attention to completing partial words or lines before adding new lines of code.\n\n<examples>\n<example>\nUser input:\n--main.py--\n# A function that reads in user inpu<CURSOR>\n\nResponse:\n<reasoning>\n1. The cursor is positioned after \"inpu\" in a comment describing a function that reads user input.\n2. We need to complete the word \"input\" in the comment first.\n3. After completing the comment, we should add a new line before defining the function.\n4. The function should use Python's built-in `input()` function to read user input.\n5. We'll name the function descriptively and include a return statement.\n</reasoning>\n\n<answer>t\ndef read_user_input():\n user_input = input(\"Enter your input: \")\n return user_input\n</answer>\n</example>\n\n<example>\nUser input:\n--main.py--\ndef fibonacci(n):\n if n <= 1:\n return n\n else:\n re<CURSOR>\n\n\nResponse:\n<reasoning>\n1. The cursor is positioned after \"re\" in the 'else' clause of a recursive Fibonacci function.\n2. We need to complete the return statement for the recursive case.\n3. The \"re\" already present likely stands for \"return\", so we'll continue from there.\n4. The Fibonacci sequence is the sum of the two preceding numbers.\n5. We should return the sum of fibonacci(n-1) and fibonacci(n-2).\n</reasoning>\n\n<answer>turn fibonacci(n-1) + fibonacci(n-2)</answer>\n</example>\n</examples>\n",
29-
"messages": [
20+
trigger = "!C",
21+
action_display_name = "Chat",
22+
model = "model1",
23+
parameters = {
24+
max_context = 4096,
25+
max_tokens = 4096,
26+
system = [[
27+
You are an AI coding assistant. Your task is to complete code snippets. The user's cursor position is marked by \"<CURSOR>\". Follow these steps:
28+
29+
1. Analyze the code context and the cursor position.
30+
2. Provide your chain of thought reasoning, wrapped in <reasoning> tags. Include thoughts about the cursor position, what needs to be completed, and any necessary formatting.
31+
3. Determine the appropriate code to complete the current thought, including finishing partial words or lines.
32+
4. Replace \"<CURSOR>\" with the necessary code, ensuring proper formatting and line breaks.
33+
5. Wrap your code solution in <answer> tags.
34+
35+
Your response should always include both the reasoning and the answer. Pay special attention to completing partial words or lines before adding new lines of code.
36+
37+
<examples>
38+
<example>
39+
User input:
40+
--main.py--
41+
# A function that reads in user inpu<CURSOR>
42+
43+
Response:
44+
<reasoning>
45+
1. The cursor is positioned after \"inpu\" in a comment describing a function that reads user input.
46+
2. We need to complete the word \"input\" in the comment first.
47+
3. After completing the comment, we should add a new line before defining the function.
48+
4. The function should use Python's built-in `input()` function to read user input.
49+
5. We'll name the function descriptively and include a return statement.
50+
</reasoning>
51+
52+
<answer>t
53+
def read_user_input():
54+
user_input = input(\"Enter your input: \")
55+
return user_input
56+
</answer>
57+
</example>
58+
59+
<example>
60+
User input:
61+
--main.py--
62+
def fibonacci(n):
63+
if n <= 1:
64+
return n
65+
else:
66+
re<CURSOR>
67+
68+
69+
Response:
70+
<reasoning>
71+
1. The cursor is positioned after \"re\" in the 'else' clause of a recursive Fibonacci function.
72+
2. We need to complete the return statement for the recursive case.
73+
3. The \"re\" already present likely stands for \"return\", so we'll continue from there.
74+
4. The Fibonacci sequence is the sum of the two preceding numbers.
75+
5. We should return the sum of fibonacci(n-1) and fibonacci(n-2).
76+
</reasoning>
77+
78+
<answer>turn fibonacci(n-1) + fibonacci(n-2)</answer>
79+
</example>
80+
</examples>
81+
]],
82+
messages = {
3083
{
31-
"role": "user",
32-
"content": "{CODE}"
84+
role = "user",
85+
content = "{CODE}"
3386
}
34-
]
87+
}
3588
},
36-
"post_process": {
37-
"extractor": "(?s)<answer>(.*?)</answer>"
89+
post_process = {
90+
extractor = "(?s)<answer>(.*?)</answer>"
3891
}
3992
}
40-
]
93+
}
4194
}
42-
]]
4395

4496
-- The easiest way to configure the language server is to use the nvim-lspconfig plugin: https://github.com/neovim/nvim-lspconfig
4597
-- Use the following snippet to configure it after installing it with the plugin manager of your choice.

0 commit comments

Comments
 (0)