Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auto Suggest] DQL Updates #7498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import { CharStream, CommonTokenStream, TokenStream } from 'antlr4ng';
import { CodeCompletionCore } from 'antlr4-c3';
import { HttpSetup } from 'opensearch-dashboards/public';
import { monaco } from '@osd/monaco';
import { DQLLexer } from './.generated/DQLLexer';
import { DQLParser, KeyValueExpressionContext } from './.generated/DQLParser';
import { getTokenPosition } from '../shared/cursor';
import { IndexPattern, IndexPatternField } from '../../index_patterns';
import { IndexPatternField } from '../../index_patterns';
import { QuerySuggestionGetFnArgs } from '../../autocomplete';
import { DQLParserVisitor } from './.generated/DQLParserVisitor';
import { getUiService } from '../../services';

const findCursorIndex = (
tokenStream: TokenStream,
Expand Down Expand Up @@ -43,11 +45,12 @@ const findFieldSuggestions = (indexPattern: any) => {
return idxField.name;
});

const fieldSuggestions: Array<{ text: string; type: string }> = fieldNames.map(
(field: string) => {
return { text: field, type: 'field' };
}
);
const fieldSuggestions: Array<{
text: string;
type: monaco.languages.CompletionItemKind;
}> = fieldNames.map((field: string) => {
return { text: field, type: monaco.languages.CompletionItemKind.Field };
});

return fieldSuggestions;
};
Expand Down Expand Up @@ -116,7 +119,16 @@ export const getSuggestions = async ({
position,
selectionEnd,
core: coreSetup,
services,
}: QuerySuggestionGetFnArgs) => {
if (
!services ||
!services.appName ||
!getUiService().Settings.supportsEnhancementsEnabled(services.appName)
) {
return [];
}

const http = coreSetup?.http;
const currentIndexPattern = indexPatterns[0];

Expand Down Expand Up @@ -173,7 +185,7 @@ export const getSuggestions = async ({
if (!!values) {
completions.push(
...values?.map((val: any) => {
return { text: val, type: 'value' };
return { text: val, type: monaco.languages.CompletionItemKind.Value };
})
);
}
Expand All @@ -187,7 +199,7 @@ export const getSuggestions = async ({
}

const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase();
completions.push({ text: tokenSymbolName, type: 'keyword' });
completions.push({ text: tokenSymbolName, type: monaco.languages.CompletionItemKind.Keyword });
});

return completions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface QuerySuggestionGetFnArgs {
signal?: AbortSignal;
boolFilter?: any;
position?: monaco.Position;
connectionService?: any; // will need to add type when ConnectionService is properly exposed from queryEnhancements
services?: any; // will need to add type when ConnectionService is properly exposed from queryEnhancements
core?: CoreSetup;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default class QueryEditorUI extends Component<Props, State> {
language: this.props.query.language,
indexPatterns,
position,
openSearchDashboards: this.services,
services: this.services,
});

return {
Expand Down
Loading