Skip to content

Commit

Permalink
Fallback to global settings when requests for folder settings fail (#981
Browse files Browse the repository at this point in the history
)

* Log workspace folder initialization failures

* Fallback to global settinsg when requests for folder settings fail

Zed seems to return an error from their LSP: `invalid value: string “…”, expected relative URL without a base`

* Update packages/tailwindcss-language-server/src/tw.ts

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
  • Loading branch information
thecrypticace and RobinMalfait committed Jun 18, 2024
1 parent 73843f5 commit d561031
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ export class TW {
// NOTE: We should eventually be smart about avoiding duplicate work. We do
// not necessarily need to set up file watchers, search for projects, read
// configs, etc… per folder. Some of this work should be sharable.
await Promise.allSettled(folders.map((basePath) => this._initFolder(basePath)))
let results = await Promise.allSettled(folders.map((basePath) => this._initFolder(basePath)))

for (let [idx, result] of results.entries()) {
if (result.status === 'rejected') {
console.error('Failed to initialize workspace folder', folders[idx], result.reason)
}
}

await this.listenForEvents()
}
Expand All @@ -164,8 +170,18 @@ export class TW {
let ignore = globalSettings.tailwindCSS.files.exclude

// Get user languages for the given workspace folder
let folderSettings = await this.settingsCache.get(base)
let userLanguages = folderSettings.tailwindCSS.includeLanguages
let userLanguages = globalSettings.tailwindCSS.includeLanguages

try {
let folderSettings = await this.settingsCache.get(base)
userLanguages = folderSettings.tailwindCSS.includeLanguages
} catch (error) {
console.error(
'Unable to get the settings for workspace folder. Using global settings instead.',
error,
)
}


// Fall back to settings defined in `initializationOptions` if invalid
if (!isObject(userLanguages)) {
Expand Down

0 comments on commit d561031

Please sign in to comment.