Skip to content

Commit f8a23ed

Browse files
committed
refactor: completion item service option
1 parent a457ae5 commit f8a23ed

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

packages/dbml-parse/src/compiler/index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -374,26 +374,31 @@ export default class Compiler {
374374
scopeKind: this.localQuery(containerScopeKind),
375375
};
376376

377-
async initMonacoServices () {
377+
async initMonacoServices (options?: {
378+
autocompletion?: {
379+
triggerCharacters?: string[];
380+
};
381+
}) {
382+
const triggerCharacters = options?.autocompletion?.triggerCharacters ?? [
383+
'.',
384+
',',
385+
'[',
386+
'(',
387+
':',
388+
'>',
389+
'<',
390+
'-',
391+
'~',
392+
'\'',
393+
'"',
394+
'/',
395+
' ',
396+
];
397+
378398
return {
379399
definitionProvider: new DBMLDefinitionProvider(this),
380400
referenceProvider: new DBMLReferencesProvider(this),
381-
// Trigger completion on these characters
382-
autocompletionProvider: new DBMLCompletionItemProvider(this, [
383-
'.',
384-
',',
385-
'[',
386-
'(',
387-
':',
388-
'>',
389-
'<',
390-
'-',
391-
'~',
392-
'\'',
393-
'"',
394-
'/',
395-
' ',
396-
]),
401+
autocompletionProvider: new DBMLCompletionItemProvider(this, { triggerCharacters }),
397402
diagnosticsProvider: new DBMLDiagnosticsProvider(this),
398403
};
399404
}

packages/dbml-parse/src/services/suggestions/provider.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
isOffsetWithinSpan,
5353
} from '@/core/utils/span';
5454
import {
55-
buildCrossFileCompletionItem,
5655
collectCrossFileSuggestions,
5756
} from '@/services/suggestions/crossFile';
5857
import {
@@ -85,46 +84,18 @@ import {
8584
getOffsetFromMonacoPosition,
8685
} from '@/services/utils';
8786

87+
export interface DBMLCompletionItemProviderOptions {
88+
triggerCharacters?: string[];
89+
}
90+
8891
export default class DBMLCompletionItemProvider implements CompletionItemProvider {
8992
private compiler: Compiler;
9093

9194
triggerCharacters: string[];
9295

93-
constructor (compiler: Compiler, triggerCharacters: string[] = []) {
96+
constructor (compiler: Compiler, options: DBMLCompletionItemProviderOptions = {}) {
9497
this.compiler = compiler;
95-
this.triggerCharacters = triggerCharacters;
96-
}
97-
98-
// Cross-file suggestion surfaces symbols from sibling project files at
99-
// global-scope lookup points. Implementation in ./crossFile.ts — these
100-
// thin wrappers keep the public provider surface stable for existing
101-
// call sites that want a CompletionList.
102-
suggestCrossFileSymbols (
103-
acceptedKinds: SymbolKind[],
104-
currentFilepath: Filepath,
105-
_currentFileContent: string,
106-
): CompletionList {
107-
return {
108-
suggestions: collectCrossFileSuggestions(this.compiler, acceptedKinds, currentFilepath),
109-
};
110-
}
111-
112-
createCrossFileCompletionItem (
113-
symbolName: string,
114-
symbolKind: SymbolKind,
115-
_fileHint: string,
116-
sourceFilepath: Filepath,
117-
currentFilepath: Filepath,
118-
currentFileContent: string,
119-
): CompletionItem {
120-
return buildCrossFileCompletionItem(
121-
this.compiler,
122-
symbolName,
123-
symbolKind,
124-
sourceFilepath,
125-
currentFilepath,
126-
currentFileContent,
127-
);
98+
this.triggerCharacters = options.triggerCharacters ?? [];
12899
}
129100

130101
provideCompletionItems (model: TextModel, position: Position): CompletionList {

0 commit comments

Comments
 (0)