Fix color decorators not updating when config changes or errors
parent
e3c3ead8ea
commit
d63a97ab15
|
@ -127,4 +127,12 @@ export function registerColorDecorator(
|
||||||
window.visibleTextEditors.forEach(updateDecorationsInEditor)
|
window.visibleTextEditors.forEach(updateDecorationsInEditor)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
emitter.on('configUpdated', () => {
|
||||||
|
window.visibleTextEditors.forEach(updateDecorationsInEditor)
|
||||||
|
})
|
||||||
|
|
||||||
|
emitter.on('configError', () => {
|
||||||
|
window.visibleTextEditors.forEach(updateDecorationsInEditor)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ export function registerDocumentColorProvider(state: State) {
|
||||||
'getDocumentColors',
|
'getDocumentColors',
|
||||||
async ({ document }) => {
|
async ({ document }) => {
|
||||||
let colors = []
|
let colors = []
|
||||||
|
if (!state.enabled) return { colors }
|
||||||
let doc = state.editor.documents.get(document)
|
let doc = state.editor.documents.get(document)
|
||||||
if (!doc) return { colors }
|
if (!doc) return { colors }
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import { provideCodeActions } from './providers/codeActions/codeActionProvider'
|
||||||
import { registerDocumentColorProvider } from './providers/documentColorProvider'
|
import { registerDocumentColorProvider } from './providers/documentColorProvider'
|
||||||
|
|
||||||
let connection = createConnection(ProposedFeatures.all)
|
let connection = createConnection(ProposedFeatures.all)
|
||||||
let state: State = { enabled: false, emitter: createEmitter(connection) }
|
const state: State = { enabled: false, emitter: createEmitter(connection) }
|
||||||
let documents = new TextDocuments()
|
let documents = new TextDocuments()
|
||||||
let workspaceFolder: string | null
|
let workspaceFolder: string | null
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ connection.onInitialize(
|
||||||
async (params: InitializeParams): Promise<InitializeResult> => {
|
async (params: InitializeParams): Promise<InitializeResult> => {
|
||||||
const capabilities = params.capabilities
|
const capabilities = params.capabilities
|
||||||
|
|
||||||
const editorState: EditorState = {
|
state.editor = {
|
||||||
connection,
|
connection,
|
||||||
documents,
|
documents,
|
||||||
documentSettings,
|
documentSettings,
|
||||||
|
@ -100,12 +100,7 @@ connection.onInitialize(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
onChange: (newState: State): void => {
|
onChange: (newState: State): void => {
|
||||||
if (newState && !newState.error) {
|
if (newState && !newState.error) {
|
||||||
state = {
|
Object.assign(state, newState, { enabled: true })
|
||||||
...newState,
|
|
||||||
enabled: true,
|
|
||||||
emitter: state.emitter,
|
|
||||||
editor: editorState,
|
|
||||||
}
|
|
||||||
connection.sendNotification('tailwindcss/configUpdated', [
|
connection.sendNotification('tailwindcss/configUpdated', [
|
||||||
state.configPath,
|
state.configPath,
|
||||||
state.config,
|
state.config,
|
||||||
|
@ -113,11 +108,7 @@ connection.onInitialize(
|
||||||
])
|
])
|
||||||
updateAllDiagnostics(state)
|
updateAllDiagnostics(state)
|
||||||
} else {
|
} else {
|
||||||
state = {
|
state.enabled = false
|
||||||
enabled: false,
|
|
||||||
emitter: state.emitter,
|
|
||||||
editor: editorState,
|
|
||||||
}
|
|
||||||
if (newState && newState.error) {
|
if (newState && newState.error) {
|
||||||
const payload: {
|
const payload: {
|
||||||
message: string
|
message: string
|
||||||
|
@ -141,14 +132,9 @@ connection.onInitialize(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (tailwindState) {
|
if (tailwindState) {
|
||||||
state = {
|
Object.assign(state, tailwindState, { enabled: true })
|
||||||
enabled: true,
|
|
||||||
emitter: state.emitter,
|
|
||||||
editor: editorState,
|
|
||||||
...tailwindState,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
state = { enabled: false, emitter: state.emitter, editor: editorState }
|
state.enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue