VS代码.error workspacefolder无法解决



在vs代码中运行c++代码时,会出现错误"workspaceFolder无法解析";。但在视觉工作室一切都很好。

我创建了一个插件,它重新创建了VSCode预定义变量的利用率:

它在使用C++、IMHO的TDD中也非常有用。

该插件在您提供的任何命令行的c/cpp文件类型上运行,并在保存该文件时使用预定义的变量。

这是否帮助您使用VSCode${workspaceFolder}运行shell代码?

干杯!

const filePath = document.fileName;
const fileWorkspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(filePath));
const cmd = this._testCommands.find(obj => obj.hasOwnProperty(document.languageId)); // Get the files and command values
let commandText = cmd[document.languageId];
try {
if (fileWorkspaceFolder) {
if (commandText.includes('${workspaceFolder}')) {
commandText = commandText.replace('${workspaceFolder}', workspaceFolderUri?.uri.fsPath ?? '');
}
if (commandText.includes('${workspaceFolderBasename}')) {
commandText = commandText.replace('${workspaceFolderBasename}', workspaceFolderUri?.name ?? '');
}
if (commandText.includes('${file}')) {
commandText = commandText.replace('${file}', document.uri.fsPath);
}
if (commandText.includes('${fileWorkspaceFolder}')) {
commandText = commandText.replace('${fileWorkspaceFolder}', fileWorkspaceFolder?.uri.fsPath ?? '');
}
if (commandText.includes('${relativeFileDirname}')) {
commandText = commandText.replace('${relativeFileDirname}', path.relative(fileWorkspaceFolder?.uri.fsPath ?? '', path.dirname(filePath)));
}
}
if (commandText.includes('${fileBasename}')) {
commandText = commandText.replace('${fileBasename}', vscode.workspace.asRelativePath(filePath));
}
if (commandText.includes('${fileBasenameNoExtension}')) {
commandText = commandText.replace('${fileBasenameNoExtension}', path.basename(filePath, path.extname(filePath)));
}
if (commandText.includes('${fileExtname}')) {
commandText = commandText.replace('${fileExtname}', filePath.split('.').pop());
}
if (commandText.includes('${fileDirname}')) {
commandText = commandText.replace('${fileDirname}', path.dirname(filePath));
}
if (commandText.includes('${fileDirnameBasename}')) {
commandText = commandText.replace('${fileDirnameBasename}', path.basename(path.dirname(filePath)));
}
const regex = /${env:(.*?)}/g;
const matches = commandText.match(regex);
if (matches) {
const resolvedString = matches.reduce((acc: string, match: string) => {
const variableName = match.slice(6, -1);
const variableValue = process.env[variableName] ?? '';
return acc.replace(match, variableValue);
}, commandText);
commandText = resolvedString;
}

相关内容

最新更新