register disposables

master
Brad Cornes 2021-05-04 16:27:05 +01:00
parent da69936f11
commit c1467b75f3
1 changed files with 40 additions and 27 deletions

View File

@ -62,7 +62,6 @@ function sortedWorkspaceFolders(): string[] {
} }
return _sortedWorkspaceFolders return _sortedWorkspaceFolders
} }
Workspace.onDidChangeWorkspaceFolders(() => (_sortedWorkspaceFolders = undefined))
function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder { function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
let sorted = sortedWorkspaceFolders() let sorted = sortedWorkspaceFolders()
@ -111,28 +110,30 @@ export function activate(context: ExtensionContext) {
// TODO: check if the actual language MAPPING changed // TODO: check if the actual language MAPPING changed
// not just the language IDs // not just the language IDs
// 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"
Workspace.onDidChangeConfiguration((event) => { context.subscriptions.push(
clients.forEach((client, key) => { Workspace.onDidChangeConfiguration((event) => {
const folder = Workspace.getWorkspaceFolder(Uri.parse(key)) clients.forEach((client, key) => {
const folder = Workspace.getWorkspaceFolder(Uri.parse(key))
if (event.affectsConfiguration('tailwindCSS', folder)) { if (event.affectsConfiguration('tailwindCSS', folder)) {
const userLanguages = getUserLanguages(folder) const userLanguages = getUserLanguages(folder)
if (userLanguages) { if (userLanguages) {
const userLanguageIds = Object.keys(userLanguages) const userLanguageIds = Object.keys(userLanguages)
const newLanguages = dedupe([...DEFAULT_LANGUAGES, ...userLanguageIds]) const newLanguages = dedupe([...DEFAULT_LANGUAGES, ...userLanguageIds])
if (!equal(newLanguages, languages.get(folder.uri.toString()))) { if (!equal(newLanguages, languages.get(folder.uri.toString()))) {
languages.set(folder.uri.toString(), newLanguages) languages.set(folder.uri.toString(), newLanguages)
if (client) { if (client) {
clients.delete(folder.uri.toString()) clients.delete(folder.uri.toString())
client.stop() client.stop()
bootWorkspaceClient(folder) bootWorkspaceClient(folder)
}
} }
} }
} }
} })
}) })
}) )
function bootWorkspaceClient(folder: WorkspaceFolder) { function bootWorkspaceClient(folder: WorkspaceFolder) {
if (clients.has(folder.uri.toString())) { if (clients.has(folder.uri.toString())) {
@ -146,6 +147,13 @@ export function activate(context: ExtensionContext) {
colorDecorationType = undefined colorDecorationType = undefined
} }
} }
context.subscriptions.push({
dispose() {
if (colorDecorationType) {
colorDecorationType.dispose()
}
},
})
// placeholder so we don't boot another server before this one is ready // placeholder so we don't boot another server before this one is ready
clients.set(folder.uri.toString(), null) clients.set(folder.uri.toString(), null)
@ -159,6 +167,7 @@ export function activate(context: ExtensionContext) {
if (!outputChannel) { if (!outputChannel) {
outputChannel = Window.createOutputChannel(CLIENT_NAME) outputChannel = Window.createOutputChannel(CLIENT_NAME)
context.subscriptions.push(outputChannel)
commands.executeCommand('setContext', 'tailwindCSS.hasOutputChannel', true) commands.executeCommand('setContext', 'tailwindCSS.hasOutputChannel', true)
} }
@ -361,18 +370,22 @@ export function activate(context: ExtensionContext) {
bootWorkspaceClient(folder) bootWorkspaceClient(folder)
} }
Workspace.onDidOpenTextDocument(didOpenTextDocument) context.subscriptions.push(Workspace.onDidOpenTextDocument(didOpenTextDocument))
Workspace.textDocuments.forEach(didOpenTextDocument) Workspace.textDocuments.forEach(didOpenTextDocument)
Workspace.onDidChangeWorkspaceFolders((event) => { context.subscriptions.push(
for (let folder of event.removed) { Workspace.onDidChangeWorkspaceFolders((event) => {
let client = clients.get(folder.uri.toString()) _sortedWorkspaceFolders = undefined
if (client) {
searchedFolders.delete(folder.uri.toString()) for (let folder of event.removed) {
clients.delete(folder.uri.toString()) let client = clients.get(folder.uri.toString())
client.stop() if (client) {
searchedFolders.delete(folder.uri.toString())
clients.delete(folder.uri.toString())
client.stop()
}
} }
} })
}) )
} }
export function deactivate(): Thenable<void> { export function deactivate(): Thenable<void> {