1

I've tried so many variations of this from code I found on github using the provideInlineCompletionItems function but cannot seem to get it to work. Is there something I am doing wrong?

const vscode = require('vscode');

function activate(context) {
    const provider = {
        provideInlineCompletionItems: async (document, position, context, token) => {
            const txt = 'hi'
            return [
                {
                    text: txt,
                    insertText: txt,
                    range:new vscode.Range(position.translate(0, txt.length), position)
                }
            ]
        },
    };
    vscode.languages.registerInlineCompletionItemProvider({pattern: "**"}, provider);
}
exports.activate = activate;

function deactivate() {}

module.exports = {
    activate,
    deactivate
};

Even with https://github.com/microsoft/vscode/issues/125663 and "editor.inlineSuggest.enabled": true, set to true it doesn't work. I know inline suggestions works since I have github copilot, I just can't seem to get it to work. Copilot is also disabled so they don't interfere

2
  • first get the completion example working Commented Dec 14, 2022 at 8:27
  • @rioV8 yeah I tried, it doesn't work. this is not much more I can think of to do, it should be a simple process Commented Dec 14, 2022 at 13:20

1 Answer 1

1

I rollbacked a version of VSCode and it works now. this is the debug code I used.

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

    // Use the console to output diagnostic information (console.log) and errors (console.error)
    // This line of code will only be executed once when your extension is activated
    console.log('Congratulations, your extension "seven" is now active!');

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with  registerCommand
    // The commandId parameter must match the command field in package.json
    let disposable = vscode.commands.registerCommand('seven.helloWorld', function () {
        // The code you place here will be executed every time your command is executed

        // Display a message box to the user
        vscode.window.showInformationMessage('Hello World from seven!');
    });

    const provider = {
        provideInlineCompletionItems: async (document, position, context, token) => {
            const line = document.lineAt(position.line);
            console.log("420")
            if (line.text.startsWith('if')) {
                console.log("421")
                let range = line.range;
                if (line.text.indexOf(";") !== -1) {
                    console.log("423")
                    range = new vscode.Range(range.start, range.end.with(undefined, line.text.indexOf(";") + 1));
                }
                console.log("424")

                return [{ text: 'if (hello) {\n};', insertText: "if (hello)", range }];
            }
        }
    };

    vscode.languages.registerInlineCompletionItemProvider({ pattern: '**' }, provider);

    context.subscriptions.push(disposable);

    
}

// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
    activate,
    deactivate
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.