'VSCode extension for quick semantic info

I am used to point the mouse and get information about certain references in Visual studio code.

Here one example, using Javascript, I point the mouse to a function reference and I get information about the function signature.

enter image description here

I would like to have something similar to other files.

e.g.

Take the following example, in a less popular language

module top #(
  parameter NB=4
);
  logic [NB /*I would like info here */ -1:0] b; 
endmodule

How can I write an extension that when I point the mouse to the parameter it shows me the the declaration in a box, preferably with the same syntax highlight as it is shown in the editor.



Solution 1:[1]

Now there is a pull request with a sample to vscode-extension-samples.

Basically you have to write something like this

import * as vscode from 'vscode';

class SimpleHoverProvider implements vscode.HoverProvider {
    public provideHover(
        document: vscode.TextDocument, 
        position: vscode.Position, 
        token: vscode.CancellationToken
    ): vscode.Hover | null {
        return new vscode.Hover(`${location.line}: ${location.character}`);
        // return null; if there is no information to show
    }
}

export function activate(context: vscode.ExtensionContext) {
    // 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, hover-provider-sample extension is active!');
    const hoverProvider = new SimpleHoverProvider();
    vscode.languages.registerHoverProvider('text', hoverProvider);
}

And define languages and activation events on package.json

{

    "activationEvents": [
        "onLanguage:text",
        "onLanguage:report"
    ],
    "contributes": {
        "languages": [
            {
                "id": "text",
                "extensions": [
                    ".txt"
                ]
            },
            {
                "id": "report",
                "extensions": [
                    ".rpt"
                ]
            }
        ]
    },
}

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 Bob