Typescript Vscode在指定行使用showTextDocument打开文件
我希望我的扩展能够在某一行打开文档。有没有办法扩展下面的代码,让文件在光标位于第4列第10行时打开?我已经看到了如何使用超链接,但我想知道是否有办法导航到扩展名中的文件Typescript Vscode在指定行使用showTextDocument打开文件,typescript,visual-studio-code,vscode-extensions,Typescript,Visual Studio Code,Vscode Extensions,我希望我的扩展能够在某一行打开文档。有没有办法扩展下面的代码,让文件在光标位于第4列第10行时打开?我已经看到了如何使用超链接,但我想知道是否有办法导航到扩展名中的文件 var openPath = vscode.Uri.file(filePath); vscode.workspace.openTextDocument(openPath).then(doc => { vscode.window.showTextDocument(doc); }); 可能是这样,这是一个固定值,但
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc => {
vscode.window.showTextDocument(doc);
});
可能是这样,这是一个固定值,但您可以传入或计算范围并显示位置
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc => {
vscode.window.showTextDocument(doc).then(editor => {
var range = new vscode.Range(new vscode.Position(10, 4), new vscode.Position(11, 0));
editor.revealRange(range);
})
});
可能是这样,这是一个固定值,但您可以传入或计算范围并显示位置
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc => {
vscode.window.showTextDocument(doc).then(editor => {
var range = new vscode.Range(new vscode.Position(10, 4), new vscode.Position(11, 0));
editor.revealRange(range);
})
});
@ddavid456提供了我需要的大部分答案,当我在下面的块中添加一行时,我得到了我需要的全部功能
var pos1 = new vscode.Position(10,4);
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc =>
{
vscode.window.showTextDocument(doc).then(editor =>
{
// Line added - by having a selection at the same position twice, the cursor jumps there
editor.selections = [new vscode.Selection(pos1,pos1)];
// And the visible range jumps there too
var range = new vscode.Range(pos1, pos1);
editor.revealRange(range);
});
});
@ddavid456提供了我需要的大部分答案,当我在下面的块中添加一行时,我得到了我需要的全部功能
var pos1 = new vscode.Position(10,4);
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc =>
{
vscode.window.showTextDocument(doc).then(editor =>
{
// Line added - by having a selection at the same position twice, the cursor jumps there
editor.selections = [new vscode.Selection(pos1,pos1)];
// And the visible range jumps there too
var range = new vscode.Range(pos1, pos1);
editor.revealRange(range);
});
});
这会在范围的常规区域打开文件,但是否有方法将光标也放在该区域,或选择范围?放置光标不确定,但可以选择范围
editor.selection=新建vscode.selection(range.start,range.end)
在RevealRange之前有一个用于showTextDocument
的选项参数。这将在范围的常规区域中打开文件,但是是否有方法将光标也放在那里,或者选择范围?放置光标不确定,但可以选择范围editor.selection=新建vscode.selection(range.start,range.end)代码>就在RevealRange之前有一个用于showTextDocument
的选项参数。