Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ export class CppProperties {
let compilerPathAndArgs: util.CompilerPathAndArgs;
if (this.CurrentConfiguration.compilerPath) {
compilerPathAndArgs = util.extractCompilerPathAndArgs(this.CurrentConfiguration.compilerPath);
paths.add(`"${compilerPathAndArgs.compilerPath}`); // It may not end with ".
paths.add(`${compilerPathAndArgs.compilerPath}`); // It may not start or end with ".
}

// Get the start/end for properties that are file-only.
Expand All @@ -765,15 +765,15 @@ export class CppProperties {
let compileCommandsStart: number = curText.search(/\s*\"compileCommands\"\s*:\s*\"/);
let compileCommandsEnd: number = compileCommandsStart === -1 ? -1 : curText.indexOf('"', curText.indexOf('"', curText.indexOf(":", compileCommandsStart)) + 1);
let compilerPathStart: number = curText.search(/\s*\"compilerPath\"\s*:\s*\"/);
let compilerPathEnd: number = compilerPathStart === -1 ? -1 : curText.indexOf('"', curText.indexOf('"', curText.indexOf(":", compilerPathStart)) + 1);
let compilerPathEnd: number = compilerPathStart === -1 ? -1 : curText.indexOf('"', curText.indexOf('"', curText.indexOf(":", compilerPathStart)) + 1) + 1;

if (this.prevSquiggleMetrics[this.CurrentConfiguration.name] === undefined) {
this.prevSquiggleMetrics[this.CurrentConfiguration.name] = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0 };
}
let newSquiggleMetrics: { [key: string]: number } = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0 };

for (let curPath of paths) {
let resolvedPath: string = curPath.substr(1, (curPath.endsWith('"') ? curPath.length - 2 : curPath.length - 1));
let resolvedPath: string = curPath.substr((curPath.startsWith('"') ? 1 : 0), (curPath.endsWith('"') ? curPath.length - 2 : curPath.length));
// Resolve special path cases.
if (resolvedPath === "${default}") {
// TODO: Add squiggles for when the C_Cpp.default.* paths are invalid.
Expand Down Expand Up @@ -842,7 +842,8 @@ export class CppProperties {
}
}
let diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
new vscode.Range(document.positionAt(curTextStartOffset + curOffset + 1), document.positionAt(curTextStartOffset + curOffset + (curPath.endsWith('"') ? curPath.length - 1 : curPath.length))),
new vscode.Range(document.positionAt(curTextStartOffset + curOffset),
document.positionAt(curTextStartOffset + curOffset + (curPath.endsWith('"') ? curPath.length - 1 : curPath.length))),
message, vscode.DiagnosticSeverity.Warning);
diagnostics.push(diagnostic);
}
Expand Down
27 changes: 21 additions & 6 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,19 +766,34 @@ export function extractCompilerPathAndArgs(inputCompilerPath: string): CompilerP
let compilerPath: string = inputCompilerPath;
let additionalArgs: string[];
if (compilerPath) {
compilerPath = compilerPath.trim();
if (compilerPath.startsWith("\"")) {
let endQuote: number = compilerPath.substr(1).search("\"") + 1;
if (endQuote !== -1) {
additionalArgs = compilerPath.substr(endQuote + 1).split(" ");
additionalArgs = additionalArgs.filter((arg: string) => { return arg.trim().length !== 0; });
additionalArgs = additionalArgs.filter((arg: string) => { return arg.trim().length !== 0; }); // Remove empty args.
compilerPath = compilerPath.substr(1, endQuote - 1);
}
} else {
if (compilerPath.includes(" ") && !fs.existsSync(compilerPath)) {
let argStart: number = compilerPath.search(" ");
additionalArgs = compilerPath.substr(argStart + 1).split(" ");
additionalArgs = additionalArgs.filter((arg: string) => { return arg.trim().length !== 0; });
compilerPath = compilerPath.substr(0, argStart);
// Go from right to left checking if a valid path is to the left of a space.
let spaceStart: number = compilerPath.lastIndexOf(" ");
if (spaceStart !== -1 && !fs.existsSync(compilerPath)) {
let potentialCompilerPath: string = compilerPath.substr(0, spaceStart);
while (!fs.existsSync(potentialCompilerPath)) {
spaceStart = potentialCompilerPath.lastIndexOf(" ");
if (spaceStart === -1) {
// Reached the start without finding a valid path. Use the original value.
potentialCompilerPath = compilerPath;
break;
}
potentialCompilerPath = potentialCompilerPath.substr(0, spaceStart);
}
if (compilerPath !== potentialCompilerPath) {
// Found a valid compilerPath and args.
additionalArgs = compilerPath.substr(spaceStart + 1).split(" ");
additionalArgs = additionalArgs.filter((arg: string) => { return arg.trim().length !== 0; }); // Remove empty args.
compilerPath = potentialCompilerPath;
}
}
}
}
Expand Down