1
+ import * as vscode from 'vscode' ;
1
2
import { AtelierAPI } from '../api' ;
3
+ import { onlyUnique } from '.' ;
4
+ import { DocumentContentProvider } from '../providers/DocumentContentProvider' ;
2
5
3
6
export class ClassDefinition {
4
7
private _className : string ;
@@ -15,7 +18,7 @@ export class ClassDefinition {
15
18
this . _classFileName = ClassDefinition . normalizeClassName ( className , true ) ;
16
19
}
17
20
18
- async methods ( scope : 'any' | 'class' | 'instance' ) : Promise < any [ ] > {
21
+ async methods ( scope : 'any' | 'class' | 'instance' = 'any' ) : Promise < any [ ] > {
19
22
let methods = [ ] ;
20
23
let filterScope = method => scope === 'any' || method . scope === scope ;
21
24
const api = new AtelierAPI ( ) ;
@@ -28,23 +31,43 @@ export class ClassDefinition {
28
31
if ( extend . length ) {
29
32
return api . actionIndex ( extend ) . then ( data => getMethods ( data . result . content ) ) ;
30
33
}
31
- return methods . filter ( filterScope ) ;
34
+ return methods
35
+ . filter ( filterScope )
36
+ . filter ( onlyUnique )
37
+ . sort ( ) ;
32
38
} ;
33
39
return api . actionIndex ( [ this . _classFileName ] ) . then ( data => getMethods ( data . result . content ) ) ;
34
40
}
35
41
42
+ async properties ( ) : Promise < any [ ] > {
43
+ let properties = [ ] ;
44
+ const api = new AtelierAPI ( ) ;
45
+ const getProperties = content => {
46
+ let extend = [ ] ;
47
+ content . forEach ( el => {
48
+ properties . push ( ...el . content . properties ) ;
49
+ extend . push ( ...el . content . super . map ( extendName => ClassDefinition . normalizeClassName ( extendName , true ) ) ) ;
50
+ } ) ;
51
+ if ( extend . length ) {
52
+ return api . actionIndex ( extend ) . then ( data => getProperties ( data . result . content ) ) ;
53
+ }
54
+ return properties . filter ( onlyUnique ) . sort ( ) ;
55
+ } ;
56
+ return api . actionIndex ( [ this . _classFileName ] ) . then ( data => getProperties ( data . result . content ) ) ;
57
+ }
58
+
36
59
async super ( ) : Promise < string [ ] > {
37
60
const api = new AtelierAPI ( ) ;
38
61
let sql = `SELECT PrimarySuper FROM %Dictionary.CompiledClass WHERE Name = ?` ;
39
- return api
40
- . actionQuery ( sql , [ this . _className ] )
41
- . then ( data =>
62
+ return api . actionQuery ( sql , [ this . _className ] ) . then (
63
+ data =>
42
64
data . result . content . reduce (
43
65
( list : string [ ] , el : { PrimarySuper : string } ) =>
44
66
list . concat ( el . PrimarySuper . split ( '~' ) . filter ( el => el . length ) ) ,
45
67
[ ]
46
68
)
47
- ) ;
69
+ // .filter(name => !['%Library.Base', '%Library.SystemBase'].includes(name))
70
+ ) ;
48
71
}
49
72
50
73
async includeCode ( ) : Promise < string [ ] > {
@@ -61,4 +84,49 @@ export class ClassDefinition {
61
84
)
62
85
) ;
63
86
}
87
+
88
+ async getPosition ( name : string , document : vscode . TextDocument ) : Promise < vscode . Location [ ] > {
89
+ let pattern = `((Class)?Method|Property|RelationShip) ${ name } (?!\w)` ;
90
+ let foundLine ;
91
+ if ( document ) {
92
+ for ( let i = 0 ; i < document . lineCount ; i ++ ) {
93
+ let line = document . lineAt ( i ) ;
94
+ if ( line . text . match ( pattern ) ) {
95
+ foundLine = i ;
96
+ break ;
97
+ }
98
+ }
99
+ }
100
+ let result : vscode . Location [ ] = [ ] ;
101
+ if ( foundLine ) {
102
+ result . push ( {
103
+ uri : DocumentContentProvider . getUri ( this . _classFileName ) ,
104
+ range : new vscode . Range ( foundLine , 0 , foundLine , 0 )
105
+ } ) ;
106
+ }
107
+ let extendList = await this . super ( ) ;
108
+ let api = new AtelierAPI ( ) ;
109
+ let docs = [ ] ;
110
+ extendList . forEach ( async docName => {
111
+ docName = ClassDefinition . normalizeClassName ( docName , true ) ;
112
+ docs . push ( api . getDoc ( docName ) ) ;
113
+ } ) ;
114
+ return Promise . all ( docs ) . then ( ( docs : any [ ] ) => {
115
+ for ( let doc of docs ) {
116
+ if ( doc && doc . result . content ) {
117
+ let docName = doc . result . name ;
118
+ let content = doc . result . content ;
119
+ for ( let line of content . keys ( ) ) {
120
+ if ( content [ line ] . match ( pattern ) ) {
121
+ result . push ( {
122
+ uri : DocumentContentProvider . getUri ( docName ) ,
123
+ range : new vscode . Range ( line , 0 , line , 0 )
124
+ } ) ;
125
+ }
126
+ }
127
+ }
128
+ }
129
+ return result ;
130
+ } ) ;
131
+ }
64
132
}
0 commit comments