Skip to content

Commit

Permalink
Add experimental support for ${fileWorkspaceFolder}.
Browse files Browse the repository at this point in the history
  • Loading branch information
helly25 committed Jul 7, 2024
1 parent 3be0fa8 commit c1a3f13
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class ConfigData {
workspacefolder: string;
config: vscode.WorkspaceConfiguration;
compileCommandsData: CompileCommandsData;
compileCommandsJsonPath: string = "";

constructor(workspacefolder: string) {
this.workspacefolder = workspacefolder;
Expand Down Expand Up @@ -286,43 +287,48 @@ class ConfigData {
}

replaceWorkspaceVars(input: string): string {
return input.replace("${workspaceRoot}", this.workspacefolder)
.replace("${workspaceFolder}", this.workspacefolder)
input = input.replace("${workspaceRoot}", this.workspacefolder);
input = input.replace("${workspaceFolder}", this.workspacefolder);
let uri = vscode.window.activeTextEditor?.document?.uri;
input = input.replace("${fileWorkspaceFolder}", uri ? uri.fsPath : "");
return input;
}

compileCommandsJson(): string {
let compileCommandsJsonDefault = "${workspaceFolder}/compile_commands.json";
let compileCommandsJson = this.config.get("compile_commands", compileCommandsJsonDefault);
let isDefault = compileCommandsJson === compileCommandsJsonDefault;
compileCommandsJson = this.replaceWorkspaceVars(compileCommandsJson);
let compileCommandsJsonPath = this.config.get("compile_commands", compileCommandsJsonDefault);
let isDefault = compileCommandsJsonPath === compileCommandsJsonDefault;
compileCommandsJsonPath = this.replaceWorkspaceVars(compileCommandsJsonPath);
try {
fs.statSync(compileCommandsJson);
fs.statSync(compileCommandsJsonPath);
}
catch (err) {
if (isDefault) {
try {
let test = this.replaceWorkspaceVars("${workspaceFolder}/build/compile_commands.json");
fs.statSync(test);
compileCommandsJson = test;
compileCommandsJsonPath = test;
}
catch (err) {
// Ignore, caught later.
}
}
}
log(DEBUG, "Using compileCommandsJson = '" + compileCommandsJson + "'.");
return compileCommandsJson;
log(DEBUG, "Using compileCommandsJson = '" + compileCommandsJsonPath + "'.");
this.compileCommandsJsonPath = compileCommandsJsonPath;
return compileCommandsJsonPath;
}

updateConfig() {
this.config = vscode.workspace.getConfiguration("iwyu");
}

updateCompileCommands() {
let compileCommandsJsonLast = this.compileCommandsJsonPath;
let compileCommandsJson = this.compileCommandsJson();
try {
let stats = fs.statSync(compileCommandsJson);
if (stats.mtimeMs !== this.compileCommandsData.mtimeMs) {
let stats = fs.statSync(this.compileCommandsJsonPath);
if (stats.mtimeMs !== this.compileCommandsData.mtimeMs || compileCommandsJsonLast !== this.compileCommandsJsonPath) {
this.compileCommandsData = this.parseCompileCommands();
}
}
Expand Down

0 comments on commit c1a3f13

Please sign in to comment.