short-circuit re-initialisation
parent
f729d57073
commit
6aabc3d9a5
|
@ -60,6 +60,7 @@ export interface FeatureFlags {
|
||||||
export interface State {
|
export interface State {
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
configPath?: string
|
configPath?: string
|
||||||
|
configModified?: number
|
||||||
config?: any
|
config?: any
|
||||||
version?: string
|
version?: string
|
||||||
separator?: string
|
separator?: string
|
||||||
|
|
|
@ -142,7 +142,35 @@ async function createProjectService(
|
||||||
params: InitializeParams,
|
params: InitializeParams,
|
||||||
documentService: DocumentService
|
documentService: DocumentService
|
||||||
): Promise<ProjectService> {
|
): Promise<ProjectService> {
|
||||||
const state: State = { enabled: false }
|
const state: State = {
|
||||||
|
enabled: false,
|
||||||
|
editor: {
|
||||||
|
connection,
|
||||||
|
globalSettings: params.initializationOptions.configuration as Settings,
|
||||||
|
userLanguages: {},
|
||||||
|
// TODO
|
||||||
|
capabilities: {
|
||||||
|
configuration: true,
|
||||||
|
diagnosticRelatedInformation: true,
|
||||||
|
},
|
||||||
|
documents: documentService.documents,
|
||||||
|
getConfiguration: async (uri?: string) => {
|
||||||
|
if (documentSettingsCache.has(uri)) {
|
||||||
|
return documentSettingsCache.get(uri)
|
||||||
|
}
|
||||||
|
let config = await connection.workspace.getConfiguration({
|
||||||
|
section: 'tailwindCSS',
|
||||||
|
scopeUri: uri,
|
||||||
|
})
|
||||||
|
documentSettingsCache.set(uri, config)
|
||||||
|
return config
|
||||||
|
},
|
||||||
|
getDocumentSymbols: (uri: string) => {
|
||||||
|
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const documentSettingsCache: Map<string, Settings> = new Map()
|
const documentSettingsCache: Map<string, Settings> = new Map()
|
||||||
let registrations: Promise<BulkUnregistration>
|
let registrations: Promise<BulkUnregistration>
|
||||||
|
|
||||||
|
@ -255,33 +283,6 @@ async function createProjectService(
|
||||||
async function init() {
|
async function init() {
|
||||||
clearRequireCache()
|
clearRequireCache()
|
||||||
|
|
||||||
// TODO
|
|
||||||
state.editor = {
|
|
||||||
connection,
|
|
||||||
globalSettings: params.initializationOptions.configuration as Settings,
|
|
||||||
userLanguages: {},
|
|
||||||
// TODO
|
|
||||||
capabilities: {
|
|
||||||
configuration: true,
|
|
||||||
diagnosticRelatedInformation: true,
|
|
||||||
},
|
|
||||||
documents: documentService.documents,
|
|
||||||
getConfiguration: async (uri?: string) => {
|
|
||||||
if (documentSettingsCache.has(uri)) {
|
|
||||||
return documentSettingsCache.get(uri)
|
|
||||||
}
|
|
||||||
let config = await connection.workspace.getConfiguration({
|
|
||||||
section: 'tailwindCSS',
|
|
||||||
scopeUri: uri,
|
|
||||||
})
|
|
||||||
documentSettingsCache.set(uri, config)
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
getDocumentSymbols: (uri: string) => {
|
|
||||||
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
let [configPath] = (
|
let [configPath] = (
|
||||||
await glob([`**/${CONFIG_FILE_GLOB}`], {
|
await glob([`**/${CONFIG_FILE_GLOB}`], {
|
||||||
cwd: folder,
|
cwd: folder,
|
||||||
|
@ -325,6 +326,7 @@ async function createProjectService(
|
||||||
setPnpApi(pnpApi)
|
setPnpApi(pnpApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const configModified = fs.statSync(configPath).mtimeMs
|
||||||
const configDir = path.dirname(configPath)
|
const configDir = path.dirname(configPath)
|
||||||
let tailwindcss: any
|
let tailwindcss: any
|
||||||
let postcss: any
|
let postcss: any
|
||||||
|
@ -356,6 +358,16 @@ async function createProjectService(
|
||||||
tailwindcssVersion = tailwindcssPkg.version
|
tailwindcssVersion = tailwindcssPkg.version
|
||||||
console.log(`Loaded tailwindcss v${tailwindcssVersion}: ${tailwindDir}`)
|
console.log(`Loaded tailwindcss v${tailwindcssVersion}: ${tailwindDir}`)
|
||||||
|
|
||||||
|
if (
|
||||||
|
state.enabled &&
|
||||||
|
postcssVersion === state.modules.postcss.version &&
|
||||||
|
tailwindcssVersion === state.modules.tailwindcss.version &&
|
||||||
|
configPath === state.configPath &&
|
||||||
|
configModified === state.configModified
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resolveConfigFn = __non_webpack_require__(resolveFrom(tailwindDir, './resolveConfig.js'))
|
resolveConfigFn = __non_webpack_require__(resolveFrom(tailwindDir, './resolveConfig.js'))
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
@ -432,6 +444,7 @@ async function createProjectService(
|
||||||
}
|
}
|
||||||
|
|
||||||
state.configPath = configPath
|
state.configPath = configPath
|
||||||
|
state.configModified = configModified
|
||||||
state.modules = {
|
state.modules = {
|
||||||
tailwindcss: { version: tailwindcssVersion, module: tailwindcss },
|
tailwindcss: { version: tailwindcssVersion, module: tailwindcss },
|
||||||
postcss: { version: postcssVersion, module: postcss },
|
postcss: { version: postcssVersion, module: postcss },
|
||||||
|
|
Loading…
Reference in New Issue