Skip to content

Commit

Permalink
dql Antlr autocomplete (opensearch-project#7160)
Browse files Browse the repository at this point in the history
* re-add provider for sql

Signed-off-by: Paul Sebastian <[email protected]>

* added temporary fix for language providor to appear for more than one language

Signed-off-by: Paul Sebastian <[email protected]>

---------

Signed-off-by: Paul Sebastian <[email protected]>
  • Loading branch information
paulstn committed Jul 24, 2024
1 parent 6e97987 commit 582aab6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class DataPublicPlugin

const ac = this.autocomplete.setup(core);
ac.addQuerySuggestionProvider('PPL', getPPLSuggestions);
ac.addQuerySuggestionProvider('SQL', getDQLSuggestions);
ac.addQuerySuggestionProvider('SQL', getSQLSuggestions);
ac.addQuerySuggestionProvider('kuery', getDQLSuggestions);

return {
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ import { QueryLanguageSelector } from './language_selector';
import { QueryEditorExtensions } from './query_editor_extensions';
import { QueryEditorBtnCollapse } from './query_editor_btn_collapse';

const LANGUAGE_ID = 'kuery';
monaco.languages.register({ id: LANGUAGE_ID });
const LANGUAGE_ID_SQL = 'SQL';
monaco.languages.register({ id: LANGUAGE_ID_SQL });

const LANGUAGE_ID_KUERY = 'kuery';
monaco.languages.register({ id: LANGUAGE_ID_KUERY });

export interface QueryEditorProps {
indexPatterns: Array<IIndexPattern | string>;
Expand Down Expand Up @@ -298,7 +301,7 @@ export default class QueryEditorUI extends Component<Props, State> {
}

public componentDidUpdate(prevProps: Props) {
if (prevProps.indexPatterns !== this.props.indexPatterns) {
if (!isEqual(prevProps.indexPatterns, this.props.indexPatterns)) {
this.fetchIndexPatterns();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,31 @@ export class CodeEditor extends React.Component<Props, {}> {
this.props.editorWillMount();
}

monaco.languages.onLanguage(this.props.languageId, () => {
if (this.props.suggestionProvider) {
monaco.languages.registerCompletionItemProvider(
this.props.languageId,
this.props.suggestionProvider
);
}

if (this.props.signatureProvider) {
monaco.languages.registerSignatureHelpProvider(
this.props.languageId,
this.props.signatureProvider
);
}

if (this.props.hoverProvider) {
monaco.languages.registerHoverProvider(this.props.languageId, this.props.hoverProvider);
}

if (this.props.languageConfiguration) {
monaco.languages.setLanguageConfiguration(
this.props.languageId,
this.props.languageConfiguration
);
}
// TEMPORARY fix for suggestion providor not appear for more than one language
['SQL', 'kuery'].forEach((language) => {
monaco.languages.onLanguage(language, () => {
if (this.props.suggestionProvider) {
monaco.languages.registerCompletionItemProvider(language, this.props.suggestionProvider);
}

if (this.props.signatureProvider) {
monaco.languages.registerSignatureHelpProvider(
this.props.languageId,
this.props.signatureProvider
);
}

if (this.props.hoverProvider) {
monaco.languages.registerHoverProvider(this.props.languageId, this.props.hoverProvider);
}

if (this.props.languageConfiguration) {
monaco.languages.setLanguageConfiguration(
this.props.languageId,
this.props.languageConfiguration
);
}
});
});

// Register the theme
Expand Down

0 comments on commit 582aab6

Please sign in to comment.