I am creating a VS Code extension in which I wish to implement the feature of showing the suggested code as ghost text which is inline on the text editor and the user may press Tab to confirm/add the code.
The following is the code for VS Code extension and my VS Code version is 1.83.1.
const vscode = require('vscode');/** * @param {vscode.ExtensionContext} context */function activate(context) { // Register the completion item provider context.subscriptions.push( vscode.languages.registerCompletionItemProvider( { scheme: "file", language: "javascript" }, { provideCompletionItems: (document, position, token, context) => { // Check if the trigger string is being typed const linePrefix = document.lineAt(position).text.substr(0, position.character); if (!linePrefix.endsWith("myTriggerString")) { return undefined; } // Create a completion item for the ghost text const suggestion = new vscode.CompletionItem("myGhostText"); suggestion.kind = vscode.CompletionItemKind.Snippet; suggestion.insertText = new vscode.SnippetString("console.log('Hello, World!');"); suggestion.detail = "Inserts a console.log statement with 'Hello, World!' as the message."; return [suggestion]; }, },"m" ) );}function deactivate() { }module.exports = { activate, deactivate}
However when I run the extension using vs code and write myTriggerString, nothing is getting suggested. Any ideas what can be the issue? The feature needs to be similar to what github copilot or other AI tools exhibit for code completion.