diff --git a/CHANGELOG.md b/CHANGELOG.md index 1356175..4a3f72d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # [0.0.19] +* Added activation support for C language. * Added setting `iwyu.fix.fix_header` which fixes includes in the corresponding header for a given implementation file (e.g. foo.h when fixing foo.cpp). # [0.0.18] diff --git a/package.json b/package.json index 3ec8cfb..c1f4082 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "Include What You Use", "include-what-you-use" ], - "version": "0.0.18", + "version": "0.0.19", "publisher": "helly25", "license": "Apache-2.0", "repository": { @@ -16,13 +16,14 @@ }, "icon": "images/logo.png", "engines": { - "vscode": "^1.78.0" + "vscode": "^1.92.0" }, "categories": [ "Other" ], "activationEvents": [ - "onLanguage:cpp" + "onLanguage:cpp", + "onLanguage:c" ], "main": "./out/extension.js", "contributes": { diff --git a/src/extension.ts b/src/extension.ts index fb1abfa..098e9b2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -41,6 +41,8 @@ export const ERROR = vscode.LogLevel.Error; const logger: vscode.LogOutputChannel = vscode.window.createOutputChannel("IWYU", { log: true }); +const supportedLanguages = ["cpp", "c"]; + function log(severity: vscode.LogLevel, message: string, ...args: any[]) { switch (severity) { case vscode.LogLevel.Off: return; @@ -395,11 +397,13 @@ class Extension { this.subscribeToDocumentChanges(context, iwyuDiagnostics); - context.subscriptions.push( - vscode.languages.registerCodeActionsProvider('cpp', new IwyuQuickFix(this.configData), { - providedCodeActionKinds: IwyuQuickFix.providedCodeActionKinds - }) - ); + for (const lang of supportedLanguages) { + context.subscriptions.push( + vscode.languages.registerCodeActionsProvider(lang, new IwyuQuickFix(this.configData), { + providedCodeActionKinds: IwyuQuickFix.providedCodeActionKinds, + }) + ); + } context.subscriptions.push(vscode.commands.registerCommand(IWYU_COMMAND_ONE, () => { this.iwyuCommandOne(); })); context.subscriptions.push(vscode.commands.registerCommand(IWYU_COMMAND_ALL, () => { this.iwyuCommandAll(); })); @@ -762,9 +766,17 @@ class Extension { } private iwyuDiagnosticsRefresh(doc: vscode.TextDocument, iwyuDiagnostics: vscode.DiagnosticCollection) { - if (doc.languageId !== "cpp") { + // Only process real files (not logs, etc.) + if (doc.uri.scheme !== "file") { return; } + + // Only process supported languages + if (!supportedLanguages.includes(doc.languageId)) { + log(DEBUG, `Unsupported language: ${doc.languageId}. Skipping.`); + return; + } + this.configData.updateConfig(); let diagnosticsOnlyRe: string = this.configData.config.get("diagnostics.only_re", ""); if (typeof diagnosticsOnlyRe !== "string" || String(diagnosticsOnlyRe) === "true") {