1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
diff --git a/packages/vscode-tailwindcss/src/extension.ts b/packages/vscode-tailwindcss/src/extension.ts
index e618e06cf86e348ce942c0b94ba102df3307d186..9cbd779d11147a15c058d83aadc4ddab95a12af5 100755
--- a/packages/vscode-tailwindcss/src/extension.ts
+++ b/packages/vscode-tailwindcss/src/extension.ts
@@ -246,6 +246,15 @@ // not just the language IDs
// e.g. "plaintext" already exists but you change it from "html" to "css"
context.subscriptions.push(
Workspace.onDidChangeConfiguration((event) => {
+ let toReboot = new Set<WorkspaceFolder>()
+
+ Workspace.textDocuments.forEach((document) => {
+ let folder = Workspace.getWorkspaceFolder(document.uri)
+ if (!folder) return
+ if (event.affectsConfiguration('tailwindCSS.experimental.configFile', folder)) {
+ toReboot.add(folder)
+ }
+ })
;[...clients].forEach(([key, client]) => {
const folder = Workspace.getWorkspaceFolder(Uri.parse(key))
let reboot = false
@@ -267,11 +276,15 @@ reboot = true
}
if (reboot && client) {
- clients.delete(folder.uri.toString())
- client.stop()
- bootWorkspaceClient(folder)
+ toReboot.add(folder)
}
})
+
+ for (let folder of toReboot) {
+ clients.get(folder.uri.toString())?.stop()
+ clients.delete(folder.uri.toString())
+ bootClientForFolderIfNeeded(folder)
+ }
})
)
@@ -568,6 +581,8 @@ },
},
initializationOptions: {
userLanguages: getUserLanguages(folder),
+ workspaceFile:
+ Workspace.workspaceFile?.scheme === 'file' ? Workspace.workspaceFile.fsPath : undefined,
},
synchronize: {
configurationSection: ['files', 'editor', 'tailwindCSS'],
@@ -602,29 +617,12 @@ client.start()
clients.set(folder.uri.toString(), client)
}
- async function didOpenTextDocument(document: TextDocument): Promise<void> {
- if (document.languageId === 'tailwindcss') {
- bootCssServer()
- }
-
- // We are only interested in language mode text
- if (document.uri.scheme !== 'file') {
- return
- }
-
- let uri = document.uri
- let folder = Workspace.getWorkspaceFolder(uri)
- // Files outside a folder can't be handled. This might depend on the language.
- // Single file languages like JSON might handle files outside the workspace folders.
- if (!folder) {
+ async function bootClientForFolderIfNeeded(folder: WorkspaceFolder): Promise<void> {
+ let settings = Workspace.getConfiguration('tailwindCSS', folder)
+ if (settings.get('experimental.configFile') !== null) {
+ bootWorkspaceClient(folder)
return
}
- // If we have nested workspace folders we only start a server on the outer most workspace folder.
- folder = getOuterMostWorkspaceFolder(folder)
-
- if (searchedFolders.has(folder.uri.toString())) return
-
- searchedFolders.add(folder.uri.toString())
let [configFile] = await Workspace.findFiles(
new RelativePattern(folder, `**/${CONFIG_GLOB}`),
@@ -648,6 +646,35 @@ bootWorkspaceClient(folder)
return
}
}
+ }
+
+ async function didOpenTextDocument(document: TextDocument): Promise<void> {
+ if (document.languageId === 'tailwindcss') {
+ bootCssServer()
+ }
+
+ // We are only interested in language mode text
+ if (document.uri.scheme !== 'file') {
+ return
+ }
+
+ let uri = document.uri
+ let folder = Workspace.getWorkspaceFolder(uri)
+ // Files outside a folder can't be handled. This might depend on the language.
+ // Single file languages like JSON might handle files outside the workspace folders.
+ if (!folder) {
+ return
+ }
+ // If we have nested workspace folders we only start a server on the outer most workspace folder.
+ folder = getOuterMostWorkspaceFolder(folder)
+
+ if (searchedFolders.has(folder.uri.toString())) {
+ return
+ }
+
+ searchedFolders.add(folder.uri.toString())
+
+ await bootClientForFolderIfNeeded(folder)
}
context.subscriptions.push(Workspace.onDidOpenTextDocument(didOpenTextDocument))
|