用于快速语义信息的 VSCode 扩展

发布于 2025-01-20 17:48:53 字数 538 浏览 2 评论 0原文

我被用来指向鼠标并获取有关Visual Studio代码中某些参考的信息。

在这里,一个示例,使用JavaScript,我将鼠标指向函数参考,并获取有关函数签名的信息。

我想拥有与其他文件相似的东西。

例如

,以以下示例为例,以一种不流行的语言,

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

我如何编写一个扩展名,当我将鼠标指向参数时,它会在框中显示声明,最好使用编辑器中显示的具有相同的语法亮点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-01-27 17:48:53

现在有一个带有示例的拉取请求 vscode-extension-samples

基本上你必须写这样的东西

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);
}

并在 package.json 上定义语言和激活事件

{

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

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"
                ]
            }
        ]
    },
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文