@@ -4,6 +4,8 @@ import * as vscode from "vscode";
44import { getDeclaredFunctions , getDeclaredSubroutines } from "../lib/functions" ;
55import { getDeclaredVars } from "../lib/variables" ;
66
7+ type SymbolType = "subroutine" | "function" | "variable" ;
8+
79export 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