1
- import {
2
- CancellationToken ,
3
- TextDocument ,
4
- Position ,
5
- Hover ,
6
- TextLine ,
7
- SymbolInformation ,
8
- } from 'vscode' ;
1
+ import { CancellationToken , TextDocument , TextLine , SymbolInformation } from 'vscode' ;
9
2
10
3
import * as vscode from 'vscode' ;
11
4
import {
@@ -16,7 +9,7 @@ import { parseVars as getDeclaredVar } from '../lib/variables';
16
9
import { EXTENSION_ID } from '../lib/tools' ;
17
10
18
11
type SymbolType = 'subroutine' | 'function' | 'variable' ;
19
- type ParserFunc = ( line : TextLine ) => SymbolInformation | undefined ;
12
+ type ParserFunc = ( document : TextDocument , line : TextLine ) => SymbolInformation | undefined ;
20
13
21
14
export class FortranDocumentSymbolProvider implements vscode . DocumentSymbolProvider {
22
15
vars : Array < vscode . SymbolInformation > ;
@@ -47,7 +40,7 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
47
40
if ( initialCharacter === '!' || initialCharacter === '#' ) continue ;
48
41
const symbolsInLine = symbolTypes
49
42
. map ( type => this . getSymbolsOfType ( type ) )
50
- . map ( fn => fn ( line ) )
43
+ . map ( fn => fn ( document , line ) )
51
44
. filter ( symb => symb !== undefined ) ;
52
45
if ( symbolsInLine . length > 0 ) {
53
46
symbols = symbols . concat ( symbolsInLine ) ;
@@ -62,39 +55,53 @@ export class FortranDocumentSymbolProvider implements vscode.DocumentSymbolProvi
62
55
return this . parseSubroutineDefinition ;
63
56
case 'function' :
64
57
return this . parseFunctionDefinition ;
65
-
66
58
case 'variable' :
67
59
return this . parseVariableDefinition ;
68
60
default :
69
61
return ( ) => undefined ;
70
62
}
71
63
}
72
64
73
- private parseSubroutineDefinition ( line : TextLine ) {
65
+ private parseSubroutineDefinition ( document : TextDocument , line : TextLine ) {
74
66
try {
75
67
const subroutine = getDeclaredSubroutine ( line ) ;
76
68
if ( subroutine ) {
77
69
const range = new vscode . Range ( line . range . start , line . range . end ) ;
78
- return new vscode . SymbolInformation ( subroutine . name , vscode . SymbolKind . Function , range ) ;
70
+ return new vscode . SymbolInformation (
71
+ subroutine . name ,
72
+ vscode . SymbolKind . Function ,
73
+ document . fileName ,
74
+ new vscode . Location ( document . uri , range )
75
+ ) ;
79
76
}
80
77
} catch ( err ) {
81
78
console . log ( err ) ;
82
79
}
83
80
}
84
81
85
- private parseFunctionDefinition ( line : TextLine ) {
82
+ private parseFunctionDefinition ( document : TextDocument , line : TextLine ) {
86
83
const fun = getDeclaredFunction ( line ) ;
87
84
if ( fun ) {
88
85
const range = new vscode . Range ( line . range . start , line . range . end ) ;
89
- return new vscode . SymbolInformation ( fun . name , vscode . SymbolKind . Function , range ) ;
86
+ return new vscode . SymbolInformation (
87
+ fun . name ,
88
+ vscode . SymbolKind . Function ,
89
+ document . fileName ,
90
+ new vscode . Location ( document . uri , range )
91
+ ) ;
90
92
}
91
93
}
92
94
93
- private parseVariableDefinition ( line : TextLine ) {
95
+ private parseVariableDefinition ( document : TextDocument , line : TextLine ) {
94
96
const variable = getDeclaredVar ( line ) ;
95
97
if ( variable ) {
96
98
const range = new vscode . Range ( line . range . start , line . range . end ) ;
97
- return new vscode . SymbolInformation ( variable . name , vscode . SymbolKind . Variable , range ) ;
99
+ return new vscode . SymbolInformation (
100
+ variable . name ,
101
+ vscode . SymbolKind . Variable ,
102
+ document . fileName ,
103
+ new vscode . Location ( document . uri , range )
104
+ ) ;
98
105
}
99
106
}
100
107
0 commit comments