Skip to content

Commit

Permalink
[Auto Suggest] DQL Updates (opensearch-project#7498)
Browse files Browse the repository at this point in the history
* update code completion to not return for visualize

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* update types to match completionitemkind

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

---------

Signed-off-by: Paul Sebastian <paulstn@amazon.com>
  • Loading branch information
paulstn committed Jul 25, 2024
1 parent 3fff70e commit 27a74ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
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

0 comments on commit 27a74ab

Please sign in to comment.