Skip to content

Commit 7230907

Browse files
committed
Add config option to detect symbols
1 parent 9e9eb70 commit 7230907

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6666
### Fixed
6767

6868
* Fixed some highlighting issues by @pedro-ricardo
69+
70+
## [0.6.3] - 2018-01-27
71+
72+
### Added
73+
74+
* Configuration option to set types of symbols shown
75+
76+
### Fixed
77+
78+
* Implementation of the symbol provider now returns a promise (Fixes #21)
79+
* Symbol provider now ignores case when searching for subroutines

src/features/document-symbol-provider.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as vscode from "vscode";
44
import { getDeclaredFunctions, getDeclaredSubroutines } from "../lib/functions";
55
import { getDeclaredVars } from "../lib/variables";
66

7+
type SymbolType = "subroutine" | "function" | "variable";
8+
79
export class FortranDocumentSymbolProvider
810
implements vscode.DocumentSymbolProvider {
911
vars: Array<vscode.SymbolInformation>;
@@ -18,12 +20,33 @@ export class FortranDocumentSymbolProvider
1820
token.onCancellationRequested(e => {
1921
reject();
2022
});
21-
this.updateFunctionDefinitions(document);
22-
this.updateSubroutineDefinitions(document);
23-
this.updateVariablesDefiniton(document);
24-
resolve([...this.functions, ...this.subroutines, ...this.vars]);
23+
const symbolTypes = this.getSymbolTypes();
24+
const documentSymbols = symbolTypes.reduce<vscode.SymbolInformation[]>(
25+
(symbols, type: SymbolType) => {
26+
return [...symbols, ...this.getSymbolsOfType(type, document)];
27+
},
28+
[]
29+
);
30+
31+
resolve(documentSymbols);
2532
});
2633
}
34+
getSymbolsOfType(
35+
type: "subroutine" | "function" | "variable",
36+
document: TextDocument
37+
) {
38+
switch (type) {
39+
case "subroutine":
40+
this.updateSubroutineDefinitions(document);
41+
return this.subroutines;
42+
case "function":
43+
this.updateFunctionDefinitions(document);
44+
return this.functions;
45+
case "variable":
46+
this.updateVariablesDefiniton(document);
47+
return this.vars;
48+
}
49+
}
2750

2851
private updateFunctionDefinitions(document: TextDocument) {
2952
this.functions = getDeclaredFunctions(document).map(fun => {
@@ -61,4 +84,12 @@ export class FortranDocumentSymbolProvider
6184
);
6285
});
6386
}
87+
getSymbolTypes() {
88+
let config = vscode.workspace.getConfiguration("fortran");
89+
const symbolTypes = config.get<SymbolType[]>("symbols", [
90+
"subroutine",
91+
"function"
92+
]);
93+
return symbolTypes;
94+
}
6495
}

0 commit comments

Comments
 (0)