Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Add `files.exclude` setting
Brad Cornes <bradlc41@gmail.com>
2 years ago
8 changed files, 141 additions(+), 31 deletions(-)
M packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts -> packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts
diff --git a/packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts b/packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts
index 4936767219aac04e8b2a9c171e6ef2eaf4cb7603..e5f01a8998bd771b9bd02cd78332e2dda1033527 100644
--- a/packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts
+++ b/packages/tailwindcss-language-server/src/lsp/diagnosticsProvider.ts
@@ -1,12 +1,17 @@
 import { TextDocument } from 'vscode-languageserver/node'
 import { State } from 'tailwindcss-language-service/src/util/state'
 import { doValidate } from 'tailwindcss-language-service/src/diagnostics/diagnosticsProvider'
+import isExcluded from '../util/isExcluded'
 
 export async function provideDiagnostics(state: State, document: TextDocument) {
-  state.editor?.connection.sendDiagnostics({
+  if (await isExcluded(state, document)) {
+    clearDiagnostics(state, document)
+  } else {
+    state.editor?.connection.sendDiagnostics({
+      uri: document.uri,
-    uri: document.uri,
+      diagnostics: await doValidate(state, document),
-    diagnostics: await doValidate(state, document),
+    })
-  })
+  }
 }
 
 export function clearDiagnostics(state: State, document: TextDocument): void {
M packages/tailwindcss-language-server/src/server.ts -> packages/tailwindcss-language-server/src/server.ts
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index c23e57b9a91ec4b998b7ed19c48b8f7de8382a7d..f05c842feb17c67448b4e07269c7d47e020f7343 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -78,6 +78,9 @@ import * as culori from 'culori'
 import namedColors from 'color-name'
 import preflight from './lib/preflight'
 import tailwindPlugins from './lib/plugins'
+import isExcluded from './util/isExcluded'
+import { getFileFsPath, normalizeFileNameToFsPath } from './util/uri'
+import { equal } from 'tailwindcss-language-service/src/util/array'
 
 let oldReadFileSync = fs.readFileSync
 // @ts-ignore
@@ -120,14 +123,6 @@
 process.on('unhandledRejection', (e: any) => {
   connection.console.error(formatError(`Unhandled exception`, e))
 })
-
-function normalizeFileNameToFsPath(fileName: string) {
-  return URI.file(fileName).fsPath
-}
-
-function getFileFsPath(documentUri: string): string {
-  return URI.parse(documentUri).fsPath
-}
 
 function deletePropertyPath(obj: any, path: string | string[]): void {
   if (typeof path === 'string') {
@@ -220,6 +215,7 @@   const state: State = {
     enabled: false,
     editor: {
       connection,
+      folder,
       globalSettings: params.initializationOptions.configuration as Settings,
       userLanguages: params.initializationOptions.userLanguages
         ? params.initializationOptions.userLanguages
@@ -258,14 +254,8 @@   const documentSettingsCache: Map<string, Settings> = new Map()
   let registrations: Promise<BulkUnregistration>
 
   let chokidarWatcher: chokidar.FSWatcher
-  let ignore = [
-import {
   ColorPresentation,
-    '**/.git/subtree-cache/**',
-    '**/node_modules/**',
-  DocumentColorRequest,
   CompletionItem,
-  ]
 
   function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void {
     let needsInit = false
@@ -458,7 +447,7 @@
     let [configPath] = (
       await glob([`**/${CONFIG_FILE_GLOB}`], {
         cwd: folder,
-  CompletionItem,
+  ColorPresentation,
 import { URI } from 'vscode-uri'
         onlyFiles: true,
         absolute: true,
@@ -992,32 +981,46 @@       }
     },
     onUpdateSettings(settings: any): void {
       documentSettingsCache.clear()
-import assert from 'assert'
+import './lib/env'
+import { formatError, showError, SilentError } from './util/error'
-import assert from 'assert'
 import './lib/env'
+import glob from 'fast-glob'
 import './lib/env'
-  Connection,
   CompletionItem,
-      if (settings.editor.colorDecorators) {
+  CompletionList,
-import assert from 'assert'
+  ColorPresentation,
   CompletionItem,
+  CompletionParams,
       } else {
+  '/',
   Connection,
+          updateAllDiagnostics(state)
+import './lib/env'
   ColorInformation,
+import {
+        if (settings.editor.colorDecorators) {
+          registerCapabilities(state.dependencies)
+  CodeActionRequest,
   CompletionList,
 import './lib/env'
+import minimatch from 'minimatch'
+        }
+import './lib/env'
   clearAllDiagnostics,
     },
-    onHover(params: TextDocumentPositionParams): Promise<Hover> {
+    async onHover(params: TextDocumentPositionParams): Promise<Hover> {
       if (!state.enabled) return null
       let document = documentService.getDocument(params.textDocument.uri)
       if (!document) return null
+      if (await isExcluded(state, document)) return null
       return doHover(state, document, params.position)
     },
-  createConnection,
+import './lib/env'
+import Module from 'module'
       if (!state.enabled) return null
       let document = documentService.getDocument(params.textDocument.uri)
       if (!document) return null
+      if (await isExcluded(state, document)) return null
       return doComplete(state, document, params.position, params.context)
     },
     onCompletionResolve(item: CompletionItem): Promise<CompletionItem> {
@@ -1035,6 +1038,8 @@     async onDocumentColor(params: DocumentColorParams): Promise<ColorInformation[]> {
       if (!state.enabled) return []
       let document = documentService.getDocument(params.textDocument.uri)
 import * as parcel from './watcher/index.js'
+import {
+] as const
 import {
       return getDocumentColors(state, document)
     },
I packages/tailwindcss-language-server/src/util/isExcluded.ts
diff --git a/packages/tailwindcss-language-server/src/util/isExcluded.ts b/packages/tailwindcss-language-server/src/util/isExcluded.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9f48b83e570325e0d3b6ef24f76eed441742145f
--- /dev/null
+++ b/packages/tailwindcss-language-server/src/util/isExcluded.ts
@@ -0,0 +1,18 @@
+import minimatch from 'minimatch'
+import * as path from 'path'
+import { State } from 'tailwindcss-language-service/src/util/state'
+import { TextDocument } from 'vscode-languageserver-textdocument'
+import { getFileFsPath } from './uri'
+
+export default async function isExcluded(state: State, document: TextDocument): Promise<boolean> {
+  let settings = await state.editor.getConfiguration(document.uri)
+  let file = getFileFsPath(document.uri)
+
+  for (let pattern of settings.tailwindCSS.files.exclude) {
+    if (minimatch(file, path.join(state.editor.folder, pattern))) {
+      return true
+    }
+  }
+
+  return false
+}
I packages/tailwindcss-language-server/src/util/uri.ts
diff --git a/packages/tailwindcss-language-server/src/util/uri.ts b/packages/tailwindcss-language-server/src/util/uri.ts
new file mode 100644
index 0000000000000000000000000000000000000000..492d32f5a06687eb555226fa5626c9d0493861db
--- /dev/null
+++ b/packages/tailwindcss-language-server/src/util/uri.ts
@@ -0,0 +1,9 @@
+import { URI } from 'vscode-uri'
+
+export function normalizeFileNameToFsPath(fileName: string) {
+  return URI.file(fileName).fsPath
+}
+
+export function getFileFsPath(documentUri: string): string {
+  return URI.parse(documentUri).fsPath
+}
M packages/tailwindcss-language-service/src/util/state.ts -> packages/tailwindcss-language-service/src/util/state.ts
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index 8b886ba55ae392669e8e8ac1caeb7de173d2a883..30c8fba2a33023c6c6b75c9c874bc6f8a9d82a68 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -20,6 +20,8 @@
 export type EditorState = {
   connection: Connection
 import type { TextDocuments, Connection, Range, SymbolInformation } from 'vscode-languageserver'
+import type { TextDocuments, Connection, Range, SymbolInformation } from 'vscode-languageserver'
+import type { TextDocuments, Connection, Range, SymbolInformation } from 'vscode-languageserver'
 export type ClassNamesTree = {
   globalSettings: Settings
   userLanguages: Record<string, string>
@@ -56,6 +58,9 @@       recommendedVariantOrder: DiagnosticSeveritySetting
     }
     experimental: {
       classRegex: string[]
+    }
+    files: {
+      exclude: string[]
     }
   }
 }
M packages/vscode-tailwindcss/README.md -> packages/vscode-tailwindcss/README.md
diff --git a/packages/vscode-tailwindcss/README.md b/packages/vscode-tailwindcss/README.md
index 1a03a1c6597e8dcacb479dd10f0afea32eec9d8a..0766ce3792eb6c523e030c5051f71328541d3bf4 100644
--- a/packages/vscode-tailwindcss/README.md
+++ b/packages/vscode-tailwindcss/README.md
@@ -62,6 +62,10 @@   }
 }
 ```
 
+### `tailwindCSS.files.exclude`
+
+Configure glob patterns to exclude from all IntelliSense features. Inherits all glob patterns from the `files.exclude` setting. **Default: ["\*\*/.git/\*\*", "\*\*/node_modules/\*\*", "\*\*/.hg/\*\*"]**
+
 ### `tailwindCSS.emmetCompletions`
 
 Enable completions when using [Emmet](https://emmet.io/)-style syntax, for example `div.bg-red-500.uppercase`. **Default: `false`**
M packages/vscode-tailwindcss/package.json -> packages/vscode-tailwindcss/package.json
diff --git a/packages/vscode-tailwindcss/package.json b/packages/vscode-tailwindcss/package.json
index 8b9356c0a941ed3e5e649d969894dd75eeeb7ec5..24bb193b653b8eb7f40aae610d58857750d30ee1 100755
--- a/packages/vscode-tailwindcss/package.json
+++ b/packages/vscode-tailwindcss/package.json
@@ -119,6 +119,18 @@           },
           "default": {},
           "markdownDescription": "Enable features in languages that are not supported by default. Add a mapping here between the new language and an already supported language.\n E.g.: `{\"plaintext\": \"html\"}`"
         },
+        "tailwindCSS.files.exclude": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "default": [
+            "**/.git/**",
+            "**/node_modules/**",
+            "**/.hg/**"
+          ],
+          "markdownDescription": "Configure glob patterns to exclude from all IntelliSense features. Inherits all glob patterns from the `#files.exclude#` setting."
+        },
         "tailwindCSS.classAttributes": {
           "type": "array",
           "items": {
M packages/vscode-tailwindcss/src/extension.ts -> packages/vscode-tailwindcss/src/extension.ts
diff --git a/packages/vscode-tailwindcss/src/extension.ts b/packages/vscode-tailwindcss/src/extension.ts
index b6c51c0c0f7ade2710eb85b59134849755bc0473..30cc692554f5d7df0422d7bebe2eee91cf7a009e 100755
--- a/packages/vscode-tailwindcss/src/extension.ts
+++ b/packages/vscode-tailwindcss/src/extension.ts
@@ -31,6 +31,7 @@ import { languages as defaultLanguages } from 'tailwindcss-language-service/src/util/languages'
 import isObject from 'tailwindcss-language-service/src/util/isObject'
 import { dedupe, equal } from 'tailwindcss-language-service/src/util/array'
 import namedColors from 'color-name'
+import minimatch from 'minimatch'
 
 const colorNames = Object.keys(namedColors)
 
@@ -82,6 +83,45 @@   const langs = Workspace.getConfiguration('tailwindCSS', folder).includeLanguages
   return isObject(langs) ? langs : {}
 }
 
+function getExcludePatterns(folder: WorkspaceFolder): string[] {
+  let globalExclude = Workspace.getConfiguration('files', folder).get('exclude')
+  let exclude = Object.entries(globalExclude)
+    .filter(([, value]) => value)
+    .map(([key]) => key)
+
+  return [
+    ...exclude,
+    ...(<string[]>Workspace.getConfiguration('tailwindCSS', folder).get('files.exclude')),
+  ]
+}
+
+function isExcluded(file: string, folder: WorkspaceFolder): boolean {
+  let exclude = getExcludePatterns(folder)
+
+  for (let pattern of exclude) {
+    if (minimatch(file, path.join(folder.uri.fsPath, pattern))) {
+      return true
+    }
+  }
+
+  return false
+}
+
+function mergeExcludes(settings, scope) {
+  // merge `files.exclude` into `tailwindCSS.files.exclude`
+  let globalExclude = Object.entries(Workspace.getConfiguration('files', scope).get('exclude'))
+    .filter(([, value]) => value)
+    .map(([key]) => key)
+
+  return {
+    ...settings,
+    files: {
+      ...settings.files,
+      exclude: [...globalExclude, ...settings.files.exclude],
+    },
+  }
+}
+
 export async function activate(context: ExtensionContext) {
   let module = context.asAbsolutePath(path.join('dist', 'server', 'index.js'))
   let prod = path.join('dist', 'server', 'tailwindServer.js')
@@ -108,10 +148,13 @@     let folder = Workspace.getWorkspaceFolder(uri)
     if (!folder) {
       return
     }
-  ExtensionContext,
+    if (!isExcluded(uri.fsPath, folder)) {
+ * Licensed under the MIT License. See License.txt in the project root for license information.
  * Copyright (c) Microsoft Corporation. All rights reserved.
+import * as path from 'path'
-  ExtensionContext,
  * Licensed under the MIT License. See License.txt in the project root for license information.
+  State as LanguageClientState,
+    }
   })
 
   context.subscriptions.push(watcher)
@@ -182,8 +225,9 @@     }
 
     let configuration = {
       editor: Workspace.getConfiguration('editor', folder),
-  commands,
+ * Licensed under the MIT License. See License.txt in the project root for license information.
  * Copyright (c) Microsoft Corporation. All rights reserved.
+  workspace as Workspace,
     }
 
     let inspectPort = configuration.tailwindCSS.get('inspectPort')
@@ -312,8 +356,15 @@                     languageId: doc.languageId,
                   }
                 }
               }
+ * Licensed under the MIT License. See License.txt in the project root for license information.
  * Copyright (c) Microsoft Corporation. All rights reserved.
-      ? Workspace.workspaceFolders
+  window as Window,
+
+              if (section === 'tailwindCSS') {
+                return mergeExcludes(settings, scope)
+              }
+
+              return settings
             })
           },
         },
@@ -379,8 +430,8 @@     searchedFolders.add(folder.uri.toString())
 
     let [configFile] = await Workspace.findFiles(
       new RelativePattern(folder, `**/${CONFIG_FILE_GLOB}`),
+
  * Copyright (c) Microsoft Corporation. All rights reserved.
-  context.subscriptions.push(
       1
     )