'Custom VSCode Editor, how to activate?

I want to develop a vscode extension to edit "csv-like" files with a specific format, with lines for definitions (akind to headers with "variable names") and lines for data.

I have already succeded in making the syntax (tmLanguage.json), but now I would like to be able to click on a data item and see what variable it relates to.

I know I must provide a registerDefinitionProvider, so my extension.js is like this:

async function activate(context) {

    console.log('Congratulations, your extension "visfile" is now active!');

    context.subscriptions.push(
        vscode.languages.registerDefinitionProvider(
            {language: "visfile"}, new VisDocumentDefinitionProvider()));
}

class VisDocumentDefinitionProvider extends vscode.DefinitionProvider {

    provideDefinition(textDocument, position, token) {
        return new Promise((resolve) => {
            console.log(textDocument);
            console.log(position);
            return new Location(Uri.parse(''), position);
        });
    }
}

function deactivate() {}

module.exports = {
    activate,
    deactivate
}

However, my activate function never gets called, since I never see the message nor does it stop at a breakpoint.

My package.json is like this:

{
    "name": "visfile",
    "displayName": "VisFile",
    "publisher": "oliviergeorg",
    "description": "VSCode editor extension for .vis files",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.66.0"
    },
    "categories": [
        "Programming Languages"
    ],
    "activationEvents": [
        "onLanguage:visfile"
    ],
    "main": "./extension.js",
    "contributes": {
        "languages": [
            {
                "id": "visfile",
                "aliases": [
                    "Vis Data File",
                    "visfile"
                ],
                "extensions": [
                    ".vis"
                ],
                "configuration": "./language-configuration.json"
            }
        ],
        "grammars": [
            {
                "language": "visfile",
                "scopeName": "text.vis",
                "path": "./syntaxes/visfile.tmLanguage.json"
            }
        ]
    }
}

What am I doing wrong?... Also I cannot find a good tutorial for the implementation of such providers, most information I find is about implementation of commands or just reference material...



Solution 1:[1]

Thanks rioV8, that lead me to the solution. I thought I would see the trace in some output window, but it appears in the DevTools which I did not even know it existed! The problem was actually in 2 parts. First an import was missing (vscode) and secondly, the VisDocumentDefinitionProvider extends vscode.DefinitionProvider was not working. So now my extension.js looks like this:

const vscode = require('vscode');

async function activate(context) {

    console.log('Congratulations, your extension "visfile" is now active!');

    context.subscriptions.push(
        vscode.languages.registerDefinitionProvider(
            {language: "visfile"}, 
            {
                provideDefinition(textDocument, position, token) {
                    return new Promise((resolve) => {
                        console.log(textDocument);
                        console.log(position);
                        return new Location(Uri.parse(''), position);
                    });
                }
            }
    ));
}

function deactivate() {}

module.exports = {
    activate,
    deactivate
}

This way I get a "Go to definition" in the constext menu, although it does nothing else.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Olivier Georg