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] Look and Feel changes #7991

Merged
merged 13 commits into from
Sep 6, 2024
Merged
6 changes: 6 additions & 0 deletions changelogs/fragments/7991.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
feat:
- Keep Autocomplete suggestion window open ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991))
paulstn marked this conversation as resolved.
Show resolved Hide resolved
- User hints below the suggestion window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991))

fix:
- DQL Autocomplete Operators distinguished ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991))
17 changes: 14 additions & 3 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const getSuggestions = async ({

// check to see if field rule is a candidate. if so, suggest field names
if (candidates.rules.has(DQLParser.RULE_field)) {
completions.push(...fetchFieldSuggestions(indexPattern, (f) => `${f}: `));
completions.push(...fetchFieldSuggestions(indexPattern, (f: any) => `${f}: `));
}

interface FoundLastValue {
Expand Down Expand Up @@ -247,12 +247,15 @@ export const getSuggestions = async ({
cursorLine,
cursorColumn + 1
),
insertText: `${val} `,
};
})
);
}
}

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 @@ -261,11 +264,19 @@ 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 = /^'(.*)'$/;
21 changes: 21 additions & 0 deletions src/plugins/data/public/ui/query_editor/_query_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,24 @@
border: none;
}
}

.suggest-widget {
position: relative;

&.visible::after {
paulstn marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
bottom: -30px;
left: 0;
width: 100%;
height: 30px;
background-color: $euiColorLightestShade;
border: 1px solid $euiColorLightShade;
padding: 5px;
paulstn marked this conversation as resolved.
Show resolved Hide resolved
padding-top: 4px;
text-align: left;
color: $euiColorDarkShade;
font-size: small;
content: "Tab to insert, ESC to close window";
display: block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const DefaultInput: React.FC<DefaultInputProps> = ({
}}
suggestionProvider={{
provideCompletionItems,
triggerCharacters: [' '],
}}
languageConfiguration={{
autoClosingPairs: [
Expand All @@ -65,6 +66,7 @@ export const DefaultInput: React.FC<DefaultInputProps> = ({
{ open: "'", close: "'" },
],
}}
triggerSuggestOnFocus={true}
/>
<div className="defaultEditor__footer">
{footerItems && (
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/ui/query_editor/editors/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const SingleLineInput: React.FC<SingleLineInputProps> = ({
}}
suggestionProvider={{
provideCompletionItems,
triggerCharacters: [' '],
}}
languageConfiguration={{
autoClosingPairs: [
Expand All @@ -108,6 +109,7 @@ export const SingleLineInput: React.FC<SingleLineInputProps> = ({
},
],
}}
triggerSuggestOnFocus={true}
/>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export default class QueryEditorUI extends Component<Props, State> {
insertText: s.insertText ?? s.text,
range: s.replacePosition ?? defaultRange,
detail: s.detail,
command: { id: 'editor.action.triggerSuggest', title: 'Trigger Next Suggestion' },
};
})
: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export interface Props {
* Should the editor use the dark theme
*/
useDarkTheme?: boolean;

/**
* Whether the suggestion widget/window will be triggered upon clicking into the editor
*/
triggerSuggestOnFocus?: boolean;
}

export class CodeEditor extends React.Component<Props, {}> {
Expand Down Expand Up @@ -141,6 +146,12 @@ export class CodeEditor extends React.Component<Props, {}> {
if (this.props.editorDidMount) {
this.props.editorDidMount(editor);
}

if (this.props.triggerSuggestOnFocus) {
editor.onDidFocusEditorWidget(() => {
editor.trigger('keyboard', 'editor.action.triggerSuggest', {});
});
}
};

render() {
Expand Down