Joh*_*ars 5 visual-studio-code vscode-extensions
我在 VS Code 中有一个专门的 WebView 扩展,用于生成 .Net 类。这些文件是通过外部命令行工具生成的。命令行工具提供的功能之一是它以 JSON 格式写入特定文件,即生成的文件的位置。我在这个特定文件上设置了一个文件观察器,以便每当它更新时,我都会运行一个扩展方法来解析该 json 文件,从 json 中提取文件路径,然后在 VS Code 中打开该文件。
虽然这有效,但我的目的是在拆分编辑器中打开此文件,这样一侧显示我的 WebView (html),另一侧显示刚刚打开的文件(又名,谁的路径来自JSON 文件如上所述)。
如何在分割窗口的另一侧打开文件,同时保持我的 webview ext. 一侧视图和另一侧显示新打开的文件?
我的工作是这样的:它可以打开文件,但不能在分割视图编辑器中打开
// uri points to the file to read JSON from
let fileUri: vscode.Uri = vscode.Uri.file(uri.fsPath);
// read JSON from relative path of this file
fss.readFile(fileUri.fsPath, 'utf8', function (err, data)
{
if(!err) {
try{
// parse the data read from file as JSON
var jsonObj = JSON.parse(data);
try{
// create uri from path within json
let fileToOpenUri: vscode.Uri = vscode.Uri.file(jsonObj.path);
// open and show the file inside VS code editor
vscode.window.showTextDocument(fileToOpenUri);
}
catch(ex)
{
// handle file Open error
vscode.window.showErrorMessage(ex);
}
}
catch(ex)
{
// handle JSON Parse error
vscode.window.showErrorMessage(ex);
}
}
else
{
// handle file read error
vscode.window.showErrorMessage(err.message);
}
});
Run Code Online (Sandbox Code Playgroud)
想要将文件打开到分割视图的另一侧。
vscode.window.showTextDocument(document, {
viewColumn: vscode.ViewColumn.Beside
});
Run Code Online (Sandbox Code Playgroud)
https://code.visualstudio.com/api/references/vscode-api#TextDocumentShowOptions
https://code.visualstudio.com/api/references/vscode-api#ViewColumn
归档时间: |
|
查看次数: |
2829 次 |
最近记录: |