From c56e800f23907c12e5e7750a98a26523556f26c0 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Wed, 20 Apr 2022 15:04:51 +0100 Subject: [PATCH] Add settings to enable/disable specific features (#535) * Add `suggest` and `hover` settings * Rename settings, add `codeActions` setting --- .../tailwindcss-language-server/src/server.ts | 10 +++++++++- .../src/util/state.ts | 3 +++ packages/vscode-tailwindcss/README.md | 12 ++++++++++++ packages/vscode-tailwindcss/package.json | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts index 97e4028..f082813 100644 --- a/packages/tailwindcss-language-server/src/server.ts +++ b/packages/tailwindcss-language-server/src/server.ts @@ -990,6 +990,8 @@ async function createProjectService( if (!state.enabled) return null let document = documentService.getDocument(params.textDocument.uri) if (!document) return null + let settings = await state.editor.getConfiguration(document.uri) + if (!settings.tailwindCSS.hovers) return null if (await isExcluded(state, document)) return null return doHover(state, document, params.position) }, @@ -997,6 +999,8 @@ async function createProjectService( if (!state.enabled) return null let document = documentService.getDocument(params.textDocument.uri) if (!document) return null + let settings = await state.editor.getConfiguration(document.uri) + if (!settings.tailwindCSS.suggestions) return null if (await isExcluded(state, document)) return null return doComplete(state, document, params.position, params.context) }, @@ -1004,8 +1008,12 @@ async function createProjectService( if (!state.enabled) return null return resolveCompletionItem(state, item) }, - onCodeAction(params: CodeActionParams): Promise { + async onCodeAction(params: CodeActionParams): Promise { if (!state.enabled) return null + let document = documentService.getDocument(params.textDocument.uri) + if (!document) return null + let settings = await state.editor.getConfiguration(document.uri) + if (!settings.tailwindCSS.codeActions) return null return doCodeActions(state, params) }, provideDiagnostics: debounce((document: TextDocument) => { diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts index 30c8fba..061dd11 100644 --- a/packages/tailwindcss-language-service/src/util/state.ts +++ b/packages/tailwindcss-language-service/src/util/state.ts @@ -41,6 +41,9 @@ export type Settings = { emmetCompletions: boolean includeLanguages: Record classAttributes: string[] + suggestions: boolean + hovers: boolean + codeActions: boolean validate: boolean showPixelEquivalents: boolean rootFontSize: number diff --git a/packages/vscode-tailwindcss/README.md b/packages/vscode-tailwindcss/README.md index 0104716..ce5068f 100644 --- a/packages/vscode-tailwindcss/README.md +++ b/packages/vscode-tailwindcss/README.md @@ -94,6 +94,18 @@ Show `px` equivalents for `rem` CSS values in completions and hovers. **Default: Root font size in pixels. Used to convert `rem` CSS values to their `px` equivalents. See [`tailwindCSS.showPixelEquivalents`](#tailwindcssshowpixelequivalents). **Default: `16`** +### `tailwindCSS.hovers` + +Enable hovers. **Default: `true`** + +### `tailwindCSS.suggestions` + +Enable autocomplete suggestions. **Default: `true`** + +### `tailwindCSS.codeActions` + +Enable code actions. **Default: `true`** + ### `tailwindCSS.validate` Enable linting. Rules can be configured individually using the `tailwindcss.lint` settings: diff --git a/packages/vscode-tailwindcss/package.json b/packages/vscode-tailwindcss/package.json index b877a1d..2544420 100755 --- a/packages/vscode-tailwindcss/package.json +++ b/packages/vscode-tailwindcss/package.json @@ -160,6 +160,24 @@ ], "markdownDescription": "The HTML attributes for which to provide class completions, hover previews, linting etc." }, + "tailwindCSS.suggestions": { + "type": "boolean", + "default": true, + "markdownDescription": "Enable autocomplete suggestions.", + "scope": "language-overridable" + }, + "tailwindCSS.hovers": { + "type": "boolean", + "default": true, + "markdownDescription": "Enable hovers.", + "scope": "language-overridable" + }, + "tailwindCSS.codeActions": { + "type": "boolean", + "default": true, + "markdownDescription": "Enable code actions.", + "scope": "language-overridable" + }, "tailwindCSS.colorDecorators": { "type": "boolean", "default": true,