Skip to content

Commit d63a97a

Browse files
committed
Fix color decorators not updating when config changes or errors
1 parent e3c3ead commit d63a97a

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/lib/registerColorDecorator.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,12 @@ export function registerColorDecorator(
127127
window.visibleTextEditors.forEach(updateDecorationsInEditor)
128128
}
129129
})
130+
131+
emitter.on('configUpdated', () => {
132+
window.visibleTextEditors.forEach(updateDecorationsInEditor)
133+
})
134+
135+
emitter.on('configError', () => {
136+
window.visibleTextEditors.forEach(updateDecorationsInEditor)
137+
})
130138
}

src/lsp/providers/documentColorProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function registerDocumentColorProvider(state: State) {
1616
'getDocumentColors',
1717
async ({ document }) => {
1818
let colors = []
19+
if (!state.enabled) return { colors }
1920
let doc = state.editor.documents.get(document)
2021
if (!doc) return { colors }
2122

src/lsp/server.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { provideCodeActions } from './providers/codeActions/codeActionProvider'
3838
import { registerDocumentColorProvider } from './providers/documentColorProvider'
3939

4040
let connection = createConnection(ProposedFeatures.all)
41-
let state: State = { enabled: false, emitter: createEmitter(connection) }
41+
const state: State = { enabled: false, emitter: createEmitter(connection) }
4242
let documents = new TextDocuments()
4343
let workspaceFolder: string | null
4444

@@ -74,7 +74,7 @@ connection.onInitialize(
7474
async (params: InitializeParams): Promise<InitializeResult> => {
7575
const capabilities = params.capabilities
7676

77-
const editorState: EditorState = {
77+
state.editor = {
7878
connection,
7979
documents,
8080
documentSettings,
@@ -100,24 +100,15 @@ connection.onInitialize(
100100
// @ts-ignore
101101
onChange: (newState: State): void => {
102102
if (newState && !newState.error) {
103-
state = {
104-
...newState,
105-
enabled: true,
106-
emitter: state.emitter,
107-
editor: editorState,
108-
}
103+
Object.assign(state, newState, { enabled: true })
109104
connection.sendNotification('tailwindcss/configUpdated', [
110105
state.configPath,
111106
state.config,
112107
state.plugins,
113108
])
114109
updateAllDiagnostics(state)
115110
} else {
116-
state = {
117-
enabled: false,
118-
emitter: state.emitter,
119-
editor: editorState,
120-
}
111+
state.enabled = false
121112
if (newState && newState.error) {
122113
const payload: {
123114
message: string
@@ -141,14 +132,9 @@ connection.onInitialize(
141132
)
142133

143134
if (tailwindState) {
144-
state = {
145-
enabled: true,
146-
emitter: state.emitter,
147-
editor: editorState,
148-
...tailwindState,
149-
}
135+
Object.assign(state, tailwindState, { enabled: true })
150136
} else {
151-
state = { enabled: false, emitter: state.emitter, editor: editorState }
137+
state.enabled = false
152138
}
153139

154140
return {

0 commit comments

Comments
 (0)