1
1
import * as vscode from "vscode" ;
2
2
import { AtelierAPI } from "../api" ;
3
- import { currentFile , CurrentFile } from "../utils" ;
3
+ import { currentFile , CurrentFile , currentWorkspaceFolder } from "../utils" ;
4
4
import { ClassDefinition } from "../utils/classDefinition" ;
5
5
import { DocumentContentProvider } from "./DocumentContentProvider" ;
6
6
@@ -10,10 +10,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
10
10
position : vscode . Position ,
11
11
token : vscode . CancellationToken
12
12
) : vscode . ProviderResult < vscode . Location | vscode . Location [ ] | vscode . DefinitionLink [ ] > {
13
+ const workspaceFolder = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
14
+ const workspaceFolderName = workspaceFolder ? workspaceFolder . name : currentWorkspaceFolder ( ) ;
13
15
const lineText = document . lineAt ( position . line ) . text ;
14
16
const file = currentFile ( ) ;
15
17
16
- const fromClassRef = this . classRef ( document , position ) ;
18
+ const fromClassRef = this . classRef ( workspaceFolderName , document , position ) ;
17
19
if ( fromClassRef ) {
18
20
return fromClassRef ;
19
21
}
@@ -39,7 +41,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
39
41
const macroMatch = macroText . match ( / ^ \$ { 3 } ( \b \w + \b ) $ / ) ;
40
42
if ( macroMatch ) {
41
43
const [ , macro ] = macroMatch ;
42
- return this . macro ( currentFile ( ) , macro ) . then ( data =>
44
+ return this . macro ( workspaceFolderName , currentFile ( ) , macro ) . then ( data =>
43
45
data && data . document . length
44
46
? new vscode . Location ( DocumentContentProvider . getUri ( data . document ) , new vscode . Position ( data . line , 0 ) )
45
47
: null
@@ -53,7 +55,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
53
55
const [ keyword , name ] = part . split ( " " ) ;
54
56
const start = pos + keyword . length + 1 ;
55
57
if ( this . isValid ( position , start , name . length ) ) {
56
- return [ this . makeClassDefinition ( position , start , name . length , this . normalizeClassName ( document , name ) ) ] ;
58
+ return [
59
+ this . makeClassDefinition (
60
+ workspaceFolderName ,
61
+ position ,
62
+ start ,
63
+ name . length ,
64
+ this . normalizeClassName ( document , name )
65
+ ) ,
66
+ ] ;
57
67
}
58
68
}
59
69
pos += part . length ;
@@ -70,7 +80,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
70
80
name = name . trim ( ) ;
71
81
const start = pos + part . indexOf ( name ) ;
72
82
if ( this . isValid ( position , start , name . length ) ) {
73
- return this . makeClassDefinition ( position , start , name . length , this . normalizeClassName ( document , name ) ) ;
83
+ return this . makeClassDefinition (
84
+ workspaceFolderName ,
85
+ position ,
86
+ start ,
87
+ name . length ,
88
+ this . normalizeClassName ( document , name )
89
+ ) ;
74
90
}
75
91
} )
76
92
. filter ( el => el != null ) ;
@@ -86,7 +102,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
86
102
const start = lineText . indexOf ( name ) ;
87
103
if ( this . isValid ( position , start , name . length ) ) {
88
104
return [
89
- this . makeRoutineDefinition ( position , start , name . length , this . normalizeRoutineName ( document , name , "inc" ) ) ,
105
+ this . makeRoutineDefinition (
106
+ workspaceFolderName ,
107
+ position ,
108
+ start ,
109
+ name . length ,
110
+ this . normalizeRoutineName ( document , name , "inc" )
111
+ ) ,
90
112
] ;
91
113
}
92
114
}
@@ -103,6 +125,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
103
125
if ( this . isValid ( position , start , name . length ) ) {
104
126
return [
105
127
this . makeRoutineDefinition (
128
+ workspaceFolderName ,
106
129
position ,
107
130
start ,
108
131
name . length ,
@@ -119,6 +142,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
119
142
}
120
143
121
144
public classRef (
145
+ workspaceFolder : string ,
122
146
document : vscode . TextDocument ,
123
147
position : vscode . Position
124
148
) : vscode . ProviderResult < vscode . Location | vscode . Location [ ] | vscode . DefinitionLink [ ] > {
@@ -129,7 +153,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
129
153
const start = classRefRange . start . character + 8 ;
130
154
if ( this . isValid ( position , start , className . length ) ) {
131
155
return [
132
- this . makeClassDefinition ( position , start , className . length , this . normalizeClassName ( document , className ) ) ,
156
+ this . makeClassDefinition (
157
+ workspaceFolder ,
158
+ position ,
159
+ start ,
160
+ className . length ,
161
+ this . normalizeClassName ( document , className )
162
+ ) ,
133
163
] ;
134
164
} else {
135
165
const classDefinition = new ClassDefinition ( className ) ;
@@ -180,6 +210,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
180
210
}
181
211
182
212
public makeClassDefinition (
213
+ workspaceFolder : string ,
183
214
position : vscode . Position ,
184
215
start : number ,
185
216
length : number ,
@@ -192,11 +223,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
192
223
new vscode . Position ( position . line , start + length )
193
224
) ,
194
225
targetRange : new vscode . Range ( firstLinePos , firstLinePos ) ,
195
- targetUri : DocumentContentProvider . getUri ( name ) ,
226
+ targetUri : DocumentContentProvider . getUri ( name , workspaceFolder ) ,
196
227
} ;
197
228
}
198
229
199
230
public makeRoutineDefinition (
231
+ workspaceFolder : string ,
200
232
position : vscode . Position ,
201
233
start : number ,
202
234
length : number ,
@@ -209,11 +241,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
209
241
new vscode . Position ( position . line , start + length )
210
242
) ,
211
243
targetRange : new vscode . Range ( firstLinePos , firstLinePos ) ,
212
- targetUri : DocumentContentProvider . getUri ( name ) ,
244
+ targetUri : DocumentContentProvider . getUri ( name , workspaceFolder ) ,
213
245
} ;
214
246
}
215
247
216
- public async macro ( file : CurrentFile , macro : string ) : Promise < { document : string ; line : number } > {
248
+ public async macro (
249
+ workspaceFolder : string ,
250
+ file : CurrentFile ,
251
+ macro : string
252
+ ) : Promise < { document : string ; line : number } > {
217
253
const fileName = file . name ;
218
254
const api = new AtelierAPI ( ) ;
219
255
let includes = [ ] ;
0 commit comments