From 65a29b8047f0ee7688e28a4e4ab2e6c4264db0c4 Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Fri, 8 Nov 2024 15:16:26 +0300 Subject: [PATCH] feat(autocomplete): suggest all columns in a row --- package-lock.json | 14 ++--- package.json | 2 +- .../NodeEndpointsTooltipContent.scss | 2 +- src/utils/monaco/yql/constants.ts | 2 +- src/utils/monaco/yql/generateSuggestions.ts | 63 +++++++++++++------ src/utils/monaco/yql/yqlSuggestions.ts | 4 +- 6 files changed, 56 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index cdbabb3c9..c3bd49752 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@gravity-ui/react-data-table": "^2.1.1", "@gravity-ui/table": "^0.5.0", "@gravity-ui/uikit": "^6.33.0", - "@gravity-ui/websql-autocomplete": "^9.1.0", + "@gravity-ui/websql-autocomplete": "^12.1.2", "@hookform/resolvers": "^3.9.0", "@reduxjs/toolkit": "^2.2.3", "@tanstack/react-table": "^8.19.3", @@ -4071,9 +4071,9 @@ } }, "node_modules/@gravity-ui/websql-autocomplete": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/websql-autocomplete/-/websql-autocomplete-9.1.0.tgz", - "integrity": "sha512-DshVPCCeHbt9s5WOcNgJElDmmqg53wzvzEaKt2dERv+v0NZGQ2PvU7LrfSZ9gJClSeewFf+4+ec25UTsYZ1zwg==", + "version": "12.1.2", + "resolved": "https://registry.npmjs.org/@gravity-ui/websql-autocomplete/-/websql-autocomplete-12.1.2.tgz", + "integrity": "sha512-f/G7CF3vUc/r/fvYvohImBeR9xcgcEWRRHU8wR6eUIFSOTRvo+XZuf9WcpaoK0WZRBRy8M4kpbe8wueg/KrvOQ==", "dependencies": { "antlr4-c3": "^3.4.1", "antlr4ng": "^3.0.4" @@ -7076,9 +7076,9 @@ } }, "node_modules/antlr4ng": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/antlr4ng/-/antlr4ng-3.0.4.tgz", - "integrity": "sha512-u1Ww6wVv9hq70E9AaYe5qW3ba8hvnjJdO3ZsKnb3iJWFV/medLEEhbyWwXCvvD2ef0ptdaiIUgmaazS/WE6uyQ==", + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/antlr4ng/-/antlr4ng-3.0.7.tgz", + "integrity": "sha512-e9VzrS6fErCUTmkZX2eKEMCsmYY87gVhmHkzmOXtUDgvwGhivUvtiHqlOByDx4Nd1PIQ0lMlhflOWEz6cGXqKA==", "peerDependencies": { "antlr4ng-cli": "^2.0.0" } diff --git a/package.json b/package.json index 77f6963c2..3f149d6b4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@gravity-ui/react-data-table": "^2.1.1", "@gravity-ui/table": "^0.5.0", "@gravity-ui/uikit": "^6.33.0", - "@gravity-ui/websql-autocomplete": "^9.1.0", + "@gravity-ui/websql-autocomplete": "^12.1.2", "@hookform/resolvers": "^3.9.0", "@reduxjs/toolkit": "^2.2.3", "@tanstack/react-table": "^8.19.3", diff --git a/src/components/TooltipsContent/NodeEndpointsTooltipContent/NodeEndpointsTooltipContent.scss b/src/components/TooltipsContent/NodeEndpointsTooltipContent/NodeEndpointsTooltipContent.scss index 234b60010..f484fc73f 100644 --- a/src/components/TooltipsContent/NodeEndpointsTooltipContent/NodeEndpointsTooltipContent.scss +++ b/src/components/TooltipsContent/NodeEndpointsTooltipContent/NodeEndpointsTooltipContent.scss @@ -7,6 +7,6 @@ } &__definition { text-align: right; - word-break: break-all; + word-break: break-word; } } diff --git a/src/utils/monaco/yql/constants.ts b/src/utils/monaco/yql/constants.ts index e6c7a4113..2d207aca5 100644 --- a/src/utils/monaco/yql/constants.ts +++ b/src/utils/monaco/yql/constants.ts @@ -1,4 +1,4 @@ -import type {YQLEntity} from '@gravity-ui/websql-autocomplete'; +import type {YQLEntity} from '@gravity-ui/websql-autocomplete/yql'; export const SimpleTypes = [ 'Text', diff --git a/src/utils/monaco/yql/generateSuggestions.ts b/src/utils/monaco/yql/generateSuggestions.ts index ef24722b5..471894186 100644 --- a/src/utils/monaco/yql/generateSuggestions.ts +++ b/src/utils/monaco/yql/generateSuggestions.ts @@ -1,9 +1,8 @@ import type { ColumnAliasSuggestion, KeywordSuggestion, - YQLEntity, - YqlAutocompleteResult, -} from '@gravity-ui/websql-autocomplete'; +} from '@gravity-ui/websql-autocomplete/shared'; +import type {YQLEntity, YqlAutocompleteResult} from '@gravity-ui/websql-autocomplete/yql'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; import type {AutocompleteEntityType, TAutocompleteEntity} from '../../../types/api/autocomplete'; @@ -123,24 +122,27 @@ function normalizeEntityPrefix(value = '', database: string) { return removeStartSlash(cleanedValue); } -type SuggestionType = keyof Omit; +type SuggestionType = + | keyof Omit + | 'suggestAllColumns'; const SuggestionsWeight: Record = { suggestTemplates: 0, suggestPragmas: 1, suggestEntity: 2, - suggestColumns: 3, - suggestColumnAliases: 4, - suggestTableIndexes: 5, - suggestTableHints: 6, - suggestEntitySettings: 7, - suggestKeywords: 8, - suggestAggregateFunctions: 9, - suggestTableFunctions: 10, - suggestWindowFunctions: 11, - suggestFunctions: 12, - suggestSimpleTypes: 13, - suggestUdfs: 14, + suggestAllColumns: 3, + suggestColumns: 4, + suggestColumnAliases: 5, + suggestTableIndexes: 6, + suggestTableHints: 7, + suggestEntitySettings: 8, + suggestKeywords: 9, + suggestAggregateFunctions: 10, + suggestTableFunctions: 11, + suggestWindowFunctions: 12, + suggestFunctions: 13, + suggestSimpleTypes: 14, + suggestUdfs: 15, }; function getSuggestionIndex(suggestionType: SuggestionType) { @@ -181,6 +183,7 @@ export async function generateColumnsSuggestion( return []; } const suggestions: monaco.languages.CompletionItem[] = []; + const normalizedColumns = suggestColumns.all ? ([] as string[]) : undefined; const multi = suggestColumns.tables.length > 1; const normalizedTableNames = @@ -228,6 +231,7 @@ export async function generateColumnsSuggestion( const normalizedParentName = normalizeEntityPrefix(col.Parent, database); const aliases = tableNameToAliasMap[normalizedParentName]; + const currentSuggestionIndex = suggestions.length; if (aliases?.length) { aliases.forEach((a) => { const columnNameSuggestion = `${a}.${normalizedName}`; @@ -237,8 +241,11 @@ export async function generateColumnsSuggestion( kind: CompletionItemKind.Field, detail: 'Column', range: rangeToInsertSuggestion, - sortText: suggestionIndexToWeight(getSuggestionIndex('suggestColumns')), + sortText: + suggestionIndexToWeight(getSuggestionIndex('suggestColumns')) + + suggestionIndexToWeight(currentSuggestionIndex), }); + normalizedColumns?.push(columnNameSuggestion); }); } else { let columnNameSuggestion = normalizedName; @@ -251,10 +258,24 @@ export async function generateColumnsSuggestion( kind: CompletionItemKind.Field, detail: 'Column', range: rangeToInsertSuggestion, - sortText: suggestionIndexToWeight(getSuggestionIndex('suggestColumns')), + sortText: + suggestionIndexToWeight(getSuggestionIndex('suggestColumns')) + + suggestionIndexToWeight(currentSuggestionIndex), }); + normalizedColumns?.push(columnNameSuggestion); } }); + if (normalizedColumns && normalizedColumns.length > 0) { + const allColumsn = normalizedColumns.join(', '); + suggestions.push({ + label: allColumsn, + insertText: allColumsn, + kind: CompletionItemKind.Field, + detail: 'All columns', + range: rangeToInsertSuggestion, + sortText: suggestionIndexToWeight(getSuggestionIndex('suggestAllColumns')), + }); + } return suggestions; } @@ -309,6 +330,7 @@ export async function generateEntitiesSuggestion( if (isDir && !withBackticks) { labelAsSnippet = `\`${label}$0\``; } + const suggestionIndex = acc.length; acc.push({ label, insertText: labelAsSnippet ?? label, @@ -321,7 +343,10 @@ export async function generateEntitiesSuggestion( command: label.endsWith('/') ? {id: 'editor.action.triggerSuggest', title: ''} : undefined, - sortText: suggestionIndexToWeight(getSuggestionIndex('suggestEntity')), + // first argument is responsible for sorting groups of suggestions, the second - to preserve suggestions order returned from backend + sortText: + suggestionIndexToWeight(getSuggestionIndex('suggestEntity')) + + suggestionIndexToWeight(suggestionIndex), }); return acc; }, [] as monaco.languages.CompletionItem[]); diff --git a/src/utils/monaco/yql/yqlSuggestions.ts b/src/utils/monaco/yql/yqlSuggestions.ts index 034f748a8..338faaac6 100644 --- a/src/utils/monaco/yql/yqlSuggestions.ts +++ b/src/utils/monaco/yql/yqlSuggestions.ts @@ -1,4 +1,4 @@ -import type {CursorPosition} from '@gravity-ui/websql-autocomplete'; +import type {CursorPosition} from '@gravity-ui/websql-autocomplete/shared'; import type Monaco from 'monaco-editor'; import { @@ -56,7 +56,7 @@ async function getSuggestions( rangeToInsertSuggestion: Monaco.IRange, database: string, ): Promise { - const {parseYqlQuery} = await import('@gravity-ui/websql-autocomplete'); + const {parseYqlQuery} = await import('@gravity-ui/websql-autocomplete/yql'); const cursorForParsing: CursorPosition = { line: cursorPosition.lineNumber, column: cursorPosition.column,