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
|
||||
editor.onDidChangeModelContent((changeEvent) => {
|
||||
const model = editor.getModel();
|
||||
if (!model) {
|
||||
if (!model || model.getValue() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user