Don't read configuration from `initializationOptions`

master
Brad Cornes 2022-01-17 13:58:13 +00:00
parent 31393e6a5c
commit 5b675434f0
2 changed files with 27 additions and 25 deletions

View File

@ -211,22 +211,9 @@ async function createProjectService(
documentService: DocumentService documentService: DocumentService
): Promise<ProjectService> { ): Promise<ProjectService> {
const disposables: Disposable[] = [] const disposables: Disposable[] = []
const state: State = { const documentSettingsCache: Map<string, Settings> = new Map()
enabled: false,
editor: { async function getConfiguration(uri?: string) {
connection,
folder,
globalSettings: params.initializationOptions.configuration as Settings,
userLanguages: params.initializationOptions.userLanguages
? params.initializationOptions.userLanguages
: {},
// TODO
capabilities: {
configuration: true,
diagnosticRelatedInformation: true,
},
documents: documentService.documents,
getConfiguration: async (uri?: string) => {
if (documentSettingsCache.has(uri)) { if (documentSettingsCache.has(uri)) {
return documentSettingsCache.get(uri) return documentSettingsCache.get(uri)
} }
@ -243,18 +230,34 @@ async function createProjectService(
let config: Settings = { editor, tailwindCSS } let config: Settings = { editor, tailwindCSS }
documentSettingsCache.set(uri, config) documentSettingsCache.set(uri, config)
return config return config
}
const state: State = {
enabled: false,
editor: {
connection,
folder,
globalSettings: await getConfiguration(),
userLanguages: params.initializationOptions.userLanguages
? params.initializationOptions.userLanguages
: {},
// TODO
capabilities: {
configuration: true,
diagnosticRelatedInformation: true,
}, },
documents: documentService.documents,
getConfiguration,
getDocumentSymbols: (uri: string) => { getDocumentSymbols: (uri: string) => {
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri }) return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
}, },
}, },
} }
const documentSettingsCache: Map<string, Settings> = new Map()
let registrations: Promise<BulkUnregistration> let registrations: Promise<BulkUnregistration>
let chokidarWatcher: chokidar.FSWatcher let chokidarWatcher: chokidar.FSWatcher
let ignore = state.editor.globalSettings.tailwindCSS.files.exclude let ignore = state.editor.globalSettings.tailwindCSS.files?.exclude ?? []
function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void { function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void {
let needsInit = false let needsInit = false
@ -447,7 +450,7 @@ async function createProjectService(
let [configPath] = ( let [configPath] = (
await glob([`**/${CONFIG_FILE_GLOB}`], { await glob([`**/${CONFIG_FILE_GLOB}`], {
cwd: folder, cwd: folder,
ignore: state.editor.globalSettings.tailwindCSS.files.exclude, ignore: state.editor.globalSettings.tailwindCSS.files?.exclude ?? [],
onlyFiles: true, onlyFiles: true,
absolute: true, absolute: true,
suppressErrors: true, suppressErrors: true,
@ -980,9 +983,9 @@ async function createProjectService(
}, },
onUpdateSettings(settings: any): void { onUpdateSettings(settings: any): void {
documentSettingsCache.clear() documentSettingsCache.clear()
let previousExclude = state.editor.globalSettings.tailwindCSS.files.exclude let previousExclude = state.editor.globalSettings.tailwindCSS.files?.exclude ?? []
state.editor.globalSettings = settings state.editor.globalSettings = settings
if (!equal(previousExclude, settings.tailwindCSS.files.exclude)) { if (!equal(previousExclude, settings.tailwindCSS.files?.exclude ?? [])) {
tryInit() tryInit()
} else { } else {
if (state.enabled) { if (state.enabled) {

View File

@ -364,7 +364,6 @@ export async function activate(context: ExtensionContext) {
}, },
initializationOptions: { initializationOptions: {
userLanguages: getUserLanguages(folder), userLanguages: getUserLanguages(folder),
configuration,
}, },
synchronize: { synchronize: {
configurationSection: ['editor', 'tailwindCSS'], configurationSection: ['editor', 'tailwindCSS'],