aboutsummaryrefslogtreecommitdiffstats
path: root/elpa/lsp-mode-20220505.630/lsp-html.el
blob: 00b526ab2ee7ca3e3bb82080f33c4c8eb8e7254a (plain) (blame)
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
;;; lsp-html.el --- vscode-html-languageserver configuration  -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Vibhav Pant

;; Author: Vibhav Pant <vibhavp@gmail.com>
;; 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-html nil
  "LSP support for HTML, using vscode's built-in language server."
  :group 'lsp-mode
  :link '(url-link "https://github.com/microsoft/vscode/tree/main/extensions/html-language-features/server")
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-experimental-custom-data nil
  "A list of JSON file paths that define custom tags, properties and other HTML
syntax constructs. Only workspace folder setting will be read."
  :type '(choice (const nil) string)
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-enable t
  "Enable/disable default HTML formatter."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-wrap-line-length 120
  "Maximum amount of characters per line (0 = disable)."
  :type 'number
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-unformatted "wbr"
  nil
  :type '(choice (const nil) string)
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-content-unformatted "pre,code,textarea"
  nil
  :group 'lsp-html
  :type '(choice (const nil) string)
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-indent-inner-html nil
  nil
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-preserve-new-lines t
  "Controls whether existing line breaks before elements should be preserved.
Only works before elements, not inside tags or for text."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-max-preserve-new-lines nil
  nil
  :type '(choice (const nil) integer)
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-indent-handlebars nil nil
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-end-with-newline nil
  "End with a newline."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-extra-liners "head, body, /html"
  nil
  :type '(choice (const nil) string)
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-format-wrap-attributes "auto"
  "Wrap attributes."
  :type '(choice
          (const "auto")
          (const "force")
          (const "force-aligned")
          (const "force-expand-multiline")
          (const "aligned-multiple")
          (const "preserve")
          (const "preserve-aligned"))
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-suggest-html5 t
  "Controls whether the built-in HTML language support suggests HTML5 tags,
properties and values."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-validate-scripts t
  "Controls whether the built-in HTML language support validates embedded
scripts."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-validate-styles t
  "Controls whether the built-in HTML language support validates embedded
styles."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-auto-closing-tags t
  "Enable/disable autoclosing of HTML tags."
  :type 'boolean
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-html-trace-server "off"
  "Traces the communication between VS Code and the HTML language server."
  :type '(choice
          (const "off")
          (const "messages")
          (const "verbose"))
  :group 'lsp-html
  :package-version '(lsp-mode . "6.1"))

(lsp-register-custom-settings
 '(("html.trace.server" lsp-html-trace-server)
   ("html.autoClosingTags" lsp-html-auto-closing-tags t)
   ("html.validate.styles" lsp-html-validate-styles t)
   ("html.validate.scripts" lsp-html-validate-scripts t)
   ("html.suggest.html5" lsp-html-suggest-html5 t)
   ("html.format.wrapAttributes" lsp-html-format-wrap-attributes)
   ("html.format.extraLiners" lsp-html-format-extra-liners)
   ("html.format.endWithNewline" lsp-html-format-end-with-newline t)
   ("html.format.indentHandlebars" lsp-html-format-indent-handlebars t)
   ("html.format.maxPreserveNewLines" lsp-html-format-max-preserve-new-lines)
   ("html.format.preserveNewLines" lsp-html-format-preserve-new-lines t)
   ("html.format.indentInnerHtml" lsp-html-format-indent-inner-html t)
   ("html.format.contentUnformatted" lsp-html-format-content-unformatted)
   ("html.format.unformatted" lsp-html-format-unformatted)
   ("html.format.wrapLineLength" lsp-html-format-wrap-line-length)
   ("html.format.enable" lsp-html-format-enable t)
   ("html.experimental.customData" lsp-html-experimental-custom-data)))

(defcustom lsp-html-server-command-args '("--stdio")
  "Command to start html-languageserver."
  :type '(repeat string)
  :group 'lsp-html
  :package-version '(lsp-mode . "6.3"))

(lsp-dependency 'html-language-server
                '(:system "vscode-html-language-server")
                '(:npm :package "vscode-langservers-extracted"
                       :path "vscode-html-language-server"))

(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection
                                   (lambda ()
                                     (cons (lsp-package-path 'html-language-server)
                                           lsp-html-server-command-args)))
                  :activation-fn (lsp-activate-on "html")
                  :priority -4
                  :completion-in-comments? t
                  :server-id 'html-ls
                  :initialized-fn (lambda (w)
                                    (with-lsp-workspace w
                                      (lsp--set-configuration
                                       (lsp-configuration-section "html"))))
                  :download-server-fn (lambda (_client callback error-callback _update?)
                                        (lsp-package-ensure
                                         'html-language-server callback
                                         error-callback))))

(lsp-consistency-check lsp-html)

(provide 'lsp-html)
;;; lsp-html.el ends here