1
1
import type { ParseError } from 'dt-sql-parser' ;
2
- import { EntityContext } from 'dt-sql-parser/dist/parser/common/entityCollector' ;
2
+ import {
3
+ EntityContext ,
4
+ } from 'dt-sql-parser/dist/parser/common/entityCollector' ;
3
5
import { WordPosition } from 'dt-sql-parser/dist/parser/common/textAndWord' ;
4
6
import * as monaco from 'monaco-editor' ;
5
7
@@ -13,7 +15,7 @@ import {
13
15
MarkerSeverity ,
14
16
Position ,
15
17
Range ,
16
- Uri
18
+ Uri ,
17
19
} from './fillers/monaco-editor-core' ;
18
20
import type { LanguageServiceDefaults } from './monaco.contribution' ;
19
21
@@ -232,15 +234,27 @@ export class DefinitionAdapter<T extends BaseSQLWorker> implements languages.Def
232
234
startColumn : - 1 ,
233
235
endColumn : - 1
234
236
} ;
235
- entities ?. forEach ( ( entity : EntityContext ) => {
236
- if (
237
- entity . entityContextType . includes ( 'Create' ) &&
238
- word ?. word &&
239
- entity . text === word ?. word
240
- ) {
241
- pos = entity . position ;
237
+ const curEntity = entities ?. find ( ( entity : EntityContext ) => {
238
+ const entityPosition = entity . position ;
239
+ if ( entityPosition . startColumn === word ?. startColumn && entityPosition . endColumn === word ?. endColumn && entityPosition . line === position . lineNumber ) {
240
+ return entity ;
242
241
}
243
- } ) ;
242
+ return null ;
243
+ } )
244
+ if ( curEntity ) {
245
+ for ( let k in entities ) {
246
+ const entity = entities [ Number ( k ) ] ;
247
+ if (
248
+ entity . entityContextType . includes ( 'Create' ) &&
249
+ word ?. word &&
250
+ entity . text === word ?. word &&
251
+ entity . entityContextType . includes ( curEntity . entityContextType )
252
+ ) {
253
+ pos = entity . position ;
254
+ break ;
255
+ }
256
+ }
257
+ }
244
258
if ( pos && pos . line !== - 1 ) {
245
259
return {
246
260
uri : model . uri ,
@@ -281,21 +295,31 @@ export class ReferenceAdapter<T extends BaseSQLWorker> implements languages.Refe
281
295
. then ( ( entities ) => {
282
296
const word = model . getWordAtPosition ( position ) ;
283
297
const arr : languages . Location [ ] = [ ] ;
284
- entities ?. forEach ( ( entity ) => {
285
- if ( word ?. word && entity . text === word ?. word ) {
286
- let pos : WordPosition | null = null ;
287
- pos = entity . position ;
288
- arr . push ( {
289
- uri : model . uri ,
290
- range : new monaco . Range (
291
- pos ?. line ,
292
- pos ?. startColumn ,
293
- pos ?. line ,
294
- pos ?. endColumn
295
- )
296
- } ) ;
298
+ const curEntity = entities ?. find ( ( entity : EntityContext ) => {
299
+ const entityPosition = entity . position ;
300
+ if ( entityPosition . startColumn === word ?. startColumn && entityPosition . endColumn === word ?. endColumn && entityPosition . line === position . lineNumber ) {
301
+ return entity ;
297
302
}
298
- } ) ;
303
+ return null ;
304
+ } )
305
+ if ( curEntity ) {
306
+ entities ?. forEach ( ( entity ) => {
307
+ if ( word ?. word && entity . text === word ?. word && curEntity . entityContextType . includes ( entity . entityContextType ) ) {
308
+ let pos : WordPosition | null = null ;
309
+ pos = entity . position ;
310
+ arr . push ( {
311
+ uri : model . uri ,
312
+ range : new monaco . Range (
313
+ pos ?. line ,
314
+ pos ?. startColumn ,
315
+ pos ?. line ,
316
+ pos ?. endColumn
317
+ )
318
+ } ) ;
319
+ }
320
+ } ) ;
321
+
322
+ }
299
323
return arr ;
300
324
} ) ;
301
325
}
0 commit comments