Improve `experimental.configFile` in multi-root workspaces (#640)
parent
aa282c19a0
commit
55d2b9e8da
|
@ -1592,6 +1592,11 @@ class TW {
|
||||||
let cssFileConfigMap: Map<string, string> = new Map()
|
let cssFileConfigMap: Map<string, string> = new Map()
|
||||||
let configTailwindVersionMap: 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 (configFileOrFiles) {
|
||||||
if (
|
if (
|
||||||
typeof configFileOrFiles !== 'string' &&
|
typeof configFileOrFiles !== 'string' &&
|
||||||
|
@ -1615,10 +1620,10 @@ class TW {
|
||||||
([relativeConfigPath, relativeDocumentSelectorOrSelectors]) => {
|
([relativeConfigPath, relativeDocumentSelectorOrSelectors]) => {
|
||||||
return {
|
return {
|
||||||
folder: base,
|
folder: base,
|
||||||
configPath: path.resolve(base, relativeConfigPath),
|
configPath: path.resolve(userDefinedConfigBase, relativeConfigPath),
|
||||||
documentSelector: [].concat(relativeDocumentSelectorOrSelectors).map((selector) => ({
|
documentSelector: [].concat(relativeDocumentSelectorOrSelectors).map((selector) => ({
|
||||||
priority: DocumentSelectorPriority.USER_CONFIGURED,
|
priority: DocumentSelectorPriority.USER_CONFIGURED,
|
||||||
pattern: path.resolve(base, selector),
|
pattern: path.resolve(userDefinedConfigBase, selector),
|
||||||
})),
|
})),
|
||||||
isUserConfigured: true,
|
isUserConfigured: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,6 +246,15 @@ export async function activate(context: ExtensionContext) {
|
||||||
// e.g. "plaintext" already exists but you change it from "html" to "css"
|
// e.g. "plaintext" already exists but you change it from "html" to "css"
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
Workspace.onDidChangeConfiguration((event) => {
|
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]) => {
|
;[...clients].forEach(([key, client]) => {
|
||||||
const folder = Workspace.getWorkspaceFolder(Uri.parse(key))
|
const folder = Workspace.getWorkspaceFolder(Uri.parse(key))
|
||||||
let reboot = false
|
let reboot = false
|
||||||
|
@ -267,11 +276,15 @@ export async function activate(context: ExtensionContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reboot && client) {
|
if (reboot && client) {
|
||||||
clients.delete(folder.uri.toString())
|
toReboot.add(folder)
|
||||||
client.stop()
|
|
||||||
bootWorkspaceClient(folder)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for (let folder of toReboot) {
|
||||||
|
clients.get(folder.uri.toString())?.stop()
|
||||||
|
clients.delete(folder.uri.toString())
|
||||||
|
bootClientForFolderIfNeeded(folder)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -568,6 +581,8 @@ export async function activate(context: ExtensionContext) {
|
||||||
},
|
},
|
||||||
initializationOptions: {
|
initializationOptions: {
|
||||||
userLanguages: getUserLanguages(folder),
|
userLanguages: getUserLanguages(folder),
|
||||||
|
workspaceFile:
|
||||||
|
Workspace.workspaceFile?.scheme === 'file' ? Workspace.workspaceFile.fsPath : undefined,
|
||||||
},
|
},
|
||||||
synchronize: {
|
synchronize: {
|
||||||
configurationSection: ['files', 'editor', 'tailwindCSS'],
|
configurationSection: ['files', 'editor', 'tailwindCSS'],
|
||||||
|
@ -602,30 +617,13 @@ export async function activate(context: ExtensionContext) {
|
||||||
clients.set(folder.uri.toString(), client)
|
clients.set(folder.uri.toString(), client)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function didOpenTextDocument(document: TextDocument): Promise<void> {
|
async function bootClientForFolderIfNeeded(folder: WorkspaceFolder): Promise<void> {
|
||||||
if (document.languageId === 'tailwindcss') {
|
let settings = Workspace.getConfiguration('tailwindCSS', folder)
|
||||||
bootCssServer()
|
if (settings.get('experimental.configFile') !== null) {
|
||||||
}
|
bootWorkspaceClient(folder)
|
||||||
|
|
||||||
// We are only interested in language mode text
|
|
||||||
if (document.uri.scheme !== 'file') {
|
|
||||||
return
|
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())
|
|
||||||
|
|
||||||
let [configFile] = await Workspace.findFiles(
|
let [configFile] = await Workspace.findFiles(
|
||||||
new RelativePattern(folder, `**/${CONFIG_GLOB}`),
|
new RelativePattern(folder, `**/${CONFIG_GLOB}`),
|
||||||
`{${getExcludePatterns(folder).join(',')}}`,
|
`{${getExcludePatterns(folder).join(',')}}`,
|
||||||
|
@ -650,6 +648,35 @@ export async function activate(context: ExtensionContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
context.subscriptions.push(Workspace.onDidOpenTextDocument(didOpenTextDocument))
|
||||||
Workspace.textDocuments.forEach(didOpenTextDocument)
|
Workspace.textDocuments.forEach(didOpenTextDocument)
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
|
|
Loading…
Reference in New Issue