Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constats';
import {updateErrorsHighlighting} from '../../../../utils/monaco/highlightErrors';
import {QUERY_ACTIONS} from '../../../../utils/query';
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
import {
Expand Down Expand Up @@ -294,6 +295,7 @@ export default function QueryEditor(props: QueryEditorProps) {
};

const onChange = (newValue: string) => {
updateErrorsHighlighting();
changeUserInput({input: newValue});
};

Expand Down
1 change: 1 addition & 0 deletions src/containers/Tenant/Query/QueryEditor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const EDITOR_OPTIONS: EditorOptions = {
minimap: {
enabled: false,
},
fixedOverflowWidgets: true,
};

export function useEditorOptions() {
Expand Down
46 changes: 46 additions & 0 deletions src/utils/monaco/highlightErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {parseYqlQueryWithoutCursor} from '@gravity-ui/websql-autocomplete/yql';
import {debounce} from 'lodash';
import {MarkerSeverity, editor} from 'monaco-editor';

import i18n from './i18n';

const owner = 'ydb';

const debouncedHighlightErrors = debounce(highlightErrors, 500);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should cancel it on useEffect return


export function updateErrorsHighlighting() {
unHighlightErrors();

debouncedHighlightErrors();
}

function highlightErrors() {
const model = window.ydbEditor?.getModel();
if (!model) {
console.error('unable to retrieve model when highlighting errors');
return;
}

const errors = parseYqlQueryWithoutCursor(model.getValue()).errors;
if (!errors.length) {
unHighlightErrors();
return;
}

const markers = errors.map(
(error): editor.IMarkerData => ({
message: i18n('context_syntax-error'),
source: error.message,
severity: MarkerSeverity.Error,
startLineNumber: error.startLine,
startColumn: error.startColumn + 1,
endLineNumber: error.endLine,
endColumn: error.endColumn + 1,
}),
);
editor.setModelMarkers(model, owner, markers);
}

function unHighlightErrors(): void {
editor.removeAllMarkers(owner);
}
3 changes: 3 additions & 0 deletions src/utils/monaco/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"context_syntax-error": "Syntax error"
}
7 changes: 7 additions & 0 deletions src/utils/monaco/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {registerKeysets} from '../../i18n';

import en from './en.json';

const COMPONENT = 'ydb-monaco';

export default registerKeysets(COMPONENT, {en});
Loading