mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Disable suggestions at beginning of value (#21302)
* Prometheus: Disable suggestions at beginning of value - fixed comparison operator regex - no longer suggest anything at beginning of label value * Detect cursor in front of label values
This commit is contained in:
parent
41fd265c64
commit
d63ad9ac93
@ -303,10 +303,17 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
const suggestions: CompletionItemGroup[] = [];
|
const suggestions: CompletionItemGroup[] = [];
|
||||||
const line = value.anchorBlock.getText();
|
const line = value.anchorBlock.getText();
|
||||||
const cursorOffset = value.selection.anchor.offset;
|
const cursorOffset = value.selection.anchor.offset;
|
||||||
const nextChar = line[cursorOffset];
|
const suffix = line.substr(cursorOffset);
|
||||||
const isValueContext = wrapperClasses.includes('attr-value');
|
const prefix = line.substr(0, cursorOffset);
|
||||||
if (!nextChar.match(/["}]/)) {
|
const isValueStart = text.match(/^(=|=~|!=|!~)/);
|
||||||
// Don't suggest anything inside a value
|
const isValueEnd = suffix.match(/^"?[,}]/);
|
||||||
|
// detect cursor in front of value, e.g., {key=|"}
|
||||||
|
const isPreValue = prefix.match(/(=|=~|!=|!~)$/) && suffix.match(/^"/);
|
||||||
|
|
||||||
|
// Don't suggestq anything at the beginning or inside a value
|
||||||
|
const isValueEmpty = isValueStart && isValueEnd;
|
||||||
|
const hasValuePrefix = isValueEnd && !isValueStart;
|
||||||
|
if ((!isValueEmpty && !hasValuePrefix) || isPreValue) {
|
||||||
return { suggestions };
|
return { suggestions };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +342,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let context: string;
|
let context: string;
|
||||||
if ((text && text.match(/^!?=~?/)) || isValueContext) {
|
if ((text && isValueStart) || wrapperClasses.includes('attr-value')) {
|
||||||
// Label values
|
// Label values
|
||||||
if (labelKey && labelValues[labelKey]) {
|
if (labelKey && labelValues[labelKey]) {
|
||||||
context = 'context-label-values';
|
context = 'context-label-values';
|
||||||
|
Loading…
Reference in New Issue
Block a user