Skip to content

Commit

Permalink
create range parameter to help identify suggestions with whitespace, …
Browse files Browse the repository at this point in the history
…implemented dql value WS suggs

Signed-off-by: Paul Sebastian <[email protected]>
  • Loading branch information
paulstn committed Aug 30, 2024
1 parent 516212f commit 949e046
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ export const getSuggestions = async ({
text: val,
type: monaco.languages.CompletionItemKind.Value,
detail: SuggestionItemDetailsTags.Value,
replacePosition: new monaco.Range(
cursorLine,
cursorColumn - lastValue.length + 1,
cursorLine,
cursorColumn + 1
),
};
})
);
Expand Down
24 changes: 2 additions & 22 deletions src/plugins/data/public/antlr/opensearch_sql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,11 @@
*/

import { monaco } from '@osd/monaco';
import { Lexer as LexerType, ParserRuleContext, Parser as ParserType } from 'antlr4ng';
import { CodeCompletionCore } from 'antlr4-c3';
import {
AutocompleteResultBase,
CursorPosition,
EnrichAutocompleteResult,
GetParseTree,
KeywordSuggestion,
LexerConstructor,
OpenSearchSqlAutocompleteResult,
ParserConstructor,
} from '../shared/types';
import { TokenDictionary } from './table';
import { createParser } from './parse';
import { SqlErrorListener } from './sql_error_listerner';
import { findCursorTokenIndex } from '../shared/cursor';
import { CursorPosition, OpenSearchSqlAutocompleteResult } from '../shared/types';
import { openSearchSqlAutocompleteData } from './opensearch_sql_autocomplete';
import { SQL_SYMBOLS } from './constants';
import { QuerySuggestion, QuerySuggestionGetFnArgs } from '../../autocomplete';
import { fetchFieldSuggestions, fetchTableSchemas, parseQuery } from '../shared/utils';
import { IDataFrameResponse, IFieldType } from '../../../common';
import { fetchFieldSuggestions, parseQuery } from '../shared/utils';
import { SuggestionItemDetailsTags } from '../shared/constants';

export interface SuggestionParams {
Expand Down Expand Up @@ -71,8 +55,6 @@ export const getSuggestions = async ({
type: monaco.languages.CompletionItemKind.Function,
insertText: af,
detail: SuggestionItemDetailsTags.AggregateFunction,
start: 0,
end: 0,
}))
);
}
Expand All @@ -85,8 +67,6 @@ export const getSuggestions = async ({
type: monaco.languages.CompletionItemKind.Keyword,
insertText: sk.value,
detail: SuggestionItemDetailsTags.Keyword,
start: 0,
end: 0,
}))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface MonacoCompatibleQuerySuggestion
text: string;
detail: string;
insertText?: string;
replacePosition?: monaco.Range;
}

/** @public **/
Expand Down
31 changes: 21 additions & 10 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ import classNames from 'classnames';
import { isEqual } from 'lodash';
import React, { Component, createRef, RefObject } from 'react';
import { monaco } from '@osd/monaco';
import { IDataPluginServices, IFieldType, IIndexPattern, Query, TimeRange } from '../..';
import {
IDataPluginServices,
IFieldType,
IIndexPattern,
Query,
QuerySuggestion,
TimeRange,
} from '../..';
import { OpenSearchDashboardsReactContextValue } from '../../../../opensearch_dashboards_react/public';
import { QuerySuggestion } from '../../autocomplete';
import { fromUser, getQueryLog, PersistedLog, toUser } from '../../query';
import { SuggestionsListSize } from '../typeahead/suggestions_component';
import { QueryLanguageSelector } from './language_selector';
Expand All @@ -30,6 +36,7 @@ import { DatasetSelector } from '../dataset_selector';
import { QueryControls } from '../../query/query_string/language_service/get_query_control_links';
import { RecentQueriesTable } from '../../query/query_string/language_service/recent_query';
import { DefaultInputProps } from './editors';
import { MonacoCompatibleQuerySuggestion } from '../../autocomplete/providers/query_suggestion_provider';

export interface QueryEditorProps {
query: Query;
Expand Down Expand Up @@ -279,7 +286,7 @@ export default class QueryEditorUI extends Component<Props, State> {

// current completion item range being given as last 'word' at pos
const wordUntil = model.getWordUntilPosition(position);
const range = new monaco.Range(
const defaultRange = new monaco.Range(
position.lineNumber,
wordUntil.startColumn,
position.lineNumber,
Expand All @@ -289,13 +296,17 @@ export default class QueryEditorUI extends Component<Props, State> {
return {
suggestions:
suggestions && suggestions.length > 0
? suggestions.map((s: QuerySuggestion) => ({
label: s.text,
kind: s.type as monaco.languages.CompletionItemKind,
insertText: s.insertText ?? s.text,
range,
detail: 'detail' in s ? s.detail : '',
}))
? suggestions
.filter((s) => 'detail' in s) // remove suggestion not of type MonacoCompatible
.map((s: MonacoCompatibleQuerySuggestion) => {
return {
label: s.text,
kind: s.type as monaco.languages.CompletionItemKind,
insertText: s.insertText ?? s.text,
range: s.replacePosition ?? defaultRange,
detail: s.detail,
};
})
: [],
incomplete: false,
};
Expand Down

0 comments on commit 949e046

Please sign in to comment.