我正在使用一种通常具有非常大且难以导航的文件的语言,因此我希望能够随时看到自己所在的函数,因为这通常是最大的困扰(向上翻页约20次以找到当前函数名称,然后向下翻页)。
我知道可以编写扩展程序通过注册文档符号提供程序来列出所有函数。但在深入研究之前,我想知道是否有一种自动且持续地在轮廓视图中显示哪个节点代表代码编辑器中的当前位置的某种指示方式。 如果没有,我可能需要创建自己的树视图(这会有这种功能吗?)。
我正在使用一种通常具有非常大且难以导航的文件的语言,因此我希望能够随时看到自己所在的函数,因为这通常是最大的困扰(向上翻页约20次以找到当前函数名称,然后向下翻页)。
我知道可以编写扩展程序通过注册文档符号提供程序来列出所有函数。但在深入研究之前,我想知道是否有一种自动且持续地在轮廓视图中显示哪个节点代表代码编辑器中的当前位置的某种指示方式。 如果没有,我可能需要创建自己的树视图(这会有这种功能吗?)。
TreeView.reveal()
。这里是我使用的代码link1,可以在当前源编辑器中根据插入符号位置选择操作列表中的条目。public update(editor: TextEditor) {
let position = editor.selection.active;
let action = Utils.findInListFromPosition(this.actions, position.character, position.line + 1);
if (action) {
this.actionTree.reveal(action, { select: true });
return;
}
let predicate = Utils.findInListFromPosition(this.predicates, position.character, position.line + 1);
if (predicate) {
this.actionTree.reveal(predicate, { select: true });
return;
}
}
这个方法是从主扩展文件中注册的选择更改事件调用的:
window.onDidChangeTextEditorSelection((event: TextEditorSelectionChangeEvent) => {
if (event.textEditor.document.languageId === "antlr" && event.textEditor.document.uri.scheme === "file") {
...
actionsProvider.update(event.textEditor);
}
});
registerDocumentSymbolProvider
解决方案一起使用的解决方案吗,还是我需要自己的registerTreeDataProvider
? - BlueMonkMN currentBlock
的变量中,其中包括 symbolInformation
,当我遇到例如方法的第一行(从正则表达式返回的匹配对象)时创建的。currentBlock.symbolInformation = new vscode.SymbolInformation(
match[1],
vscode.SymbolKind.Method,
className,
new vscode.Location(document.uri,
new vscode.Position(lineNum, line.firstNonWhitespaceCharacterIndex)));
当我走到这个区块的末尾时,我会将之前存储的数据与剩余信息结合起来,并将其推送到SymbolInformation[]
结果中。
private popBlock(document: vscode.TextDocument, lineNum: number, currentBlock: IndentInfo): vscode.SymbolInformation | undefined {
if (currentBlock.symbolInformation !== undefined) {
currentBlock.symbolInformation = new vscode.SymbolInformation(
currentBlock.symbolInformation.name,
currentBlock.symbolInformation.kind,
currentBlock.symbolInformation.containerName,
new vscode.Location(
currentBlock.symbolInformation.location.uri,
new vscode.Range(
currentBlock.symbolInformation.location.range.start,
new vscode.Position(lineNum-1, document.lineAt(lineNum-1).text.length)
)
)
);
return currentBlock.symbolInformation;
}
}