typescript - Vscode在指定行使用showTextDocument打开文件
问题描述
我希望我的扩展程序能够在某一行打开文档。有没有办法扩展下面的代码,用光标在第 10 行第 4 列打开文件?我已经看到如何使用超链接完成此操作,但我想知道是否有一种方法可以导航到扩展名中的文件。
var openPath = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(openPath).then(doc => {
vscode.window.showTextDocument(doc);
});
解决方案
@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);
});
});
推荐阅读
- performance - Haskell中不重复字符的最长子串的性能
- powershell - 从powershell将变量传递给命令提示符有问题吗?
- javascript - 安装 CORS 后烧瓶服务器出错:AttributeError:“FlaskApp”对象没有属性“after_request”
- node.js - PUT API 请求返回 JSON 正文错误
- mongodb - Mongoose Model.update() 没有效果
- html - 图标没有以任何方式出现
- flutter - 计划外的应用栏
- ios - FetchedResults 不会触发和 SwiftUI 更新但上下文成功保存它
- fatal-error - 如何解决“线程 1:致命错误:No ObservableObject of type,,”崩溃消息
- arrays - 字符串数组中未终止的字符串文字错误 - Swift