fixed extension configs
This commit is contained in:
parent
2d1efd339e
commit
bdb615876d
3 changed files with 89 additions and 23 deletions
2
.vscode/extensions.json
vendored
2
.vscode/extensions.json
vendored
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher", "ms-vscode.extension-test-runner"]
|
"recommendations": ["dbaeumer.vscode-eslint"]
|
||||||
}
|
}
|
||||||
|
|
59
package.json
59
package.json
|
@ -20,7 +20,64 @@
|
||||||
"main": "./dist/extension.js",
|
"main": "./dist/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
]
|
],
|
||||||
|
"configuration": {
|
||||||
|
"title": "Ai Code",
|
||||||
|
"properties": {
|
||||||
|
"aiCode.ollamaHost": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "host for ollama",
|
||||||
|
"default": "http://localhost:11434"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.enable": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "should auto complete be enabled",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.model": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"default": "deepseek-coder:6.7b"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.prefixStart": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"default": "<prefixStart>"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.prefixEnds": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"default": "<prefixStart>,</prefixStart>,<prefixEnd>,</prefixEnd>"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.suffixStart": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"default": "<suffixStart>"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.suffixEnd": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "",
|
||||||
|
"default": "</suffixStart>"
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.maxTokens": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "",
|
||||||
|
"default": 50,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.generationTimeout": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "",
|
||||||
|
"default": 200,
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"aiCode.inlineCompletion.triePruneTimeout": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "",
|
||||||
|
"default": 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run package",
|
"vscode:prepublish": "npm run package",
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { Ollama } from 'ollama/browser';
|
import { Ollama } from 'ollama/browser';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
const CONFIG_NAMESPACE = 'ai-code';
|
const CONFIG_NAMESPACE = 'aiCode';
|
||||||
|
|
||||||
const KEY_OLLAMA_HOST = 'ollamaHost';
|
const KEY_OLLAMA_HOST = 'ollamaHost';
|
||||||
|
|
||||||
|
const KEY_INLINE_COMPLETION_ENABLE = 'inlineCompletion.enable';
|
||||||
const KEY_INLINE_COMPLETION_MODEL = 'inlineCompletion.model';
|
const KEY_INLINE_COMPLETION_MODEL = 'inlineCompletion.model';
|
||||||
const KEY_INLINE_COMPLETION_PREFIX_START = 'inlineCompletion.prefixStart';
|
const KEY_INLINE_COMPLETION_PREFIX_START = 'inlineCompletion.prefixStart';
|
||||||
const KEY_INLINE_COMPLETION_PREFIX_END = 'inlineCompletion.prefixEnd';
|
const KEY_INLINE_COMPLETION_PREFIX_END = 'inlineCompletion.prefixEnd';
|
||||||
|
@ -14,9 +15,11 @@ const KEY_INLINE_COMPLETION_MAX_TOKENS = 'inlineCompletion.maxTokens';
|
||||||
const KEY_INLINE_COMPLETION_GENERATION_TIMEOUT = 'inlineCompletion.generationTimeout';
|
const KEY_INLINE_COMPLETION_GENERATION_TIMEOUT = 'inlineCompletion.generationTimeout';
|
||||||
const KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT = 'inlineCompletion.triePruneTimeout';
|
const KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT = 'inlineCompletion.triePruneTimeout';
|
||||||
|
|
||||||
|
const DEFAULT_OLLAMA_HOST = 'http://localhost:11434';
|
||||||
|
const DEFAULT_INLINE_COMPLETION_ENABLE = true;
|
||||||
const DEFAULT_INLINE_COMPLETION_MODEL = 'deepseek-coder:6.7b';
|
const DEFAULT_INLINE_COMPLETION_MODEL = 'deepseek-coder:6.7b';
|
||||||
const DEFAULT_INLINE_COMPLETION_PREFIX_START = '<prefixStart>';
|
const DEFAULT_INLINE_COMPLETION_PREFIX_START = '<prefixStart>';
|
||||||
const DEFAULT_INLINE_COMPLETION_PREFIX_ENDS = ['<prefixStart>', '</prefixStart>', '<prefixEnd>', '</prefixEnd>'];
|
const DEFAULT_INLINE_COMPLETION_PREFIX_ENDS = ['<prefixStart>', '</prefixStart>', '<prefixEnd>', '</prefixEnd>'].join();
|
||||||
const DEFAULT_INLINE_COMPLETION_SUFFIX_START = '<suffixStart>';
|
const DEFAULT_INLINE_COMPLETION_SUFFIX_START = '<suffixStart>';
|
||||||
const DEFAULT_INLINE_COMPLETION_SUFFIX_END = '</suffixStart>';
|
const DEFAULT_INLINE_COMPLETION_SUFFIX_END = '</suffixStart>';
|
||||||
const DEFAULT_INLINE_COMPLETION_MAX_TOKENS = 50;
|
const DEFAULT_INLINE_COMPLETION_MAX_TOKENS = 50;
|
||||||
|
@ -24,8 +27,9 @@ const DEFAULT_INLINE_COMPLETION_GENERATION_TIMEOUT = 200;
|
||||||
const DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT = 10000;
|
const DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT = 10000;
|
||||||
|
|
||||||
interface ExtensionConfiguration {
|
interface ExtensionConfiguration {
|
||||||
ollamaHost: string | undefined
|
ollamaHost: string
|
||||||
inlineCompletion: {
|
inlineCompletion: {
|
||||||
|
enable: boolean
|
||||||
model: string
|
model: string
|
||||||
prefixStart: string
|
prefixStart: string
|
||||||
prefixEnds: string[]
|
prefixEnds: string[]
|
||||||
|
@ -46,16 +50,17 @@ export const getExtensionState = (): ExtensionState => {
|
||||||
const extensionConfig = vscode.workspace.getConfiguration(CONFIG_NAMESPACE);
|
const extensionConfig = vscode.workspace.getConfiguration(CONFIG_NAMESPACE);
|
||||||
|
|
||||||
const configuration: ExtensionConfiguration = {
|
const configuration: ExtensionConfiguration = {
|
||||||
ollamaHost: extensionConfig.get(KEY_OLLAMA_HOST),
|
ollamaHost: extensionConfig.get(KEY_OLLAMA_HOST, DEFAULT_OLLAMA_HOST),
|
||||||
inlineCompletion: {
|
inlineCompletion: {
|
||||||
model: extensionConfig.get(KEY_INLINE_COMPLETION_MODEL) ?? DEFAULT_INLINE_COMPLETION_MODEL,
|
enable: extensionConfig.get(KEY_INLINE_COMPLETION_ENABLE, DEFAULT_INLINE_COMPLETION_ENABLE),
|
||||||
prefixStart: extensionConfig.get(KEY_INLINE_COMPLETION_PREFIX_START) ?? DEFAULT_INLINE_COMPLETION_PREFIX_START,
|
model: extensionConfig.get(KEY_INLINE_COMPLETION_MODEL, DEFAULT_INLINE_COMPLETION_MODEL),
|
||||||
prefixEnds: extensionConfig.get<string>(KEY_INLINE_COMPLETION_PREFIX_END)?.split(',') ?? DEFAULT_INLINE_COMPLETION_PREFIX_ENDS,
|
prefixStart: extensionConfig.get(KEY_INLINE_COMPLETION_PREFIX_START, DEFAULT_INLINE_COMPLETION_PREFIX_START),
|
||||||
suffixStart: extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_START) ?? DEFAULT_INLINE_COMPLETION_SUFFIX_START,
|
prefixEnds: extensionConfig.get<string>(KEY_INLINE_COMPLETION_PREFIX_END, DEFAULT_INLINE_COMPLETION_PREFIX_ENDS)?.split(',').map((value) => value.trim()),
|
||||||
suffixEnd: extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_END) ?? DEFAULT_INLINE_COMPLETION_SUFFIX_END,
|
suffixStart: extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_START, DEFAULT_INLINE_COMPLETION_SUFFIX_START),
|
||||||
maxTokens: extensionConfig.get(KEY_INLINE_COMPLETION_MAX_TOKENS) ?? DEFAULT_INLINE_COMPLETION_MAX_TOKENS,
|
suffixEnd: extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_END, DEFAULT_INLINE_COMPLETION_SUFFIX_END),
|
||||||
generationTimeout: extensionConfig.get(KEY_INLINE_COMPLETION_GENERATION_TIMEOUT) ?? DEFAULT_INLINE_COMPLETION_GENERATION_TIMEOUT,
|
maxTokens: extensionConfig.get(KEY_INLINE_COMPLETION_MAX_TOKENS, DEFAULT_INLINE_COMPLETION_MAX_TOKENS),
|
||||||
triePruneTimeout: extensionConfig.get(KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT) ?? DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT,
|
generationTimeout: extensionConfig.get(KEY_INLINE_COMPLETION_GENERATION_TIMEOUT, DEFAULT_INLINE_COMPLETION_GENERATION_TIMEOUT),
|
||||||
|
triePruneTimeout: extensionConfig.get(KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT, DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,42 +74,46 @@ export const getExtensionState = (): ExtensionState => {
|
||||||
|
|
||||||
vscode.workspace.onDidChangeConfiguration((event) => {
|
vscode.workspace.onDidChangeConfiguration((event) => {
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_OLLAMA_HOST}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_OLLAMA_HOST}`)) {
|
||||||
configuration.ollamaHost = extensionConfig.get(KEY_OLLAMA_HOST);
|
configuration.ollamaHost = extensionConfig.get(KEY_OLLAMA_HOST, DEFAULT_OLLAMA_HOST);
|
||||||
state.ollama = new Ollama({
|
state.ollama = new Ollama({
|
||||||
host: configuration.ollamaHost,
|
host: configuration.ollamaHost,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_ENABLE}`)) {
|
||||||
|
configuration.inlineCompletion.enable = extensionConfig.get(KEY_INLINE_COMPLETION_ENABLE, DEFAULT_INLINE_COMPLETION_ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_MODEL}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_MODEL}`)) {
|
||||||
configuration.inlineCompletion.model = extensionConfig.get(KEY_INLINE_COMPLETION_MODEL) ?? DEFAULT_INLINE_COMPLETION_MODEL;
|
configuration.inlineCompletion.model = extensionConfig.get(KEY_INLINE_COMPLETION_MODEL, DEFAULT_INLINE_COMPLETION_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_PREFIX_START}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_PREFIX_START}`)) {
|
||||||
configuration.inlineCompletion.prefixStart = extensionConfig.get(KEY_INLINE_COMPLETION_PREFIX_START) ?? DEFAULT_INLINE_COMPLETION_PREFIX_START;
|
configuration.inlineCompletion.prefixStart = extensionConfig.get(KEY_INLINE_COMPLETION_PREFIX_START, DEFAULT_INLINE_COMPLETION_PREFIX_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_PREFIX_END}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_PREFIX_END}`)) {
|
||||||
configuration.inlineCompletion.prefixEnds = extensionConfig.get<string>(KEY_INLINE_COMPLETION_PREFIX_END)?.split(',') ?? DEFAULT_INLINE_COMPLETION_PREFIX_ENDS;
|
configuration.inlineCompletion.prefixEnds = extensionConfig.get<string>(KEY_INLINE_COMPLETION_PREFIX_END, DEFAULT_INLINE_COMPLETION_PREFIX_ENDS)?.split(',').map((value) => value.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_SUFFIX_START}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_SUFFIX_START}`)) {
|
||||||
configuration.inlineCompletion.suffixStart = extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_START) ?? DEFAULT_INLINE_COMPLETION_SUFFIX_START;
|
configuration.inlineCompletion.suffixStart = extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_START, DEFAULT_INLINE_COMPLETION_SUFFIX_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_SUFFIX_END}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_SUFFIX_END}`)) {
|
||||||
configuration.inlineCompletion.suffixEnd = extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_END) ?? DEFAULT_INLINE_COMPLETION_SUFFIX_END;
|
configuration.inlineCompletion.suffixEnd = extensionConfig.get(KEY_INLINE_COMPLETION_SUFFIX_END, DEFAULT_INLINE_COMPLETION_SUFFIX_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_MAX_TOKENS}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_MAX_TOKENS}`)) {
|
||||||
configuration.inlineCompletion.maxTokens = extensionConfig.get(KEY_INLINE_COMPLETION_MAX_TOKENS) ?? DEFAULT_INLINE_COMPLETION_MAX_TOKENS;
|
configuration.inlineCompletion.maxTokens = extensionConfig.get(KEY_INLINE_COMPLETION_MAX_TOKENS, DEFAULT_INLINE_COMPLETION_MAX_TOKENS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_GENERATION_TIMEOUT}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_GENERATION_TIMEOUT}`)) {
|
||||||
configuration.inlineCompletion.generationTimeout = extensionConfig.get(KEY_INLINE_COMPLETION_GENERATION_TIMEOUT) ?? DEFAULT_INLINE_COMPLETION_GENERATION_TIMEOUT;
|
configuration.inlineCompletion.generationTimeout = extensionConfig.get(KEY_INLINE_COMPLETION_GENERATION_TIMEOUT, DEFAULT_INLINE_COMPLETION_GENERATION_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT}`)) {
|
if (event.affectsConfiguration(`${CONFIG_NAMESPACE}.${KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT}`)) {
|
||||||
configuration.inlineCompletion.triePruneTimeout = extensionConfig.get(KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT) ?? DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT;
|
configuration.inlineCompletion.triePruneTimeout = extensionConfig.get(KEY_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT, DEFAULT_INLINE_COMPLETION_TRIE_PRUNE_TIMEOUT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue