-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathconfig.ts
89 lines (78 loc) · 2.17 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import merge from 'deepmerge'
import { isObject } from './utils'
import type { Settings } from '@tailwindcss/language-service/src/util/state'
import type { Connection } from 'vscode-languageserver'
export interface SettingsCache {
get(uri?: string): Promise<Settings>
clear(): void
}
function getDefaultSettings(): Settings {
return {
editor: { tabSize: 2 },
tailwindCSS: {
inspectPort: null,
emmetCompletions: false,
classAttributes: ['class', 'className', 'ngClass', 'class:list'],
codeActions: true,
hovers: true,
annotations: false,
suggestions: true,
validate: true,
colorDecorators: true,
rootFontSize: 16,
lint: {
cssConflict: 'warning',
invalidApply: 'error',
invalidScreen: 'error',
invalidVariant: 'error',
invalidConfigPath: 'error',
invalidTailwindDirective: 'error',
invalidSourceDirective: 'error',
recommendedVariantOrder: 'warning',
},
showPixelEquivalents: true,
includeLanguages: {},
files: { exclude: ['**/.git/**', '**/node_modules/**', '**/.hg/**', '**/.svn/**'] },
experimental: {
classRegex: [],
configFile: null,
},
},
}
}
export function createSettingsCache(connection: Connection): SettingsCache {
const cache: Map<string, Settings> = new Map()
async function get(uri?: string) {
let config = cache.get(uri)
if (!config) {
config = await load(uri)
cache.set(uri, config)
}
return config
}
async function load(uri?: string) {
let [editor, tailwindCSS] = await Promise.all([
connection.workspace.getConfiguration({
section: 'editor',
scopeUri: uri,
}),
connection.workspace.getConfiguration({
section: 'tailwindCSS',
scopeUri: uri,
}),
])
editor = isObject(editor) ? editor : {}
tailwindCSS = isObject(tailwindCSS) ? tailwindCSS : {}
return merge<Settings>(
getDefaultSettings(),
{ editor, tailwindCSS },
{ arrayMerge: (_destinationArray, sourceArray, _options) => sourceArray },
)
}
return {
get,
clear() {
cache.clear()
},
}
}