Skip to content

Commit

Permalink
Update default for iwyu.compile_commands (#10)
Browse files Browse the repository at this point in the history
If `iwyu.compile_commands` is set to the default `auto`, then the extension will try:
  - `${workspaceFolder}/compile_commands.json`,
  - `${workspaceFolder}/build/compile_commands.json`,
  - `${fileWorkspaceFolder}/compile_commands.json`, and
  - `${fileWorkspaceFolder}/build/compile_commands.json`.

This should address #5 in slightly better way as it supports the common places.

This fixes #11
  • Loading branch information
helly25 authored Jul 8, 2024
1 parent ce1270a commit ee678af
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# [0.0.16]

* If `iwyu.compile_commands` is set to the default `auto`, then the extension will try:
- `${workspaceFolder}/compile_commands.json`,
- `${workspaceFolder}/build/compile_commands.json`,
- `${fileWorkspaceFolder}/compile_commands.json`, and
- `${fileWorkspaceFolder}/build/compile_commands.json`.
* Added rudimentary support for `${fileWorkspaceFolder}` in `iwyu.compile_commands` settings.

# [0.0.15]
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ easily achievable with all projects. The standard clang configurations also have

This extension has the following general settings:

- `iwyu.compile_commands` Path to `compile_commands.json` file (supports `${workspaceFolder}` and
`${workspaceRoot}`).
- `iwyu.compile_commands` Path to `compile_commands.json` file (supports `${workspaceFolder}`,
`${workspaceRoot}` and `${fileWorkspaceFolder}`). If set to the default `auto`, then the extension will try:
- `${workspaceFolder}/compile_commands.json`,
- `${workspaceFolder}/build/compile_commands.json`,
- `${fileWorkspaceFolder}/compile_commands.json`, and
- `${fileWorkspaceFolder}/build/compile_commands.json`.
- `iwyu.filter_iwu_output`: Regexp expression filter for iwyu output. This will be used as {here} in
'#include.*({here})'. For instance in order to not add system includes under '__fwd/*.', set this to '<__fwd/'. This
does not result in removing such headers, it merely prevents adding them, so it won't produce diagnostics for such includes.
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Include What You Use",
"include-what-you-use"
],
"version": "0.0.15",
"version": "0.0.16",
"publisher": "helly25",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -41,8 +41,8 @@
"properties": {
"iwyu.compile_commands": {
"type": "string",
"default": "${workspaceFolder}/compile_commands.json",
"markdownDescription": "Path to `compile_commands.json` file (supports `${workspaceFolder}` and `${workspaceRoot}`)."
"default": "auto",
"markdownDescription": "Path to `compile_commands.json` file (supports `${workspaceFolder}`, `${fileWorkspaceFolder}` and `${workspaceRoot}`). If this is set to the default `auto`, then the extension will try `${workspaceFolder}/compile_commands.json`, `${workspaceFolder}/build/compile_commands.json`, `${fileWorkspaceFolder}/compile_commands.json` and `${fileWorkspaceFolder}/build/compile_commands.json`."
},
"iwyu.filter_iwyu_output": {
"type": "string",
Expand Down Expand Up @@ -183,16 +183,16 @@
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.78.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/node": "^16.18.101",
"@types/vscode": "^1.78.0",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@vscode/test-electron": "^2.3.0",
"eslint": "^8.39.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"typescript": "^5.0.4",
"@vscode/test-electron": "^2.3.0"
"typescript": "^5.0.4"
}
}
}
33 changes: 28 additions & 5 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 @@ -295,20 +296,42 @@ class ConfigData {
}

compileCommandsJson(): string {
let compileCommandsJsonDefault = "${workspaceFolder}/compile_commands.json";
let compileCommandsJson = this.config.get("compile_commands", compileCommandsJsonDefault);
return this.replaceWorkspaceVars(compileCommandsJson);
let compileCommandsJsonDefault = "auto";
let compileCommandsJsonPath = this.config.get("compile_commands", compileCommandsJsonDefault);
const tests: readonly string[] = compileCommandsJsonPath === compileCommandsJsonDefault ?
[
"${workspaceFolder}/compile_commands.json",
"${workspaceFolder}/build/compile_commands.json",
"${fileWorkspaceFolder}/compile_commands.json",
"${fileWorkspaceFolder}/build/compile_commands.json",
]
: [compileCommandsJsonPath];
for (let test of tests) {
try {
test = this.replaceWorkspaceVars(test);
fs.statSync(test);
compileCommandsJsonPath = test;
break;
}
catch (err) {
// Ignore, caught later.
}
}
log(DEBUG, "Using compileCommandsJson = '" + compileCommandsJsonPath + "'.");
this.compileCommandsJsonPath = compileCommandsJsonPath;
return this.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 ee678af

Please sign in to comment.