VSCode 快速语义信息扩展
VSCode extension for quick semantic info
我习惯于在 Visual studio 代码中将鼠标指向并获取有关某些引用的信息。
这是一个示例,使用 Javascript,我将鼠标指向一个函数引用,然后我获得了有关函数签名的信息。
我想要和其他文件类似的东西。
例如
举下面的例子,用一种不太流行的语言
module top #(
parameter NB=4
);
logic [NB /*I would like info here */ -1:0] b;
endmodule
我如何编写一个扩展,当我将鼠标指向参数时,它会在框中显示声明,最好使用与编辑器中显示的相同的语法突出显示。
现在有一个带有示例的拉取请求 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"
]
}
]
},
}
我习惯于在 Visual studio 代码中将鼠标指向并获取有关某些引用的信息。
这是一个示例,使用 Javascript,我将鼠标指向一个函数引用,然后我获得了有关函数签名的信息。
我想要和其他文件类似的东西。
例如
举下面的例子,用一种不太流行的语言
module top #(
parameter NB=4
);
logic [NB /*I would like info here */ -1:0] b;
endmodule
我如何编写一个扩展,当我将鼠标指向参数时,它会在框中显示声明,最好使用与编辑器中显示的相同的语法突出显示。
现在有一个带有示例的拉取请求 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"
]
}
]
},
}