Compare commits

...

1 commit

Author SHA1 Message Date
igardev
f7fe67ea3d Fix code completion in case max_parallel_completions = 1 or empty. 2026-01-07 18:37:59 +02:00
4 changed files with 21 additions and 64 deletions

View file

@ -74,10 +74,6 @@
"command": "extension.askAi",
"title": "llama-vscode: Ask AI"
},
{
"command": "extension.askAiWithContext",
"title": "llama-vscode: Ask AI With Context"
},
{
"command": "extension.editSelectedText",
"title": "llama-vscode: Edit Selected Text with AI"
@ -186,11 +182,6 @@
"key": "ctrl+;",
"when": "editorTextFocus"
},
{
"command": "extension.askAiWithContext",
"key": "ctrl+Shift+;",
"when": "editorTextFocus"
},
{
"command": "extension.askAiWithTools",
"key": "ctrl+Shift+t",

View file

@ -128,19 +128,9 @@ export class ChatWithAi {
// console.log("onDidReceiveMessage: " + message.text);
}
});
// Wait for the page to load before sending message
if (query) extraCont += await this.prepareRagContext(query);
setTimeout(async () => {
if (aiPanel) aiPanel.webview.postMessage({ command: 'setText', text: queryToSend, context: extraCont });
}, Math.max(0, 3000 - (Date.now() - createWebviewTimeInMs)));
} else {
aiPanel.reveal();
this.lastActiveEditor = editor;
if (query) extraCont += await this.prepareRagContext(query);
// Wait for the page to load before sending message
setTimeout(async () => {
if (aiPanel) aiPanel.webview.postMessage({ command: 'setText', text: queryToSend, context: extraCont });
}, 500);
}
}
@ -157,46 +147,12 @@ export class ChatWithAi {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self' https: http: data: blob: 'unsafe-inline' 'unsafe-eval';
connect-src 'self' https: http: ws: wss:;
frame-src 'self' https: http:;">
<title>llama.cpp server UI</title>
<script>
// Initialize the VS Code API
const vscode = acquireVsCodeApi();
vscode.postMessage({ command: 'jsAction', text: 'vscode javascript object created' });
// Listen for messages from the extension
window.addEventListener('message', (event) => {
vscode.postMessage({ command: 'jsAction', text: 'message received' });
const { command, text, context } = event.data; // Extract the command and text from the event
if (command === 'setText') {
vscode.postMessage({ command: 'jsAction', text: 'command setText received' });
const iframe = document.getElementById('askAiIframe');
if (iframe) {
vscode.postMessage({ command: 'jsAction', text: 'askAiIframe obtained' });
iframe.contentWindow.postMessage({ command: 'setText', text: text, context: context }, '*');
vscode.postMessage({ command: 'jsAction', text: text });
}
}
if (command === 'escapePressed') {
vscode.postMessage({ command: 'jsAction', text: 'command escape pressed' });
vscode.postMessage({ command: 'escapePressed' });
}
if (command === 'jsAction') {
vscode.postMessage({ command: 'jsAction', text: text });
}
});
// Listen for key events in the iframe
window.addEventListener('keydown', (event) => {
vscode.postMessage({ command: 'jsAction', text: 'keydown event received' });
if (event.key === 'Escape') {
// Send a message to the extension when Escape is pressed
vscode.postMessage({ command: 'escapePressed', text: "" });
vscode.postMessage({ command: 'jsAction', text: "Escabe key pressed..." });
}
});
</script>
<style>
body, html {
margin: 0;
@ -213,7 +169,7 @@ export class ChatWithAi {
</style>
</head>
<body>
<iframe src="${url}" id="askAiIframe"></iframe>
<iframe src="${url}" sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals" id="askAiIframe"></iframe>
</body>
</html>
`;

View file

@ -91,6 +91,7 @@ export class Completion {
let newCompletions: string[] = []
let firstComplLines: string[] = []
for (let compl of completions){
let suggestionLines = compl.split(/\r?\n/)
Utils.removeTrailingNewLines(suggestionLines);
@ -357,7 +358,7 @@ export class Completion {
private getComplFromContent(codeCompletions: any): string[] | undefined {
if ("content" in codeCompletions)
return codeCompletions.content??""
return [codeCompletions.content??""]
if (codeCompletions.length > 0){
let completions: Set<string> = new Set()
@ -368,7 +369,15 @@ export class Completion {
}
else return [];
}
// Function for printing the first n Fibonachi numbers
private getMaxNumber(numbers: number[]): number {
let max = 0;
for (const num of numbers) {
if (num > max) {
max = num;
}
}
return max;
}
}

View file

@ -711,7 +711,8 @@ export const PREDEFINED_LISTS = new Map<string, any>([
"delete_file",
"get_diff",
"edit_file",
"ask_user"
"ask_user",
"update_todo_list"
]
},
{