Skip to content

Commit

Permalink
Linter include dirs cache out of date
Browse files Browse the repository at this point in the history
Fixes #464
  • Loading branch information
gnikit committed May 7, 2022
1 parent c2febbf commit e7028c3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// Module to hold all command names

export const RestartLS = 'fortran.analysis.restartLanguageServer';
export const RescanLint = 'fortran.analysis.rescanLinter';
18 changes: 17 additions & 1 deletion src/features/linter-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {}
Expand All @@ -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);
Expand All @@ -48,7 +53,6 @@ export class FortranLintingProvider {
public dispose(): void {
this.diagnosticCollection.clear();
this.diagnosticCollection.dispose();
// this.command.dispose();
}

private doModernFortranLint(textDocument: vscode.TextDocument) {
Expand Down Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e7028c3

Please sign in to comment.