Skip to content

Commit 136a5a2

Browse files
authored
[ES|QL] fix: Selecting a lookup index alias adds the $0 suffix (#234026)
Closes #233260 ## Summary Fixes a wrongly built completion item that was rendering a snippet symbol when selecting an index alias. Added a validation check in the test completion helper that verifies that every completion text using a snippet symbol has a `asSnippet` flag. https://github.com/user-attachments/assets/b6d8f171-d938-45dc-bcf9-05e0f88a167a ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
1 parent 0da625f commit 136a5a2

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/platform/packages/shared/kbn-esql-ast/src/__tests__/autocomplete.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export const expectSuggestions = async (
9191

9292
const suggestions: string[] = [];
9393
result.forEach((suggestion) => {
94+
if (containsSnippet(suggestion.text) && !suggestion.asSnippet) {
95+
throw new Error(
96+
`Suggestion with snippet placeholder must be marked as a snippet. -> ${suggestion.text}`
97+
);
98+
}
9499
suggestions.push(suggestion.text);
95100
});
96101
expect(uniq(suggestions).sort()).toEqual(uniq(expectedSuggestions).sort());
@@ -269,3 +274,10 @@ export function getLiteralsByType(_type: SupportedDataType | SupportedDataType[]
269274
}
270275
return [];
271276
}
277+
278+
export const containsSnippet = (text: string): boolean => {
279+
// Matches most common monaco snippets
280+
// $0, $1, etc. and ${1:placeholder}, ${2:another}
281+
const snippetRegex = /\$(\d+|\{\d+:[^}]*\})/;
282+
return snippetRegex.test(text);
283+
};

src/platform/packages/shared/kbn-esql-ast/src/commands_registry/commands/join/autocomplete.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export async function autocomplete(
5454
({
5555
label: mnemonic,
5656
text: mnemonic + ' $0',
57+
asSnippet: true,
5758
detail: description,
5859
kind: 'Keyword',
5960
sortText: `${i}-MNEMONIC`,

src/platform/packages/shared/kbn-esql-ast/src/definitions/utils/sources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export const specialIndicesToSuggestions = (
205205
aliasSuggestions.push({
206206
label: alias,
207207
text: alias + ' $0',
208+
asSnippet: true,
208209
kind: 'Issue',
209210
detail: i18n.translate('kbn-esql-ast.esql.autocomplete.specialIndexes.indexType.alias', {
210211
defaultMessage: 'Alias',

0 commit comments

Comments
 (0)