Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 55 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/tailwindcss-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"color-name": "1.1.4",
"culori": "0.20.1",
"debounce": "1.2.0",
"deepmerge": "4.2.2",
"detective": "5.2.0",
"dlv": "1.1.3",
"dset": "3.1.2",
Expand Down
49 changes: 42 additions & 7 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ import { getColor } from 'tailwindcss-language-service/src/util/color'
import * as culori from 'culori'
import namedColors from 'color-name'
import tailwindPlugins from './lib/plugins'
import isExcluded, { DEFAULT_FILES_EXCLUDE } from './util/isExcluded'
import isExcluded from './util/isExcluded'
import { getFileFsPath, normalizeFileNameToFsPath } from './util/uri'
import { equal } from 'tailwindcss-language-service/src/util/array'
import preflight from 'tailwindcss/lib/css/preflight.css'
import merge from 'deepmerge'

// @ts-ignore
global.__preflight = preflight
Expand Down Expand Up @@ -238,7 +239,42 @@ async function createProjectService(
scopeUri: uri,
}),
])
let config: Settings = { editor, tailwindCSS }
editor = isObject(editor) ? editor : {}
tailwindCSS = isObject(tailwindCSS) ? tailwindCSS : {}

let config: Settings = merge<Settings>(
{
editor: { tabSize: 2 },
tailwindCSS: {
emmetCompletions: false,
classAttributes: ['class', 'className', 'ngClass'],
codeActions: true,
hovers: true,
suggestions: true,
validate: true,
colorDecorators: true,
rootFontSize: 16,
lint: {
cssConflict: 'warning',
invalidApply: 'error',
invalidScreen: 'error',
invalidVariant: 'error',
invalidConfigPath: 'error',
invalidTailwindDirective: 'error',
recommendedVariantOrder: 'warning',
},
showPixelEquivalents: true,
includeLanguages: {},
files: { exclude: ['**/.git/**', '**/node_modules/**', '**/.hg/**', '**/.svn/**'] },
experimental: {
classRegex: [],
configFile: null,
},
},
},
{ editor, tailwindCSS },
{ arrayMerge: (_destinationArray, sourceArray, _options) => sourceArray }
)
documentSettingsCache.set(uri, config)
return config
}
Expand Down Expand Up @@ -266,7 +302,7 @@ async function createProjectService(
}

let chokidarWatcher: chokidar.FSWatcher
let ignore = state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE
let ignore = state.editor.globalSettings.tailwindCSS.files.exclude

function onFileEvents(changes: Array<{ file: string; type: FileChangeType }>): void {
let needsInit = false
Expand Down Expand Up @@ -421,7 +457,7 @@ async function createProjectService(
configPath = (
await glob([`**/${CONFIG_FILE_GLOB}`], {
cwd: folder,
ignore: state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE,
ignore: state.editor.globalSettings.tailwindCSS.files.exclude,
onlyFiles: true,
absolute: true,
suppressErrors: true,
Expand Down Expand Up @@ -937,10 +973,9 @@ async function createProjectService(
},
async onUpdateSettings(settings: any): Promise<void> {
documentSettingsCache.clear()
let previousExclude =
state.editor.globalSettings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE
let previousExclude = state.editor.globalSettings.tailwindCSS.files.exclude
state.editor.globalSettings = await state.editor.getConfiguration()
if (!equal(previousExclude, settings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE)) {
if (!equal(previousExclude, settings.tailwindCSS.files.exclude)) {
tryInit()
} else {
if (state.enabled) {
Expand Down
4 changes: 1 addition & 3 deletions packages/tailwindcss-language-server/src/util/isExcluded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { State } from 'tailwindcss-language-service/src/util/state'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { getFileFsPath } from './uri'

export const DEFAULT_FILES_EXCLUDE = ['**/.git/**', '**/.svn/**', '**/.hg/**', '**/node_modules/**']

export default async function isExcluded(state: State, document: TextDocument): Promise<boolean> {
let settings = await state.editor.getConfiguration(document.uri)
let file = getFileFsPath(document.uri)

for (let pattern of settings.tailwindCSS.files?.exclude ?? DEFAULT_FILES_EXCLUDE) {
for (let pattern of settings.tailwindCSS.files.exclude) {
if (minimatch(file, path.join(state.editor.folder, pattern))) {
return true
}
Expand Down
Loading