ensure diagnostics are updated when the user's tailwind config changes

master
Brad Cornes 2020-06-15 19:00:03 +01:00
parent 60cc17be77
commit 3de1b980ad
2 changed files with 27 additions and 4 deletions

View File

@ -405,3 +405,22 @@ export async function provideDiagnostics(
diagnostics,
})
}
export function clearDiagnostics(state: State, document: TextDocument): void {
state.editor.connection.sendDiagnostics({
uri: document.uri,
diagnostics: [],
})
}
export function clearAllDiagnostics(state: State): void {
state.editor.documents.all().forEach((document) => {
clearDiagnostics(state, document)
})
}
export function updateAllDiagnostics(state: State): void {
state.editor.documents.all().forEach((document) => {
provideDiagnostics(state, document)
})
}

View File

@ -26,7 +26,11 @@ import {
import { provideHover } from './providers/hoverProvider'
import { URI } from 'vscode-uri'
import { getDocumentSettings } from './util/getDocumentSettings'
import { provideDiagnostics } from './providers/diagnosticsProvider'
import {
provideDiagnostics,
updateAllDiagnostics,
clearAllDiagnostics,
} from './providers/diagnosticsProvider'
import { createEmitter } from '../lib/emitter'
let connection = createConnection(ProposedFeatures.all)
@ -102,6 +106,7 @@ connection.onInitialize(
state.config,
state.plugins,
])
updateAllDiagnostics(state)
} else {
state = {
enabled: false,
@ -122,6 +127,7 @@ connection.onInitialize(
}
connection.sendNotification('tailwindcss/configError', [payload])
}
clearAllDiagnostics(state)
// TODO
// connection.sendNotification('tailwindcss/configUpdated', [null])
}
@ -196,9 +202,7 @@ connection.onDidChangeConfiguration((change) => {
)
}
state.editor.documents.all().forEach((doc) => {
provideDiagnostics(state, doc)
})
updateAllDiagnostics(state)
})
connection.onCompletion(