Back

vscode provideCompletionItems

  • 0
  • Self Hosted
Asmir 🍉
10 Jun, 2024, 17:58

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

TypeScript
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 <span></span> or inside of

TypeScript
<!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 ?

TL;DR
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.
Asmir 🍉
10 Jun, 2024, 17:58
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more