Tempo: Multi-line support for error markers in TraceQL editor (#75904)

* Don't show error when editor is empty

* Added multi-line support for error markers

* Fixed bug where new lines weren't being counted as characters

* Take startLine and endLine into account in column calculations

* Fix
This commit is contained in:
Andre Pereira 2023-10-10 13:53:43 +01:00 committed by GitHub
parent f40b695267
commit 1f9bd7466d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -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;
}

View File

@ -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,
};
})
);