From 2d52a842cbde2dff1e1504cdba1f98ad193673ed Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Tue, 21 Dec 2021 13:54:47 +0800 Subject: [PATCH] feat: includeCompletionsWithClassMemberSnippets (#321) * docs: update yarn configuration (#311) * feat: includeCompletionsWithClassMemberSnippets typescript.suggest.includeCompletionsWithClassMemberSnippets Co-authored-by: KY64 <31939494+KY64@users.noreply.github.com> --- Readme.md | 3 +++ package.json | 6 ++++++ src/server/features/completionItemProvider.ts | 2 +- src/server/features/fileConfigurationManager.ts | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index b2a2696..a5c9ade 100644 --- a/Readme.md +++ b/Readme.md @@ -156,6 +156,9 @@ for guide of coc.nvim's configuration. TypeScript 4.3+ in the workspace, default: `true` - `typescript.suggest.includeCompletionsWithSnippetText`: Enable snippet completions from TS Server. Requires using TypeScript 4.3+ in the workspace, default: `true` +- `typescript.suggest.includeCompletionsWithClassMemberSnippets`: Enable/disable + snippet completions for class members. Requires using TypeScript 4.5+ in the + workspace, default: `true` - `typescript.format.enabled`:Enable/disable format of typescript files. - `typescript.format.insertSpaceAfterCommaDelimiter` default: `true` - `typescript.format.insertSpaceAfterConstructor` default: `false` diff --git a/package.json b/package.json index 103bd80..029a1d2 100644 --- a/package.json +++ b/package.json @@ -390,6 +390,12 @@ "description": "Enable/disable snippet completions from TS Server. Requires using TypeScript 4.3+ in the workspace.", "scope": "resource" }, + "typescript.suggest.includeCompletionsWithClassMemberSnippets": { + "type": "boolean", + "default": true, + "description": "Enable/disable snippet completions for class members. Requires using TypeScript 4.5+ in the workspace", + "scope": "resource" + }, "typescript.format.enabled": { "type": "boolean", "default": true, diff --git a/src/server/features/completionItemProvider.ts b/src/server/features/completionItemProvider.ts index 7f2ad21..25733cf 100644 --- a/src/server/features/completionItemProvider.ts +++ b/src/server/features/completionItemProvider.ts @@ -259,7 +259,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP item.additionalTextEdits = additionalTextEdits if (detail && item.insertTextFormat == InsertTextFormat.Snippet) { const shouldCompleteFunction = await this.isValidFunctionCompletionContext(filepath, position, token) - if (shouldCompleteFunction) { + if (shouldCompleteFunction && !item.insertText) { this.createSnippetOfFunctionCall(item, detail) } } diff --git a/src/server/features/fileConfigurationManager.ts b/src/server/features/fileConfigurationManager.ts index 6d83e56..8c6e796 100644 --- a/src/server/features/fileConfigurationManager.ts +++ b/src/server/features/fileConfigurationManager.ts @@ -40,6 +40,7 @@ export interface SuggestOptions { readonly importStatementSuggestions: boolean readonly includeCompletionsForImportStatements: boolean readonly includeCompletionsWithSnippetText: boolean + readonly includeCompletionsWithClassMemberSnippets: boolean } export default class FileConfigurationManager { @@ -162,6 +163,7 @@ export default class FileConfigurationManager { importStatementSuggestions: config.get('importStatements', true), includeCompletionsForImportStatements: config.get('includeCompletionsForImportStatements', true), includeCompletionsWithSnippetText: config.get('includeCompletionsWithSnippetText', true), + includeCompletionsWithClassMemberSnippets: config.get('includeCompletionsWithClassMemberSnippets', true), includeAutomaticOptionalChainCompletions: config.get('includeAutomaticOptionalChainCompletions', true) } } @@ -182,6 +184,7 @@ export default class FileConfigurationManager { allowRenameOfImportPath: true, providePrefixAndSuffixTextForRename: config.get('renameShorthandProperties', true) === false ? false : config.get('useAliasesForRenames', true), includeCompletionsForImportStatements: this.getCompleteOptions(language).includeCompletionsForImportStatements, + includeCompletionsWithClassMemberSnippets: this.getCompleteOptions(language).includeCompletionsWithClassMemberSnippets, includeCompletionsWithSnippetText: this.getCompleteOptions(language).includeCompletionsWithSnippetText, } return preferences