tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
Add `files.exclude` setting
8 changed files, 132 additions(+), 32 deletions(-)
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({
- uri: document.uri,
- diagnostics: await doValidate(state, document),
- })
+ if (await isExcluded(state, document)) {
+ clearDiagnostics(state, document)
+ } else {
+ state.editor?.connection.sendDiagnostics({
+ uri: document.uri,
+ diagnostics: await doValidate(state, document),
+ })
+ }
}
export function clearDiagnostics(state: State, document: TextDocument): void {
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
@@ -121,14 +124,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') {
path = path.split('.')
@@ -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,12 +254,7 @@ const documentSettingsCache: Map<string, Settings> = new Map()
let registrations: Promise<BulkUnregistration>
let chokidarWatcher: chokidar.FSWatcher
- let ignore = [
- '**/.git/objects/**',
- '**/.git/subtree-cache/**',
- '**/node_modules/**',
- '**/.hg/store/**',
- ]
+ let ignore = state.editor.globalSettings.tailwindCSS.files.exclude
function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void {
let needsInit = false
@@ -456,7 +447,7 @@
let [configPath] = (
await glob([`**/${CONFIG_FILE_GLOB}`], {
cwd: folder,
- ignore: ['**/node_modules'],
+ ignore: state.editor.globalSettings.tailwindCSS.files.exclude,
onlyFiles: true,
absolute: true,
suppressErrors: true,
@@ -989,25 +980,33 @@ }
},
onUpdateSettings(settings: any): void {
documentSettingsCache.clear()
- if (state.enabled) {
- updateAllDiagnostics(state)
- }
- if (settings.editor.colorDecorators) {
- registerCapabilities(state.dependencies)
+ let previousExclude = state.editor.globalSettings.tailwindCSS.files.exclude
+ state.editor.globalSettings = settings
+ if (!equal(previousExclude, settings.tailwindCSS.files.exclude)) {
+ tryInit()
} else {
- connection.sendNotification('@/tailwindCSS/clearColors')
+ if (state.enabled) {
+ updateAllDiagnostics(state)
+ }
+ if (settings.editor.colorDecorators) {
+ registerCapabilities(state.dependencies)
+ } else {
+ connection.sendNotification('@/tailwindCSS/clearColors')
+ }
}
},
- 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)
},
- onCompletion(params: CompletionParams): Promise<CompletionList> {
+ async onCompletion(params: CompletionParams): Promise<CompletionList> {
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> {
@@ -1026,6 +1025,7 @@ async onDocumentColor(params: DocumentColorParams): Promise<ColorInformation[]> {
if (!state.enabled) return []
let document = documentService.getDocument(params.textDocument.uri)
if (!document) return []
+ if (await isExcluded(state, document)) return null
return getDocumentColors(state, document)
},
async onColorPresentation(params: ColorPresentationParams): Promise<ColorPresentation[]> {
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
+}
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
+}
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
@@ -19,6 +19,7 @@ }
export type EditorState = {
connection: Connection
+ folder: string
documents: TextDocuments<TextDocument>
globalSettings: Settings
userLanguages: Record<string, string>
@@ -55,6 +56,9 @@ recommendedVariantOrder: DiagnosticSeveritySetting
}
experimental: {
classRegex: string[]
+ }
+ files: {
+ exclude: string[]
}
}
}
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`**
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": {
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,8 +148,10 @@ let folder = Workspace.getWorkspaceFolder(uri)
if (!folder) {
return
}
- folder = getOuterMostWorkspaceFolder(folder)
- bootWorkspaceClient(folder)
+ if (!isExcluded(uri.fsPath, folder)) {
+ folder = getOuterMostWorkspaceFolder(folder)
+ bootWorkspaceClient(folder)
+ }
})
context.subscriptions.push(watcher)
@@ -180,7 +222,7 @@ }
let configuration = {
editor: Workspace.getConfiguration('editor', folder),
- tailwindCSS: Workspace.getConfiguration('tailwindCSS', folder),
+ tailwindCSS: mergeExcludes(Workspace.getConfiguration('tailwindCSS', folder), folder),
}
let inspectPort = configuration.tailwindCSS.get('inspectPort')
@@ -309,7 +351,13 @@ languageId: doc.languageId,
}
}
}
- return Workspace.getConfiguration(section, scope)
+ let settings = Workspace.getConfiguration(section, scope)
+
+ if (section === 'tailwindCSS') {
+ return mergeExcludes(settings, scope)
+ }
+
+ return settings
})
},
},
@@ -375,7 +423,7 @@ searchedFolders.add(folder.uri.toString())
let [configFile] = await Workspace.findFiles(
new RelativePattern(folder, `**/${CONFIG_FILE_GLOB}`),
- '**/node_modules/**',
+ `{${getExcludePatterns(folder).join(',')}}`,
1
)