diff --git a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx index c8f2dd7f4f5..42d83347505 100644 --- a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx +++ b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx @@ -70,7 +70,7 @@ export function TraceQLEditor(props: Props) { // Register callback for query changes editor.onDidChangeModelContent((changeEvent) => { const model = editor.getModel(); - if (!model) { + if (!model || model.getValue() === '') { return; } diff --git a/public/app/plugins/datasource/tempo/traceql/errorHighlighting.ts b/public/app/plugins/datasource/tempo/traceql/errorHighlighting.ts index b9b50641500..dff1c7f9715 100644 --- a/public/app/plugins/datasource/tempo/traceql/errorHighlighting.ts +++ b/public/app/plugins/datasource/tempo/traceql/errorHighlighting.ts @@ -106,17 +106,30 @@ export const setErrorMarkers = ( model, 'owner', // default value errorNodes.map((errorNode) => { + let startLine = 0; + let endLine = 0; + let start = errorNode.from; + let end = errorNode.to; + + while (start > 0) { + startLine++; + start -= model.getLineLength(startLine) + 1; // new lines don't count for getLineLength() but they still count as a character for the parser + } + while (end > 0) { + endLine++; + end -= model.getLineLength(endLine) + 1; + } + return { message: computeErrorMessage(errorNode), severity: monaco.MarkerSeverity.Error, - // As of now, we support only single-line queries - startLineNumber: 0, - endLineNumber: 0, + startLineNumber: startLine, + endLineNumber: endLine, - // `+ 1` because squiggles seem shifted by one - startColumn: errorNode.from + 1, - endColumn: errorNode.to + 1, + // `+ 2` because of the above computations + startColumn: start + model.getLineLength(startLine) + 2, + endColumn: end + model.getLineLength(endLine) + 2, }; }) );