Skip to content

Commit 12e70f6

Browse files
committed
Share glob patterns
1 parent b92cdb2 commit 12e70f6

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONFIG_GLOB = '{tailwind,tailwind.config}.{js,cjs}'
2+
export const PACKAGE_LOCK_GLOB = '{package-lock.json,yarn.lock,pnpm-lock.yaml}'
3+
export const CSS_GLOB = '*.{css,scss,sass,less,pcss}'

packages/tailwindcss-language-server/src/server.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { equal } from 'tailwindcss-language-service/src/util/array'
8080
import preflight from 'tailwindcss/lib/css/preflight.css'
8181
import merge from 'deepmerge'
8282
import { getTextWithoutComments } from 'tailwindcss-language-service/src/util/doc'
83+
import { CONFIG_GLOB, CSS_GLOB, PACKAGE_LOCK_GLOB } from './lib/constants'
8384

8485
// @ts-ignore
8586
global.__preflight = preflight
@@ -97,9 +98,6 @@ new Function(
9798
`
9899
)(require, __dirname)
99100

100-
const CONFIG_FILE_GLOB = '{tailwind,tailwind.config}.{js,cjs}'
101-
const PACKAGE_GLOB = '{package-lock.json,yarn.lock,pnpm-lock.yaml}'
102-
const CSS_GLOB = '*.{css,scss,sass,less,pcss}'
103101
const TRIGGER_CHARACTERS = [
104102
// class attributes
105103
'"',
@@ -370,7 +368,7 @@ async function createProjectService(
370368

371369
let isConfigFile = projectConfig.configPath
372370
? change.file === projectConfig.configPath
373-
: minimatch(file, `**/${CONFIG_FILE_GLOB}`, { dot: true })
371+
: minimatch(file, `**/${CONFIG_GLOB}`, { dot: true })
374372
let isDependency = state.dependencies && state.dependencies.includes(change.file)
375373

376374
if (!isConfigFile && !isDependency) continue
@@ -1510,7 +1508,7 @@ class TW {
15101508
} else {
15111509
let projects: Record<string, Array<DocumentSelector>> = {}
15121510

1513-
let files = await glob([`**/${CONFIG_FILE_GLOB}`, `**/${CSS_GLOB}`], {
1511+
let files = await glob([`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`], {
15141512
cwd: base,
15151513
ignore: (await getConfiguration()).tailwindCSS.files.exclude,
15161514
onlyFiles: true,
@@ -1611,7 +1609,7 @@ class TW {
16111609
}
16121610
}
16131611

1614-
let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_GLOB}`, { dot: true })
1612+
let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_LOCK_GLOB}`, { dot: true })
16151613
if (isPackageFile) {
16161614
for (let [key] of this.projects) {
16171615
let projectConfig = JSON.parse(key) as ProjectConfig
@@ -1649,7 +1647,7 @@ class TW {
16491647
}
16501648
}
16511649

1652-
let isConfigFile = minimatch(normalizedFilename, `**/${CONFIG_FILE_GLOB}`, {
1650+
let isConfigFile = minimatch(normalizedFilename, `**/${CONFIG_GLOB}`, {
16531651
dot: true,
16541652
})
16551653
if (isConfigFile && change.type === FileChangeType.Created) {
@@ -1698,8 +1696,8 @@ class TW {
16981696
DidChangeWatchedFilesNotification.type,
16991697
{
17001698
watchers: [
1701-
{ globPattern: `**/${CONFIG_FILE_GLOB}` },
1702-
{ globPattern: `**/${PACKAGE_GLOB}` },
1699+
{ globPattern: `**/${CONFIG_GLOB}` },
1700+
{ globPattern: `**/${PACKAGE_LOCK_GLOB}` },
17031701
{ globPattern: `**/${CSS_GLOB}` },
17041702
],
17051703
}
@@ -1749,7 +1747,7 @@ class TW {
17491747
} else {
17501748
let watch: typeof chokidar.watch = require('chokidar').watch
17511749
let chokidarWatcher = watch(
1752-
[`**/${CONFIG_FILE_GLOB}`, `**/${PACKAGE_GLOB}`, `**/${CSS_GLOB}`],
1750+
[`**/${CONFIG_GLOB}`, `**/${PACKAGE_LOCK_GLOB}`, `**/${CSS_GLOB}`],
17531751
{
17541752
cwd: base,
17551753
ignorePermissionErrors: true,

packages/vscode-tailwindcss/src/extension.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ import isObject from 'tailwindcss-language-service/src/util/isObject'
4141
import { dedupe, equal } from 'tailwindcss-language-service/src/util/array'
4242
import namedColors from 'color-name'
4343
import minimatch from 'minimatch'
44+
import { CONFIG_GLOB, CSS_GLOB } from 'tailwindcss-language-server/src/lib/constants'
4445

4546
const colorNames = Object.keys(namedColors)
4647

4748
const CLIENT_ID = 'tailwindcss-intellisense'
4849
const CLIENT_NAME = 'Tailwind CSS IntelliSense'
4950

50-
const CONFIG_FILE_GLOB = '{tailwind,tailwind.config}.{js,cjs}'
51-
const CSS_GLOB = '*.{css,scss,sass,less,pcss}'
52-
5351
let clients: Map<string, LanguageClient> = new Map()
5452
let languages: Map<string, string[]> = new Map()
5553
let searchedFolders: Set<string> = new Set()
@@ -155,7 +153,7 @@ export async function activate(context: ExtensionContext) {
155153
})
156154
)
157155

158-
let configWatcher = Workspace.createFileSystemWatcher(`**/${CONFIG_FILE_GLOB}`, false, true, true)
156+
let configWatcher = Workspace.createFileSystemWatcher(`**/${CONFIG_GLOB}`, false, true, true)
159157

160158
configWatcher.onDidCreate((uri) => {
161159
let folder = Workspace.getWorkspaceFolder(uri)
@@ -568,7 +566,7 @@ export async function activate(context: ExtensionContext) {
568566
searchedFolders.add(folder.uri.toString())
569567

570568
let [configFile] = await Workspace.findFiles(
571-
new RelativePattern(folder, `**/${CONFIG_FILE_GLOB}`),
569+
new RelativePattern(folder, `**/${CONFIG_GLOB}`),
572570
`{${getExcludePatterns(folder).join(',')}}`,
573571
1
574572
)

0 commit comments

Comments
 (0)