@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2
2
import { DocumentContentProvider } from './DocumentContentProvider' ;
3
3
import { AtelierAPI } from '../api' ;
4
4
import { ClassDefinition } from '../utils/classDefinition' ;
5
- import { currentFile } from '../utils' ;
5
+ import { currentFile , CurrentFile } from '../utils' ;
6
6
7
7
export class ObjectScriptDefinitionProvider implements vscode . DefinitionProvider {
8
8
provideDefinition (
@@ -39,9 +39,8 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
39
39
let macroText = macroRange ? document . getText ( macroRange ) : '' ;
40
40
let macroMatch = macroText . match ( / ^ \$ { 3 } ( \b \w + \b ) $ / ) ;
41
41
if ( macroMatch ) {
42
- let fileName = currentFile ( ) . name ;
43
42
let [ , macro ] = macroMatch ;
44
- return this . macro ( fileName , macro ) . then ( data =>
43
+ return this . macro ( currentFile ( ) , macro ) . then ( data =>
45
44
data && data . document . length
46
45
? new vscode . Location ( DocumentContentProvider . getUri ( data . document ) , new vscode . Position ( data . line , 0 ) )
47
46
: null
@@ -200,13 +199,21 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
200
199
} ;
201
200
}
202
201
203
- async macro ( fileName : string , macro : string ) : Promise < { document : string ; line : number } > {
202
+ async macro ( file : CurrentFile , macro : string ) : Promise < { document : string ; line : number } > {
203
+ let fileName = file . name ;
204
204
const api = new AtelierAPI ( ) ;
205
205
let includes = [ ] ;
206
206
if ( fileName . toLowerCase ( ) . endsWith ( 'cls' ) ) {
207
207
let classDefinition = new ClassDefinition ( fileName ) ;
208
208
includes = await classDefinition . includeCode ( ) ;
209
209
}
210
+ let tmpContent = file . content . replace ( / \r / , '' ) ;
211
+ let match = tmpContent . match ( new RegExp ( `^[\\t ]*#def(?:ine|1arg) \\b${ macro } \\b` , 'm' ) ) ;
212
+ if ( match ) {
213
+ let line = tmpContent . substr ( 0 , match . index ) . split ( '\n' ) . length - 1 ;
214
+ return Promise . resolve ( { document : fileName , line } ) ;
215
+ }
216
+
210
217
return api . getmacrolocation ( fileName , macro , includes ) . then ( data => data . result . content ) ;
211
218
}
212
219
}
0 commit comments