Skip to content

Commit 8aa2064

Browse files
authored
Merge settings with defaults (#605)
1 parent 9ca9359 commit 8aa2064

File tree

12 files changed

+161
-155
lines changed

12 files changed

+161
-155
lines changed

package-lock.json

Lines changed: 55 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tailwindcss-language-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"color-name": "1.1.4",
4545
"culori": "0.20.1",
4646
"debounce": "1.2.0",
47+
"deepmerge": "4.2.2",
4748
"detective": "5.2.0",
4849
"dlv": "1.1.3",
4950
"dset": "3.1.2",

packages/tailwindcss-language-server/src/server.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ import { getColor } from 'tailwindcss-language-service/src/util/color'
7878
import * as culori from 'culori'
7979
import namedColors from 'color-name'
8080
import tailwindPlugins from './lib/plugins'
81-
import isExcluded, { DEFAULT_FILES_EXCLUDE } from './util/isExcluded'
81+
import isExcluded from './util/isExcluded'
8282
import { getFileFsPath, normalizeFileNameToFsPath } from './util/uri'
8383
import { equal } from 'tailwindcss-language-service/src/util/array'
8484
import preflight from 'tailwindcss/lib/css/preflight.css'
85+
import merge from 'deepmerge'
8586

8687
// @ts-ignore
8788
global.__preflight = preflight
@@ -238,7 +239,42 @@ async function createProjectService(
238239
scopeUri: uri,
239240
}),
240241
])
241-
let config: Settings = { editor, tailwindCSS }
242+
editor = isObject(editor) ? editor : {}
243+
tailwindCSS = isObject(tailwindCSS) ? tailwindCSS : {}
244+
245+
let config: Settings = merge<Settings>(
246+
{
247+
editor: { tabSize: 2 },
248+
tailwindCSS: {
249+
emmetCompletions: false,
250+
classAttributes: ['class', 'className', 'ngClass'],
251+
codeActions: true,
252+
hovers: true,
253+
suggestions: true,
254+
validate: true,
255+
colorDecorators: true,
256+
rootFontSize: 16,
257+
lint: {
258+
cssConflict: 'warning',
259+
invalidApply: 'error',
260+
invalidScreen: 'error',
261+
invalidVariant: 'error',
262+
invalidConfigPath: 'error',
263+
invalidTailwindDirective: 'error',
264+
recommendedVariantOrder: 'warning',
265+
},
266+
showPixelEquivalents: true,
267+
includeLanguages: {},
268+
files: { exclude: ['**/.git/**', '**/node_modules/**', '**/.hg/**', '**/.svn/**'] },
269+
experimental: {
270+
classRegex: [],
271+
configFile: null,
272+
},
273+
},
274+
},
275+
{ editor, tailwindCSS },
276+
{ arrayMerge: (_destinationArray, sourceArray, _options) => sourceArray }
277+
)
242278
documentSettingsCache.set(uri, config)
243279
return config
244280
}
@@ -266,7 +302,7 @@ async function createProjectService(
266302
}
267303

268304
let chokidarWatcher: chokidar.FSWatcher
269-
let ignore = state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE
305+
let ignore = state.editor.globalSettings.tailwindCSS.files.exclude
270306

271307
function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void {
272308
let needsInit = false
@@ -421,7 +457,7 @@ async function createProjectService(
421457
configPath = (
422458
await glob([`**/${CONFIG_FILE_GLOB}`], {
423459
cwd: folder,
424-
ignore: state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE,
460+
ignore: state.editor.globalSettings.tailwindCSS.files.exclude,
425461
onlyFiles: true,
426462
absolute: true,
427463
suppressErrors: true,
@@ -937,10 +973,9 @@ async function createProjectService(
937973
},
938974
async onUpdateSettings(settings: any): Promise<void> {
939975
documentSettingsCache.clear()
940-
let previousExclude =
941-
state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE
976+
let previousExclude = state.editor.globalSettings.tailwindCSS.files.exclude
942977
state.editor.globalSettings = await state.editor.getConfiguration()
943-
if (!equal(previousExclude, settings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE)) {
978+
if (!equal(previousExclude, settings.tailwindCSS.files.exclude)) {
944979
tryInit()
945980
} else {
946981
if (state.enabled) {

packages/tailwindcss-language-server/src/util/isExcluded.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { State } from 'tailwindcss-language-service/src/util/state'
44
import { TextDocument } from 'vscode-languageserver-textdocument'
55
import { getFileFsPath } from './uri'
66

7-
export const DEFAULT_FILES_EXCLUDE = ['**/.git/**', '**/.svn/**', '**/.hg/**', '**/node_modules/**']
8-
97
export default async function isExcluded(state: State, document: TextDocument): Promise<boolean> {
108
let settings = await state.editor.getConfiguration(document.uri)
119
let file = getFileFsPath(document.uri)
1210

13-
for (let pattern of settings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE) {
11+
for (let pattern of settings.tailwindCSS.files.exclude) {
1412
if (minimatch(file, path.join(state.editor.folder, pattern))) {
1513
return true
1614
}

0 commit comments

Comments
 (0)