forked from emacs-lsp/lsp-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsp-css.el
243 lines (204 loc) · 7.56 KB
/
lsp-css.el
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
;;; lsp-css.el --- CSS language server configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Ivan Yonchovski
;; Author: Ivan Yonchovski <[email protected]>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'lsp-mode)
(defgroup lsp-css nil
"LSP support for CSS."
:group 'lsp-mode
:link '(url-link
"https://github.com/vscode-langservers/vscode-css-languageserver-bin"))
(defcustom lsp-css-experimental-custom-data nil
"A list of JSON file paths that define custom CSS data that
loads custom properties, at directives, pseudo classes /
elements."
:type '(repeat string))
(defcustom lsp-css-completion-trigger-property-value-completion t
"By default, VS Code triggers property value completion after
selecting a CSS property. Use this setting to disable this
behavior."
:type 'boolean)
(defcustom lsp-css-validate t
"Enables or disables all validations."
:type 'boolean)
(defcustom lsp-css-lint-compatible-vendor-prefixes "ignore"
"When using a vendor-specific prefix make sure to also include
all other vendor-specific properties."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-vendor-prefix "warning"
"When using a vendor-specific prefix, also include the standard
property."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-duplicate-properties "ignore"
"Do not use duplicate style definitions."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-empty-rules "warning"
"Do not use empty rulesets."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-import-statement "ignore"
"Import statements do not load in parallel."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-box-model "ignore"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-universal-selector "ignore"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-zero-units "ignore"
"No unit for zero needed."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-font-face-properties "warning"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-hex-color-length "error"
"Hex colors must consist of three or six hex numbers."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-arguments-in-color-function "error"
"Invalid number of parameters."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-unknown-properties "warning"
"Unknown property."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-valid-properties nil
"A list of properties that are not validated against the
`unknownProperties` rule."
:type '(repeat string))
(defcustom lsp-css-lint-ie-hack "ignore"
"IE hacks are only necessary when supporting IE7 and older."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-unknown-vendor-specific-properties "ignore"
"Unknown vendor specific property."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-property-ignored-due-to-display "warning"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-important "ignore"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-float "ignore"
nil
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-id-selector "ignore"
"Selectors should not contain IDs because these rules are too
tightly coupled with the HTML."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-lint-unknown-at-rules "warning"
"Unknown at-rule."
:type '(choice
(const "ignore")
(const "warning")
(const "error")))
(defcustom lsp-css-trace-server "off"
"Traces the communication between VS Code and the CSS language
server."
:type '(choice
(const "off")
(const "messages")
(const "verbose")))
(lsp-register-custom-settings
'(("css.trace.server" lsp-css-trace-server)
("css.lint.unknownAtRules" lsp-css-lint-unknown-at-rules)
("css.lint.idSelector" lsp-css-lint-id-selector)
("css.lint.float" lsp-css-lint-float)
("css.lint.important" lsp-css-lint-important)
("css.lint.propertyIgnoredDueToDisplay" lsp-css-lint-property-ignored-due-to-display)
("css.lint.unknownVendorSpecificProperties" lsp-css-lint-unknown-vendor-specific-properties)
("css.lint.ieHack" lsp-css-lint-ie-hack)
("css.lint.validProperties" lsp-css-lint-valid-properties)
("css.lint.unknownProperties" lsp-css-lint-unknown-properties)
("css.lint.argumentsInColorFunction" lsp-css-lint-arguments-in-color-function)
("css.lint.hexColorLength" lsp-css-lint-hex-color-length)
("css.lint.fontFaceProperties" lsp-css-lint-font-face-properties)
("css.lint.zeroUnits" lsp-css-lint-zero-units)
("css.lint.universalSelector" lsp-css-lint-universal-selector)
("css.lint.boxModel" lsp-css-lint-box-model)
("css.lint.importStatement" lsp-css-lint-import-statement)
("css.lint.emptyRules" lsp-css-lint-empty-rules)
("css.lint.duplicateProperties" lsp-css-lint-duplicate-properties)
("css.lint.vendorPrefix" lsp-css-lint-vendor-prefix)
("css.lint.compatibleVendorPrefixes" lsp-css-lint-compatible-vendor-prefixes)
("css.validate" lsp-css-validate t)
("css.completion.triggerPropertyValueCompletion" lsp-css-completion-trigger-property-value-completion t)
("css.experimental.customData" lsp-css-experimental-custom-data)))
;;; CSS
(defun lsp-clients-css--apply-code-action (action)
"Apply ACTION as workspace edit command."
(lsp--apply-text-edits (cl-caddr (gethash "arguments" action))))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection '("css-languageserver" "--stdio"))
:major-modes '(css-mode less-mode less-css-mode sass-mode scss-mode)
:priority -1
:action-handlers (lsp-ht ("_css.applyCodeAction" #'lsp-clients-css--apply-code-action))
:server-id 'css-ls))
(provide 'lsp-css)
;;; lsp-css.el ends here
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End: