我正在尝试使用webview进行VS代码扩展。我想从其他目录(/CSS/index.css)导入样式表。
这是我的程序结构。
markmap-vscode
├─.vscode
├─CSS
│ ├─ index.css
│ └─ mindmap.css
├─examples
├─node_modules
├─src
│ └─ extension.js
...下面是extenstion.js的一部分,当我运行这个命令(markmap-vscode.startWebview)时,它返回TypeError: Cannot read property 'extensionPath。但是其他VS代码API工作得很好,我读到vscode.ExtensionContext.extensionPath给出了扩展路径,但是在这段代码中,VS代码找不到ExtensionContext的属性。
const startWebview = vscode.commands.registerCommand(
'markmap-vscode.startWebview',
() => {
const nowEditor = vscode.window.activeTextEditor;
const panel = vscode.window.createWebviewPanel(
'markMap',
'makrdown to mind map',
vscode.ViewColumn.Two,
{
enableScripts: true,
},
);
// Get path to resource on disk
try {
const onDiskPathOfIndex = vscode.Uri.file(
path.join(vscode.ExtensionContext.extensionPath, 'CSS', 'index.css'),
);
} catch (e) {
console.error(e);
}
panel.webview.html = getWebviewContent();
},
);
context.subscriptions.push(startWebview);它提供了一个很好的webview,但是它不能加载本地文件。API之间的区别是什么?为什么它找不到extensionPath
发布于 2020-04-21 08:51:35
从您提供的doc链接中:
作为ExtensionContext的一个实例作为扩展.
的激活调用的第一个参数提供。
https://stackoverflow.com/questions/61338547
复制相似问题