tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
Improve `experimental.configFile` in multi-root workspaces (#640)
Signature
-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJjUYgtCRBK7hj4Ov3rIwAAK3wIAKLuDvCejRkpIrJiTJnPNTbo
eSm1ixIw4iunv99U5YdEwsEBgo1rwWuLSM/111d7UisJF+l6V1mQaDqgt3wc+Dx0
TGrEJ1Pj16NHo93SsrvpTXqDr5JDxsaXms7I552HELuE8rTIs125s6qVzFSX+wXr
kDwc4rKSpHIX1q4q1UAE9Pzu2uT8n8EJLha6Zskw314vDcl12AOjxxA1AbA6yQPy
xKMTYiL2SqdXBKoGB1coeZMdC6auZsqwPT9RlV40gENrELL5eG9OAySFzjz0HJJ5
mMLWK07gR+kERbikZqxmNtthSOhS7QTufgvLBII1r2OcO4Fb3f6oVhO3WstcG6g=
=bVJO
-----END PGP SIGNATURE-----
2 changed files, 58 additions(+), 26 deletions(-)
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index bef3178e973d9d15a298b82c66b9fbc2dab54913..d40adf60f7ff946aa9182ab8f0d0540792d8b6cf 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -1592,6 +1592,11 @@ let base = normalizeFileNameToFsPath(this.initializeParams.rootPath)
let cssFileConfigMap: Map<string, string> = new Map()
let configTailwindVersionMap: Map<string, string> = new Map()
+ // base directory to resolve relative `experimental.configFile` paths against
+ let userDefinedConfigBase = this.initializeParams.initializationOptions?.workspaceFile
+ ? path.dirname(this.initializeParams.initializationOptions.workspaceFile)
+ : base
+
if (configFileOrFiles) {
if (
typeof configFileOrFiles !== 'string' &&
@@ -1615,10 +1620,10 @@ workspaceFolders = Object.entries(configFiles).map(
([relativeConfigPath, relativeDocumentSelectorOrSelectors]) => {
return {
folder: base,
- configPath: path.resolve(base, relativeConfigPath),
+ configPath: path.resolve(userDefinedConfigBase, relativeConfigPath),
documentSelector: [].concat(relativeDocumentSelectorOrSelectors).map((selector) => ({
priority: DocumentSelectorPriority.USER_CONFIGURED,
- pattern: path.resolve(base, selector),
+ pattern: path.resolve(userDefinedConfigBase, selector),
})),
isUserConfigured: true,
}
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))