Skip to content

Commit

Permalink
feat: make keyword filtering in completion provider configurable (#1204)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich authored Sep 27, 2023
1 parent 03e0cbf commit 9f4ec36
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/langium/src/lsp/completion/completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class DefaultCompletionProvider implements CompletionProvider {
try {
const scope = this.scopeProvider.getScope(refInfo);
scope.getAllElements().forEach(e => {
if (this.filterCrossReference(e)) {
if (this.filterCrossReference(context, e)) {
acceptor(context, this.createReferenceCompletionItem(e));
}
});
Expand All @@ -425,13 +425,12 @@ export class DefaultCompletionProvider implements CompletionProvider {
};
}

protected filterCrossReference(_nodeDescription: AstNodeDescription): boolean {
protected filterCrossReference(_context: CompletionContext, _nodeDescription: AstNodeDescription): boolean {
return true;
}

protected completionForKeyword(context: CompletionContext, keyword: ast.Keyword, acceptor: CompletionAcceptor): MaybePromise<void> {
// Filter out keywords that do not contain any word character
if (!keyword.value.match(/[\w]/)) {
if (!this.filterKeyword(context, keyword)) {
return;
}
acceptor(context, {
Expand All @@ -442,6 +441,11 @@ export class DefaultCompletionProvider implements CompletionProvider {
});
}

protected filterKeyword(_context: CompletionContext, keyword: ast.Keyword): boolean {
// Filter out keywords that do not contain any word character
return keyword.value.match(/[\w]/) !== null;
}

protected fillCompletionItem(context: CompletionContext, item: CompletionValueItem): CompletionItem | undefined {
let label: string;
if (typeof item.label === 'string') {
Expand Down

0 comments on commit 9f4ec36

Please sign in to comment.