From d0f82d95a6b814bf8ef6c94a36661354bf73fad1 Mon Sep 17 00:00:00 2001 From: alex <48489896+devnaumov@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:26:21 +0200 Subject: [PATCH] CB-5121 use different regex for long proposals mode (#2778) Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com> --- .../SQLEditor/useSqlDialectAutocompletion.ts | 19 +++++++++++++------ .../src/SqlEditorSettingsService.ts | 5 +++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/useSqlDialectAutocompletion.ts b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/useSqlDialectAutocompletion.ts index ace802e4e8..88b48f65a0 100644 --- a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/useSqlDialectAutocompletion.ts +++ b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/useSqlDialectAutocompletion.ts @@ -12,7 +12,7 @@ import { useService } from '@cloudbeaver/core-di'; import { LocalizationService } from '@cloudbeaver/core-localization'; import { GlobalConstants } from '@cloudbeaver/core-utils'; import type { Compartment, Completion, CompletionConfig, CompletionContext, CompletionResult, Extension } from '@cloudbeaver/plugin-codemirror6'; -import type { ISQLEditorData, SQLProposal } from '@cloudbeaver/plugin-sql-editor'; +import { type ISQLEditorData, SqlEditorSettingsService, type SQLProposal } from '@cloudbeaver/plugin-sql-editor'; const codemirrorComplexLoader = createComplexLoader(() => import('@cloudbeaver/plugin-codemirror6')); @@ -22,20 +22,27 @@ type SqlCompletion = Completion & { const CLOSE_CHARACTERS = /[\s()[\]{};:>,=\\*]/; const COMPLETION_WORD = /[\w*]*/; +const COMPLETION_WORD_LONG_PROPOSALS = /[\w.*]*/; export function useSqlDialectAutocompletion(data: ISQLEditorData): [Compartment, Extension] { const { closeCompletion, useEditorAutocompletion } = useComplexLoader(codemirrorComplexLoader); const localizationService = useService(LocalizationService); - const optionsRef = useObjectRef({ data }); + const sqlEditorSettingsService = useService(SqlEditorSettingsService); + const optionsRef = useObjectRef({ data, sqlEditorSettingsService }); const [config] = useState(() => { function getOptionsFromProposals(explicit: boolean, word: string, proposals: SQLProposal[]): SqlCompletion[] { const wordLowerCase = word.toLocaleLowerCase(); - const hasSameName = proposals.some(({ displayString }) => displayString.toLocaleLowerCase() === wordLowerCase); + const hasSameName = proposals.some( + ({ replacementString, displayString }) => + displayString.toLocaleLowerCase() === wordLowerCase || replacementString.toLocaleLowerCase() === wordLowerCase, + ); const filteredProposals = proposals .filter( - ({ displayString }) => - word === '*' || (displayString.toLocaleLowerCase() !== wordLowerCase && displayString.toLocaleLowerCase().startsWith(wordLowerCase)), + ({ replacementString, displayString }) => + word === '*' || + (displayString.toLocaleLowerCase() !== wordLowerCase && displayString.toLocaleLowerCase().startsWith(wordLowerCase)) || + (replacementString.toLocaleLowerCase() !== wordLowerCase && replacementString.toLocaleLowerCase().startsWith(wordLowerCase)), ) .sort((a, b) => (b.score ?? 0) - (a.score ?? 0)); @@ -63,7 +70,7 @@ export function useSqlDialectAutocompletion(data: ISQLEditorData): [Compartment, return null; } - const word = context.matchBefore(COMPLETION_WORD); + const word = context.matchBefore(optionsRef.sqlEditorSettingsService.longNameProposals ? COMPLETION_WORD_LONG_PROPOSALS : COMPLETION_WORD); if (word === null) { return null; diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditorSettingsService.ts b/webapp/packages/plugin-sql-editor/src/SqlEditorSettingsService.ts index 521393b0a5..23e3642ebb 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditorSettingsService.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditorSettingsService.ts @@ -56,6 +56,7 @@ const defaultSettings = schema.object({ }) .pipe(schema.enum(TABLE_ALIAS_OPTIONS)) .default('PLAIN'), + 'SQLEditor.ContentAssistant.proposals.long.name': schema.coerce.boolean().default(false), }); export type SqlEditorSettings = schema.infer; @@ -78,6 +79,10 @@ export class SqlEditorSettingsService extends Dependency { return this.settings.getValue('sql.proposals.insert.table.alias'); } + get longNameProposals(): boolean { + return this.settings.getValue('SQLEditor.ContentAssistant.proposals.long.name'); + } + readonly settings: SettingsProvider; constructor(