Skip to content

Commit ac61186

Browse files
committed
Fixes
1 parent be66035 commit ac61186

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/platform/packages/shared/kbn-esql-language/src/commands/registry/stats/autocomplete.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ import {
2929
} from '../../definitions/all_operators';
3030
import type { ICommandCallbacks } from '../types';
3131
import type { FunctionReturnType } from '../../definitions/types';
32-
import {
33-
ESQL_NUMBER_TYPES,
34-
FunctionDefinitionTypes,
35-
ESQL_COMMON_NUMERIC_TYPES,
36-
} from '../../definitions/types';
32+
import { FunctionDefinitionTypes, ESQL_COMMON_NUMERIC_TYPES } from '../../definitions/types';
3733
import { findAutocompleteAstPosition } from '../../../language/shared/parse_for_autocomplete_query';
3834
import { setTestFunctions } from '../../definitions/utils/test_functions';
3935
import {
@@ -307,7 +303,7 @@ describe('STATS Autocomplete', () => {
307303
...getFieldNamesByType(roundParameterTypes),
308304
...getFunctionSignaturesByReturnType(
309305
Location.STATS_BY,
310-
ESQL_NUMBER_TYPES,
306+
roundParameterTypes,
311307
{ scalar: true, grouping: true },
312308
undefined,
313309
['round']
@@ -321,7 +317,7 @@ describe('STATS Autocomplete', () => {
321317
...getFieldNamesByType(roundParameterTypes),
322318
...getFunctionSignaturesByReturnType(
323319
Location.STATS_BY,
324-
ESQL_NUMBER_TYPES,
320+
roundParameterTypes,
325321
{ scalar: true, grouping: true },
326322
undefined,
327323
['round']

src/platform/packages/shared/kbn-esql-language/src/language/hover/helpers.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,22 @@ export const getVariablesHoverContent = (
3939
return buildVariablesHoverContent(usedVariablesInNode, variables);
4040
};
4141

42+
const getParamNameAtOffset = (text: string, offset: number): string | undefined => {
43+
let start = offset;
44+
while (start > 0 && /\w/.test(text[start - 1])) start--;
45+
if (start > 0 && text[start - 1] === '?') {
46+
let end = offset;
47+
while (end < text.length && /\w/.test(text[end])) end++;
48+
return text.slice(start, end);
49+
}
50+
return undefined;
51+
};
52+
4253
export function getPromqlHoverItem(
4354
root: WalkerAstNode,
4455
offset: number,
45-
callbacks?: ESQLCallbacks
56+
callbacks?: ESQLCallbacks,
57+
fullText?: string
4658
): { contents: Array<{ value: string }> } {
4759
let functionNode: PromQLFunction | undefined;
4860
let selectorNode: PromQLSelector | undefined;
@@ -80,6 +92,19 @@ export function getPromqlHoverItem(
8092
}
8193
}
8294

95+
// Fallback for params in PromQL label matchers: the PromQL parser doesn't store
96+
// named params in label.value, so the Walker never visits them. Scan the raw text.
97+
if (!paramNode && fullText) {
98+
const paramName = getParamNameAtOffset(fullText, offset);
99+
if (paramName) {
100+
const variables = callbacks?.getVariables?.();
101+
const variablesContent = buildVariablesHoverContent([paramName], variables);
102+
if (variablesContent.length) {
103+
return { contents: variablesContent };
104+
}
105+
}
106+
}
107+
83108
if (literalNode) {
84109
const hoverType = literalNode.literalType === 'time' ? 'duration' : 'scalar';
85110

src/platform/packages/shared/kbn-esql-language/src/language/hover/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function getHoverItem(fullText: string, offset: number, callbacks?:
3232
const commandAtOffset = [...root.commands].reverse().find((cmd) => offset >= cmd.location.min);
3333

3434
if (commandAtOffset?.name === 'promql') {
35-
return getPromqlHoverItem(root, offset, callbacks);
35+
return getPromqlHoverItem(root, offset, callbacks, fullText);
3636
}
3737

3838
let containingFunction: ESQLFunction<'variadic-call'> | undefined;

0 commit comments

Comments
 (0)