Skip to content

Commit 2f41b83

Browse files
LSP: Refresh internal caches when settings are updated (#1273)
We use the pull model (`workspace/configuration`) to get settings for a document and we cache these internally so we don't repeat these calls multiple times for a given request. We're set up to listen for configuration refresh notifications and update the project settings when we get them. Unfortunately, we didn't actually _register_ for these notifications, so we never got them. This meant that if you changed the settings for an already opened file or workspace folder, the language server would not react to these changes. This PR fixes this by registering for configuration change notifications and now open files with color decorators, completions, etc… should react to changes in the settings as needed. If settings are updated and our langauge server doesn't react to or handle these changes, it is definitely a bug. Hopefully this will squash all of those particular ones but… we'll see. 😅
1 parent 182600d commit 2f41b83

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,11 +1181,9 @@ export async function createProjectService(
11811181
if (state.enabled) {
11821182
refreshDiagnostics()
11831183
}
1184-
if (settings.editor?.colorDecorators) {
1185-
updateCapabilities()
1186-
} else {
1187-
connection.sendNotification('@/tailwindCSS/clearColors')
1188-
}
1184+
1185+
updateCapabilities()
1186+
connection.sendNotification('@/tailwindCSS/clearColors')
11891187
},
11901188
onFileEvents,
11911189
async onHover(params: TextDocumentPositionParams): Promise<Hover> {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
DocumentLinkRequest,
3434
TextDocumentSyncKind,
3535
CodeLensRequest,
36+
DidChangeConfigurationNotification,
3637
} from 'vscode-languageserver/node'
3738
import { URI } from 'vscode-uri'
3839
import normalizePath from 'normalize-path'
@@ -799,6 +800,7 @@ export class TW {
799800

800801
private updateCapabilities() {
801802
if (!supportsDynamicRegistration(this.initializeParams)) {
803+
this.connection.client.register(DidChangeConfigurationNotification.type, undefined)
802804
return
803805
}
804806

@@ -810,12 +812,16 @@ export class TW {
810812

811813
let capabilities = BulkRegistration.create()
812814

815+
// TODO: We should *not* be re-registering these capabilities
816+
// IDEA: These should probably be static registrations up front
813817
capabilities.add(HoverRequest.type, { documentSelector: null })
814818
capabilities.add(DocumentColorRequest.type, { documentSelector: null })
815819
capabilities.add(CodeActionRequest.type, { documentSelector: null })
816820
capabilities.add(CodeLensRequest.type, { documentSelector: null })
817821
capabilities.add(DocumentLinkRequest.type, { documentSelector: null })
822+
capabilities.add(DidChangeConfigurationNotification.type, undefined)
818823

824+
// TODO: Only re-register this if trigger characters change
819825
capabilities.add(CompletionRequest.type, {
820826
documentSelector: null,
821827
resolveProvider: true,

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- v4: Make sure completions show after variants using arbitrary and bare values ([#1263](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1263))
77
- v4: Add support for upcoming `@source not` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
88
- v4: Add support for upcoming `@source inline(…)` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
9+
- LSP: Refresh internal caches when settings are updated ([#1273](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1273))
910

1011
# 0.14.9
1112

0 commit comments

Comments
 (0)