【发布时间】:2019-09-06 00:36:56
【问题描述】:
试图在 VS 代码 extension.js 中获取当前项目文件夹路径,但我收到 [object Promise] 错误。如何解决这个问题?谁能解决这个问题?
extension.js:
const getCurrentlyopenedprojectpath = async() => {
const editor = window.activeTextEditor;
if (!editor || !workspace.workspaceFolders || workspace.workspaceFolders.length < 2) {
return null;
}
let text;
const resource = editor.document.uri;
if (resource.scheme === 'file') {
const folder = workspace.getWorkspaceFolder(resource);
if (!folder) {
text = `$(alert) <outside workspace> → ${basename(resource.fsPath)}`;
} else {
text = `$(file-submodule) ${basename(folder.uri.fsPath)} (${folder.index + 1} of ${workspace.workspaceFolders.length}) → $(file-code) ${basename(resource.fsPath)}`;
}
}
return {
text
};
}
console.log(getCurrentlyopenedprojectpath());
【问题讨论】:
标签: javascript node.js visual-studio-code