Skip to content

Commit df125c4

Browse files
author
zhaoge
committed
feat(optimize reference and definition feat): optimize reference and definition feat
1 parent 1fa35ee commit df125c4

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

src/languageFeatures.ts

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
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';
35
import { WordPosition } from 'dt-sql-parser/dist/parser/common/textAndWord';
46
import * as monaco from 'monaco-editor';
57

@@ -13,7 +15,7 @@ import {
1315
MarkerSeverity,
1416
Position,
1517
Range,
16-
Uri
18+
Uri,
1719
} from './fillers/monaco-editor-core';
1820
import type { LanguageServiceDefaults } from './monaco.contribution';
1921

@@ -232,15 +234,27 @@ export class DefinitionAdapter<T extends BaseSQLWorker> implements languages.Def
232234
startColumn: -1,
233235
endColumn: -1
234236
};
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;
242241
}
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+
}
244258
if (pos && pos.line !== -1) {
245259
return {
246260
uri: model.uri,
@@ -281,21 +295,31 @@ export class ReferenceAdapter<T extends BaseSQLWorker> implements languages.Refe
281295
.then((entities) => {
282296
const word = model.getWordAtPosition(position);
283297
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;
297302
}
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+
}
299323
return arr;
300324
});
301325
}

0 commit comments

Comments
 (0)