mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
f40b695267
commit
1f9bd7466d
@ -70,7 +70,7 @@ export function TraceQLEditor(props: Props) {
|
|||||||
// Register callback for query changes
|
// Register callback for query changes
|
||||||
editor.onDidChangeModelContent((changeEvent) => {
|
editor.onDidChangeModelContent((changeEvent) => {
|
||||||
const model = editor.getModel();
|
const model = editor.getModel();
|
||||||
if (!model) {
|
if (!model || model.getValue() === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,17 +106,30 @@ export const setErrorMarkers = (
|
|||||||
model,
|
model,
|
||||||
'owner', // default value
|
'owner', // default value
|
||||||
errorNodes.map((errorNode) => {
|
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 {
|
return {
|
||||||
message: computeErrorMessage(errorNode),
|
message: computeErrorMessage(errorNode),
|
||||||
severity: monaco.MarkerSeverity.Error,
|
severity: monaco.MarkerSeverity.Error,
|
||||||
|
|
||||||
// As of now, we support only single-line queries
|
startLineNumber: startLine,
|
||||||
startLineNumber: 0,
|
endLineNumber: endLine,
|
||||||
endLineNumber: 0,
|
|
||||||
|
|
||||||
// `+ 1` because squiggles seem shifted by one
|
// `+ 2` because of the above computations
|
||||||
startColumn: errorNode.from + 1,
|
startColumn: start + model.getLineLength(startLine) + 2,
|
||||||
endColumn: errorNode.to + 1,
|
endColumn: end + model.getLineLength(endLine) + 2,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user