Asmir 🍉Original post
Rank 1: Thread
Hello guys i'm havint my snippets on my appwrite database i wish to build my extension to use them i'm having an issue
JavaScript
const htmlConsoleCompletionProvider = vscode.languages.registerCompletionItemProvider( "html", { provideCompletionItems: async function (document: vscode.TextDocument, position: vscode.Position): Promise<any> { const activeEditor = vscode.window.activeTextEditor; if (!activeEditor) return new vscode.CompletionList([], true); const { text } = activeEditor.document.lineAt(activeEditor.selection.active.line);
try { const matchingSnippets = (await callToAPIAndRetrieve(text)) as any[];
const completionItems = matchingSnippets.map((snippet: any) => { return { label: snippet.label, kind: vscode.CompletionItemKind.Snippet, documentation: snippet.description, insertText: new vscode.SnippetString(snippet.value), }; }); return new vscode.CompletionList(completionItems, true); } catch (error) { console.error("Error retrieving snippets:", error); return new vscode.CompletionList([], true); } }, }, "" );Everythink works fine if the html file is empty but if i'm inside a html tag like or inside of
Markup
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body> </body></html>It doesn't do anybody knows why ?
Summary
Issue with vscode provideCompletionItems when the HTML file is not empty. Developers are encountering problems with snippets retrieval within html tags.
Solution: Check the text context within the HTML tag for snippet retrieval, as the issue might arise from there.