From 3bd84b1ead087844fa45bf72dee00bfd44bd9aca Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Wed, 22 Dec 2021 01:17:42 +0800 Subject: [PATCH] Add typescript.check.npmIsInstalled configuration --- Readme.md | 3 +++ package.json | 8 +++++++- src/server/features/fileConfigurationManager.ts | 4 +++- src/server/utils/configuration.ts | 2 +- src/server/utils/typingsStatus.ts | 15 ++++++++++++--- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 03ffc52..baadd25 100644 --- a/Readme.md +++ b/Readme.md @@ -132,6 +132,9 @@ for guide of coc.nvim's configuration. directory. These trace files can be used to diagnose TS Server performance issues. The log may contain file paths, source code, and other potentially sensitive information from your project, default: `false` +- `typescript.check.npmIsInstalled`: Check if npm is installed for [Automatic + Type + Acquisition](https://code.visualstudio.com/docs/nodejs/working-with-javascript#_typings-and-automatic-type-acquisition). - `typescript.updateImportsOnFileMove.enable`:Enable update imports on file move., default: `true` - `typescript.implementationsCodeLens.enable`:Enable codeLens for diff --git a/package.json b/package.json index 4b5ed22..ed90e4a 100644 --- a/package.json +++ b/package.json @@ -258,7 +258,7 @@ }, "tsserver.disableAutomaticTypeAcquisition": { "type": "boolean", - "default": true, + "default": false, "description": "Disable download of typings" }, "tsserver.useBatchedBufferSync": { @@ -266,6 +266,12 @@ "default": true, "description": "Use batched buffer sync support." }, + "typescript.check.npmIsInstalled": { + "type": "boolean", + "default": true, + "markdownDescription": "Check if npm is installed for [Automatic Type Acquisition](https://code.visualstudio.com/docs/nodejs/working-with-javascript#_typings-and-automatic-type-acquisition).", + "scope": "window" + }, "typescript.showUnused": { "type": "boolean", "default": true, diff --git a/src/server/features/fileConfigurationManager.ts b/src/server/features/fileConfigurationManager.ts index 1f39d28..2b8141a 100644 --- a/src/server/features/fileConfigurationManager.ts +++ b/src/server/features/fileConfigurationManager.ts @@ -177,7 +177,7 @@ export default class FileConfigurationManager { const config = workspace.getConfiguration(`${language}.preferences`, uri) const suggestConfig = this.getCompleteOptions(language) // getImportModuleSpecifierEndingPreference available on ts 2.9.0 - const preferences: Proto.UserPreferences & { importModuleSpecifierEnding?: string } = { + const preferences: Proto.UserPreferences = { quotePreference: this.getQuoteStyle(config), importModuleSpecifierPreference: getImportModuleSpecifier(config) as any, importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(config), @@ -191,6 +191,8 @@ export default class FileConfigurationManager { includeCompletionsForImportStatements: suggestConfig.includeCompletionsForImportStatements, includeCompletionsWithClassMemberSnippets: suggestConfig.includeCompletionsWithClassMemberSnippets, includeCompletionsWithSnippetText: suggestConfig.includeCompletionsWithSnippetText, + allowIncompleteCompletions: true, + displayPartsForJSDoc: true, } return preferences } diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index f6ae787..bac12d9 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -97,7 +97,7 @@ export class TypeScriptServiceConfiguration { } public get disableAutomaticTypeAcquisition(): boolean { - return this._configuration.get('disableAutomaticTypeAcquisition', true) + return this._configuration.get('disableAutomaticTypeAcquisition', false) } public get formatOnType(): boolean { diff --git a/src/server/utils/typingsStatus.ts b/src/server/utils/typingsStatus.ts index 8adf8b9..d1608a5 100644 --- a/src/server/utils/typingsStatus.ts +++ b/src/server/utils/typingsStatus.ts @@ -1,4 +1,4 @@ -import { StatusBarItem, window } from 'coc.nvim' +import { StatusBarItem, workspace, window } from 'coc.nvim' /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. @@ -110,10 +110,19 @@ export class AtaProgressReporter { } } - private onTypesInstallerInitializationFailed() { // tslint:disable-line + private async onTypesInstallerInitializationFailed() { // tslint:disable-line this.statusItem.hide() if (!this._invalid) { - window.showMessage('Could not install typings files for JavaScript language features. Please ensure that NPM is installed', 'error') + const config = workspace.getConfiguration('typescript') + if (config.get('check.npmIsInstalled', true)) { + const dontShowAgain = "Don't Show Again" + const selected = await window.showWarningMessage( + "Could not install typings files for JavaScript language features. Please ensure that NPM is installed or configure 'typescript.npm' in your user settings. visit https://go.microsoft.com/fwlink/?linkid=847635 to learn more.", + dontShowAgain) + if (selected === dontShowAgain) { + config.update('check.npmIsInstalled', false, true) + } + } } this._invalid = true }