@@ -4,6 +4,8 @@ import * as vscode from "vscode";
4
4
import { getDeclaredFunctions , getDeclaredSubroutines } from "../lib/functions" ;
5
5
import { getDeclaredVars } from "../lib/variables" ;
6
6
7
+ type SymbolType = "subroutine" | "function" | "variable" ;
8
+
7
9
export class FortranDocumentSymbolProvider
8
10
implements vscode . DocumentSymbolProvider {
9
11
vars : Array < vscode . SymbolInformation > ;
@@ -18,12 +20,33 @@ export class FortranDocumentSymbolProvider
18
20
token . onCancellationRequested ( e => {
19
21
reject ( ) ;
20
22
} ) ;
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 ) ;
25
32
} ) ;
26
33
}
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
+ }
27
50
28
51
private updateFunctionDefinitions ( document : TextDocument ) {
29
52
this . functions = getDeclaredFunctions ( document ) . map ( fun => {
@@ -61,4 +84,12 @@ export class FortranDocumentSymbolProvider
61
84
) ;
62
85
} ) ;
63
86
}
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
+ }
64
95
}
0 commit comments