diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dba736..c983599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/README.md b/README.md index 68202e2..fae76aa 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package-lock.json b/package-lock.json index 272ae56..39e75d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "helly25iwyu", - "version": "0.0.1", + "version": "0.0.16", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "helly25iwyu", - "version": "0.0.1", + "version": "0.0.16", "license": "Apache-2.0", "devDependencies": { "@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", @@ -187,9 +187,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.18.34", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.34.tgz", - "integrity": "sha512-VmVm7gXwhkUimRfBwVI1CHhwp86jDWR04B5FGebMMyxV90SlCmFujwUHrxTD4oO+SOYU86SoxvhgeRQJY7iXFg==", + "version": "16.18.101", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.101.tgz", + "integrity": "sha512-AAsx9Rgz2IzG8KJ6tXd6ndNkVcu+GYB6U/SnFAaokSPNx2N7dcIIfnighYUNumvj6YS2q39Dejz5tT0NCV7CWA==", "dev": true }, "node_modules/@types/semver": { diff --git a/package.json b/package.json index 44de9f4..02680fc 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", @@ -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" } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index c804030..b2c4bda 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -249,6 +249,7 @@ class ConfigData { workspacefolder: string; config: vscode.WorkspaceConfiguration; compileCommandsData: CompileCommandsData; + compileCommandsJsonPath: string = ""; constructor(workspacefolder: string) { this.workspacefolder = workspacefolder; @@ -295,9 +296,30 @@ 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() { @@ -305,10 +327,11 @@ class ConfigData { } 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(); } }