@@ -7,6 +7,7 @@ import { workspaceState } from '../extension';
7
7
export class ClassDefinition {
8
8
private _className : string ;
9
9
private _classFileName : string ;
10
+
10
11
public static normalizeClassName ( className , withExtension = false ) : string {
11
12
return className . replace ( / ^ % ( \b \w + \b ) $ / , '%Library.$1' ) + ( withExtension ? '.cls' : '' ) ;
12
13
}
@@ -19,6 +20,14 @@ export class ClassDefinition {
19
20
this . _classFileName = ClassDefinition . normalizeClassName ( className , true ) ;
20
21
}
21
22
23
+ get uri ( ) : vscode . Uri {
24
+ return DocumentContentProvider . getUri ( this . _classFileName ) ;
25
+ }
26
+
27
+ async getDocument ( ) : Promise < vscode . TextDocument > {
28
+ return vscode . workspace . openTextDocument ( this . uri ) ;
29
+ }
30
+
22
31
store ( kind : string , data : any ) : any {
23
32
workspaceState . update ( `${ this . _classFileName } |${ kind } ` , data ) ;
24
33
return data ;
@@ -106,11 +115,13 @@ export class ClassDefinition {
106
115
. actionQuery ( sql , [ this . _className ] )
107
116
. then (
108
117
data =>
109
- data . result . content . reduce (
110
- ( list : string [ ] , el : { PrimarySuper : string } ) =>
111
- list . concat ( el . PrimarySuper . split ( '~' ) . filter ( el => el . length ) ) ,
112
- [ ]
113
- )
118
+ data . result . content
119
+ . reduce (
120
+ ( list : string [ ] , el : { PrimarySuper : string } ) =>
121
+ list . concat ( el . PrimarySuper . split ( '~' ) . filter ( el => el . length ) ) ,
122
+ [ ]
123
+ )
124
+ . filter ( ( name : string ) => name !== this . _className )
114
125
// .filter(name => !['%Library.Base', '%Library.SystemBase'].includes(name))
115
126
)
116
127
. then ( data => this . store ( 'super' , data ) ) ;
@@ -136,53 +147,32 @@ export class ClassDefinition {
136
147
. then ( data => this . store ( 'includeCode' , data ) ) ;
137
148
}
138
149
139
- async getPosition ( name : string , document ?: vscode . TextDocument ) : Promise < vscode . Location [ ] > {
150
+ async getMemberLocation ( name : string ) : Promise < vscode . Location > {
140
151
let pattern ;
141
152
if ( name . startsWith ( '#' ) ) {
142
153
pattern = `(Parameter) ${ name . substr ( 1 ) } (?!\w)` ;
143
154
} else {
144
155
pattern = `((Class)?Method|Property|RelationShip) ${ name } (?!\w)` ;
145
156
}
146
- let foundLine ;
147
- if ( document ) {
157
+ return this . getDocument ( ) . then ( document => {
148
158
for ( let i = 0 ; i < document . lineCount ; i ++ ) {
149
159
let line = document . lineAt ( i ) ;
150
160
if ( line . text . match ( pattern ) ) {
151
- foundLine = i ;
152
- break ;
161
+ return new vscode . Location ( this . uri , new vscode . Position ( i , 0 ) ) ;
153
162
}
154
163
}
155
- }
156
- let result : vscode . Location [ ] = [ ] ;
157
- if ( foundLine ) {
158
- result . push ( {
159
- uri : DocumentContentProvider . getUri ( this . _classFileName ) ,
160
- range : new vscode . Range ( foundLine , 0 , foundLine , 0 )
161
- } ) ;
162
- }
163
- let extendList = await this . super ( ) ;
164
- let api = new AtelierAPI ( ) ;
165
- let docs = [ ] ;
166
- extendList . forEach ( async docName => {
167
- docName = ClassDefinition . normalizeClassName ( docName , true ) ;
168
- docs . push ( api . getDoc ( docName ) ) ;
169
- } ) ;
170
- return Promise . all ( docs ) . then ( ( docs : any [ ] ) => {
171
- for ( let doc of docs ) {
172
- if ( doc && doc . result . content ) {
173
- let docName = doc . result . name ;
174
- let content = doc . result . content ;
175
- for ( let line of content . keys ( ) ) {
176
- if ( content [ line ] . match ( pattern ) ) {
177
- result . push ( {
178
- uri : DocumentContentProvider . getUri ( docName ) ,
179
- range : new vscode . Range ( line , 0 , line , 0 )
180
- } ) ;
181
- }
182
- }
183
- }
184
- }
185
- return result ;
164
+ return ;
186
165
} ) ;
187
166
}
167
+
168
+ async getMemberLocations ( name : string ) : Promise < vscode . Location [ ] > {
169
+ let extendList = await this . super ( ) ;
170
+ return Promise . all ( [
171
+ await this . getMemberLocation ( name ) ,
172
+ ...extendList . map ( async docName => {
173
+ let classDef = new ClassDefinition ( docName ) ;
174
+ return classDef . getMemberLocation ( name ) ;
175
+ } )
176
+ ] ) . then ( data => data . filter ( el => el != null ) ) ;
177
+ }
188
178
}
0 commit comments