11import * as vscode from "vscode" ;
22import { AtelierAPI } from "../api" ;
3- import { currentFile , CurrentFile } from "../utils" ;
3+ import { currentFile , CurrentFile , currentWorkspaceFolder } from "../utils" ;
44import { ClassDefinition } from "../utils/classDefinition" ;
55import { DocumentContentProvider } from "./DocumentContentProvider" ;
66
@@ -10,10 +10,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
1010 position : vscode . Position ,
1111 token : vscode . CancellationToken
1212 ) : vscode . ProviderResult < vscode . Location | vscode . Location [ ] | vscode . DefinitionLink [ ] > {
13+ const workspaceFolder = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
14+ const workspaceFolderName = workspaceFolder ? workspaceFolder . name : currentWorkspaceFolder ( ) ;
1315 const lineText = document . lineAt ( position . line ) . text ;
1416 const file = currentFile ( ) ;
1517
16- const fromClassRef = this . classRef ( document , position ) ;
18+ const fromClassRef = this . classRef ( workspaceFolderName , document , position ) ;
1719 if ( fromClassRef ) {
1820 return fromClassRef ;
1921 }
@@ -39,7 +41,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
3941 const macroMatch = macroText . match ( / ^ \$ { 3 } ( \b \w + \b ) $ / ) ;
4042 if ( macroMatch ) {
4143 const [ , macro ] = macroMatch ;
42- return this . macro ( currentFile ( ) , macro ) . then ( data =>
44+ return this . macro ( workspaceFolderName , currentFile ( ) , macro ) . then ( data =>
4345 data && data . document . length
4446 ? new vscode . Location ( DocumentContentProvider . getUri ( data . document ) , new vscode . Position ( data . line , 0 ) )
4547 : null
@@ -53,7 +55,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
5355 const [ keyword , name ] = part . split ( " " ) ;
5456 const start = pos + keyword . length + 1 ;
5557 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+ ] ;
5767 }
5868 }
5969 pos += part . length ;
@@ -70,7 +80,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
7080 name = name . trim ( ) ;
7181 const start = pos + part . indexOf ( name ) ;
7282 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+ ) ;
7490 }
7591 } )
7692 . filter ( el => el != null ) ;
@@ -86,7 +102,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
86102 const start = lineText . indexOf ( name ) ;
87103 if ( this . isValid ( position , start , name . length ) ) {
88104 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+ ) ,
90112 ] ;
91113 }
92114 }
@@ -103,6 +125,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
103125 if ( this . isValid ( position , start , name . length ) ) {
104126 return [
105127 this . makeRoutineDefinition (
128+ workspaceFolderName ,
106129 position ,
107130 start ,
108131 name . length ,
@@ -119,6 +142,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
119142 }
120143
121144 public classRef (
145+ workspaceFolder : string ,
122146 document : vscode . TextDocument ,
123147 position : vscode . Position
124148 ) : vscode . ProviderResult < vscode . Location | vscode . Location [ ] | vscode . DefinitionLink [ ] > {
@@ -129,7 +153,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
129153 const start = classRefRange . start . character + 8 ;
130154 if ( this . isValid ( position , start , className . length ) ) {
131155 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+ ) ,
133163 ] ;
134164 } else {
135165 const classDefinition = new ClassDefinition ( className ) ;
@@ -180,6 +210,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
180210 }
181211
182212 public makeClassDefinition (
213+ workspaceFolder : string ,
183214 position : vscode . Position ,
184215 start : number ,
185216 length : number ,
@@ -192,11 +223,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
192223 new vscode . Position ( position . line , start + length )
193224 ) ,
194225 targetRange : new vscode . Range ( firstLinePos , firstLinePos ) ,
195- targetUri : DocumentContentProvider . getUri ( name ) ,
226+ targetUri : DocumentContentProvider . getUri ( name , workspaceFolder ) ,
196227 } ;
197228 }
198229
199230 public makeRoutineDefinition (
231+ workspaceFolder : string ,
200232 position : vscode . Position ,
201233 start : number ,
202234 length : number ,
@@ -209,11 +241,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
209241 new vscode . Position ( position . line , start + length )
210242 ) ,
211243 targetRange : new vscode . Range ( firstLinePos , firstLinePos ) ,
212- targetUri : DocumentContentProvider . getUri ( name ) ,
244+ targetUri : DocumentContentProvider . getUri ( name , workspaceFolder ) ,
213245 } ;
214246 }
215247
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 } > {
217253 const fileName = file . name ;
218254 const api = new AtelierAPI ( ) ;
219255 let includes = [ ] ;
0 commit comments