Skip to content

Commit

Permalink
specify dql operators in details and icon
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Sebastian <[email protected]>
  • Loading branch information
paulstn committed Sep 4, 2024
1 parent dc3f22d commit 4cc7be2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ export const getSuggestions = async ({
}
}

const dqlOperators = new Set([DQLParser.AND, DQLParser.OR, DQLParser.NOT]);

// suggest other candidates, mainly keywords
[...candidates.tokens.keys()].forEach((token: number) => {
// ignore identifier, already handled with field rule
Expand All @@ -262,11 +264,18 @@ export const getSuggestions = async ({
}

const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase();

if (tokenSymbolName) {
let type = monaco.languages.CompletionItemKind.Keyword;
let detail = SuggestionItemDetailsTags.Keyword;
if (dqlOperators.has(token)) {
type = monaco.languages.CompletionItemKind.Operator;
detail = SuggestionItemDetailsTags.Operator;
}
completions.push({
text: tokenSymbolName,
type: monaco.languages.CompletionItemKind.Keyword,
detail: SuggestionItemDetailsTags.Keyword,
type,
detail,
insertText: `${tokenSymbolName} `,
});
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/antlr/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const enum SuggestionItemDetailsTags {
Keyword = 'Keyword',
AggregateFunction = 'Aggregate Function',
Value = 'Value',
Operator = 'Operator',
}
export const quotesRegex = /^'(.*)'$/;

0 comments on commit 4cc7be2

Please sign in to comment.