From e7028c38b7a8ee72068206690d389e04b380e9f8 Mon Sep 17 00:00:00 2001 From: gnikit Date: Sat, 7 May 2022 18:09:35 +0100 Subject: [PATCH] Linter include dirs cache out of date Fixes #464 --- CHANGELOG.md | 3 +++ package.json | 11 +++++++++++ src/features/commands.ts | 1 + src/features/linter-provider.ts | 18 +++++++++++++++++- src/lib/helper.ts | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2d2f942..0f7deb7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Added ability to rescan for linting include files. - Added GitHub Actions support for pre-Release builds ([#459](https://github.com/fortran-lang/vscode-fortran-support/issues/459)) - Added unittest for `fortls` spawning and integration, checks for initialization values @@ -63,6 +64,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed issue with linter cache containing outdated folders + ([#464](https://github.com/fortran-lang/vscode-fortran-support/issues/464)) - Fixed slow performance of very long lines by using a different solution for ([#207](https://github.com/fortran-lang/vscode-fortran-support/issues/207)) ([#309](https://github.com/fortran-lang/vscode-fortran-support/issues/309)) diff --git a/package.json b/package.json index 22002534..f6d13975 100644 --- a/package.json +++ b/package.json @@ -346,6 +346,11 @@ "category": "Fortran", "command": "fortran.analysis.restartLanguageServer", "title": "Restart the Fortran Language Server" + }, + { + "category": "Fortran", + "command": "fortran.analysis.rescanLinter", + "title": "Rescan Linter paths" } ], "menus": { @@ -355,6 +360,12 @@ "command": "fortran.analysis.restartLanguageServer", "title": "Restart the Fortran Language Server", "when": "!virtualWorkspace && shellExecutionSupported" + }, + { + "category": "Fortran", + "command": "fortran.analysis.rescanLinter", + "title": "Rescan Linter paths", + "when": "!virtualWorkspace && shellExecutionSupported" } ] } diff --git a/src/features/commands.ts b/src/features/commands.ts index 9fbaf9b6..b5ee2312 100644 --- a/src/features/commands.ts +++ b/src/features/commands.ts @@ -3,3 +3,4 @@ // Module to hold all command names export const RestartLS = 'fortran.analysis.restartLanguageServer'; +export const RescanLint = 'fortran.analysis.rescanLinter'; diff --git a/src/features/linter-provider.ts b/src/features/linter-provider.ts index 11cacfd2..ff135def 100644 --- a/src/features/linter-provider.ts +++ b/src/features/linter-provider.ts @@ -9,6 +9,7 @@ import { FortranDocumentSelector, resolveVariables } from '../lib/tools'; import * as fg from 'fast-glob'; import { glob } from 'glob'; import { arraysEqual } from '../lib/helper'; +import { RescanLint } from './commands'; export class FortranLintingProvider { constructor(private logger: LoggingService = new LoggingService()) {} @@ -28,6 +29,10 @@ export class FortranLintingProvider { } public async activate(subscriptions: vscode.Disposable[]) { + // Register Linter commands + subscriptions.push(vscode.commands.registerCommand(RescanLint, this.rescanLinter, this)); + + // Register the Linter provider this.diagnosticCollection = vscode.languages.createDiagnosticCollection('Fortran'); vscode.workspace.onDidOpenTextDocument(this.doModernFortranLint, this, subscriptions); @@ -48,7 +53,6 @@ export class FortranLintingProvider { public dispose(): void { this.diagnosticCollection.clear(); this.diagnosticCollection.dispose(); - // this.command.dispose(); } private doModernFortranLint(textDocument: vscode.TextDocument) { @@ -166,6 +170,10 @@ export class FortranLintingProvider { // Check if we can use the cached results for the include directories no // need to evaluate the glob patterns everytime we call the linter + // TODO: register command that forces re-linting + // Not sure what the best approach for this one is? + // Should I add a watcher to all the files under globIncPaths? + // Should I add a watcher on the files under the workspace? if (arraysEqual(includePaths, this.cache['includePaths'])) { return this.cache['globIncPaths']; } @@ -446,4 +454,12 @@ export class FortranLintingProvider { break; } } + + /** + * Regenerate the cache for the include files paths of the linter + */ + private rescanLinter() { + this.cache['includePaths'] = []; + this.getIncludePaths(); + } } diff --git a/src/lib/helper.ts b/src/lib/helper.ts index 9627ba2f..ac2374ad 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -116,6 +116,6 @@ export function arraysEqual(a: any[], b: any[]) { if (a === b) return true; if (a == null || b == null) return false; if (a.length !== b.length) return false; - if (a.every((e, i) => e !== b[i])) return false; + if (!a.every((e, i) => e === b[i])) return false; return true; }