Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug committed Jan 17, 2025
1 parent 3cf0cc1 commit 3f22c2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/utils/monaco/highlightErrors.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import {parseYqlQueryWithoutCursor} from '@gravity-ui/websql-autocomplete/yql';
import {MarkerSeverity, editor} from 'monaco-editor';

import i18n from './i18n';

const owner = 'ydb';

let errorsHighlightingTimeoutId: ReturnType<typeof setTimeout>;

export function disableErrorsHighlighting(): void {
export function updateErrorsHighlighting() {
unHighlightErrors();
}

export function updateErrorsHighlighting(): void {
disableErrorsHighlighting();

clearTimeout(errorsHighlightingTimeoutId);
errorsHighlightingTimeoutId = setTimeout(() => highlightErrors(), 500);
}

function highlightErrors(): void {
function highlightErrors() {
const model = window.ydbEditor?.getModel();
if (!model) {
console.error('unable to retrieve model when highlighting errors');
Expand All @@ -29,26 +27,21 @@ function highlightErrors(): void {
return;
}

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

function unHighlightErrors(): void {
editor.removeAllMarkers(owner);
}

function convertAutocompleteErrorLocationIndexToMonacoIndex(
autocompleteLocationIndex: number,
): number {
return autocompleteLocationIndex + 1;
}
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});

0 comments on commit 3f22c2f

Please sign in to comment.