config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-vetur.el (13371B)


      1 ;;; lsp-vetur.el --- vls configuration                 -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2019  Ivan Yonchovski
      4 
      5 ;; Author: Ivan Yonchovski <yyoncho@gmail.com>
      6 ;; Keywords:
      7 
      8 ;; This program is free software; you can redistribute it and/or modify
      9 ;; it under the terms of the GNU General Public License as published by
     10 ;; the Free Software Foundation, either version 3 of the License, or
     11 ;; (at your option) any later version.
     12 
     13 ;; This program is distributed in the hope that it will be useful,
     14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;; GNU General Public License for more details.
     17 
     18 ;; You should have received a copy of the GNU General Public License
     19 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     20 
     21 ;;; Commentary:
     22 
     23 ;; VLS configuration
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 (require 'lsp-html)
     29 ;; vls shares the same format configurations with ts-ls.
     30 (require 'lsp-javascript)
     31 
     32 (defgroup lsp-vetur nil
     33   "LSP support for Vue, using the Vue Language Server."
     34   :group 'lsp-mode
     35   :link '(url-link "https://github.com/vuejs/vetur/tree/master/server")
     36   :package-version '(lsp-mode . "6.1"))
     37 
     38 (defcustom lsp-vetur-ignore-project-warning nil
     39   "Ignore projects without jsconfig.json or tsconfig.json warnings."
     40   :type 'boolean
     41   :group 'lsp-vetur
     42   :package-version '(lsp-mode . "9.0.0"))
     43 
     44 (defcustom lsp-vetur-use-workspace-dependencies nil
     45   "Use dependencies from workspace. Currently only for
     46 TypeScript."
     47   :type 'boolean
     48   :group 'lsp-vetur
     49   :package-version '(lsp-mode . "6.1"))
     50 
     51 (defcustom lsp-vetur-completion-auto-import t
     52   "Include completion for module export and auto import them"
     53   :type 'boolean
     54   :group 'lsp-vetur
     55   :package-version '(lsp-mode . "6.1"))
     56 
     57 (defcustom lsp-vetur-completion-scaffold-snippet-sources
     58   '((workspace . "(W)")
     59     (user . "(U)")
     60     (vetur . "(V)"))
     61   "Where Vetur source Scaffold Snippets from and how to indicate them.
     62 - workspace: <WORKSPACE>/.vscode/vetur/snippets.
     63 - user: <USER-DATA-DIR>/User/snippets/vetur.
     64 - vetur: Bundled in Vetur.
     65 The source value can be a string \"(User)\" or an emoji \"✌\".
     66 Set a source to \"\" to disable it.
     67 "
     68   :type 'alist
     69   :group 'lsp-vetur
     70   :link '(url-link "https://vuejs.github.io/vetur/guide/snippet.html")
     71   :package-version '(lsp-mode. "9.0.0"))
     72 
     73 (defcustom lsp-vetur-completion-tag-casing "kebab"
     74   "Casing conversion for tag completion"
     75   :type '(choice
     76           (const "initial")
     77           (const "kebab"))
     78   :group 'lsp-vetur
     79   :package-version '(lsp-mode . "6.1"))
     80 
     81 (defcustom lsp-vetur-grammar-custom-blocks '((docs . "md") (i18n . "json"))
     82   "Mapping from custom block tag name to language name. Used for
     83  generating grammar to support syntax highlighting for custom
     84  blocks."
     85   :type 'alist
     86   :group 'lsp-vetur
     87   :package-version '(lsp-mode . "6.1"))
     88 
     89 (defcustom lsp-vetur-validation-template t
     90   "Validate vue-html in <template> using eslint-plugin-vue"
     91   :type 'boolean
     92   :group 'lsp-vetur
     93   :package-version '(lsp-mode . "6.1"))
     94 
     95 (defcustom lsp-vetur-language-features-code-actions t
     96   "Enable/disable code actions."
     97   :type 'boolean
     98   :group 'lsp-vetur
     99   :package-version '(lsp-mode . "8.0.0"))
    100 
    101 (defcustom lsp-vetur-validation-style t
    102   "Validate css/scss/less/postcss in <style>"
    103   :type 'boolean
    104   :group 'lsp-vetur
    105   :package-version '(lsp-mode . "6.1"))
    106 
    107 (defcustom lsp-vetur-validation-script t
    108   "Validate js/ts in <script>"
    109   :type 'boolean
    110   :group 'lsp-vetur
    111   :package-version '(lsp-mode . "6.1"))
    112 
    113 (defcustom lsp-vetur-format-enable t
    114   "Enable/disable the Vetur document formatter."
    115   :type 'boolean
    116   :group 'lsp-vetur
    117   :package-version '(lsp-mode . "6.1"))
    118 
    119 (defcustom lsp-vetur-format-options-tab-size 2
    120   "Number of spaces per indentation level. Inherited by all formatters."
    121   :type 'number
    122   :group 'lsp-vetur
    123   :package-version '(lsp-mode . "6.1"))
    124 
    125 (defcustom lsp-vetur-format-options-use-tabs nil
    126   "Use tabs for indentation. Inherited by all formatters."
    127   :type 'boolean
    128   :group 'lsp-vetur
    129   :package-version '(lsp-mode . "6.1"))
    130 
    131 (defcustom lsp-vetur-format-default-formatter-html "prettyhtml"
    132   "Default formatter for <template> region"
    133   :type '(choice
    134           (const "none")
    135           (const "prettyhtml")
    136           (const "js-beautify-html")
    137           (const "prettier"))
    138   :group 'lsp-vetur
    139   :package-version '(lsp-mode . "6.1"))
    140 
    141 (defcustom lsp-vetur-format-default-formatter-css "prettier"
    142   "Default formatter for <style> region"
    143   :type '(choice
    144           (const "none")
    145           (const "prettier"))
    146   :group 'lsp-vetur
    147   :package-version '(lsp-mode . "6.1"))
    148 
    149 (defcustom lsp-vetur-format-default-formatter-postcss "prettier"
    150   "Default formatter for <style lang='postcss'> region"
    151   :type '(choice
    152           (const "none")
    153           (const "prettier"))
    154   :group 'lsp-vetur
    155   :package-version '(lsp-mode . "6.1"))
    156 
    157 (defcustom lsp-vetur-format-default-formatter-scss "prettier"
    158   "Default formatter for <style lang='scss'> region"
    159   :type '(choice
    160           (const "none")
    161           (const "prettier"))
    162   :group 'lsp-vetur
    163   :package-version '(lsp-mode . "6.1"))
    164 
    165 (defcustom lsp-vetur-format-default-formatter-less "prettier"
    166   "Default formatter for <style lang='less'> region"
    167   :type '(choice
    168           (const "none")
    169           (const "prettier"))
    170   :group 'lsp-vetur
    171   :package-version '(lsp-mode . "6.1"))
    172 
    173 (defcustom lsp-vetur-format-default-formatter-stylus "stylus-supremacy"
    174   "Default formatter for <style lang='stylus'> region"
    175   :type '(choice
    176           (const "none")
    177           (const "stylus-supremacy"))
    178   :group 'lsp-vetur
    179   :package-version '(lsp-mode . "6.1"))
    180 
    181 (defcustom lsp-vetur-format-default-formatter-js "prettier"
    182   "Default formatter for <script> region"
    183   :type '(choice
    184           (const "none")
    185           (const "prettier")
    186           (const "prettier-eslint")
    187           (const "vscode-typescript"))
    188   :group 'lsp-vetur
    189   :package-version '(lsp-mode . "6.1"))
    190 
    191 (defcustom lsp-vetur-format-default-formatter-ts "prettier"
    192   "Default formatter for <script> region"
    193   :type '(choice
    194           (const "none")
    195           (const "prettier")
    196           (const "vscode-typescript"))
    197   :group 'lsp-vetur
    198   :package-version '(lsp-mode . "6.1"))
    199 
    200 (defcustom lsp-vetur-format-default-formatter-options
    201   '((js-beautify-html (wrap_attributes . "force-expand-multiline"))
    202     (prettyhtml (printWidth . 100)
    203                 (singleQuote . :json-false)
    204                 (wrapAttributes . :json-false)
    205                 (sortAttributes . :json-false)))
    206   "Options for all default formatters"
    207   :type 'alist
    208   :group 'lsp-vetur
    209   :package-version '(lsp-mode . "6.1"))
    210 
    211 (defcustom lsp-vetur-format-style-initial-indent nil
    212   "Whether to have initial indent for <style> region"
    213   :type 'boolean
    214   :group 'lsp-vetur
    215   :package-version '(lsp-mode . "6.1"))
    216 
    217 (defcustom lsp-vetur-format-script-initial-indent nil
    218   "Whether to have initial indent for <script> region"
    219   :type 'boolean
    220   :group 'lsp-vetur
    221   :package-version '(lsp-mode . "6.1"))
    222 
    223 (defcustom lsp-vetur-trace-server "off"
    224   "Traces the communication between VS Code and Vue Language Server."
    225   :type '(choice
    226           (const "off")
    227           (const "messages")
    228           (const "verbose"))
    229   :group 'lsp-vetur
    230   :package-version '(lsp-mode . "6.1"))
    231 
    232 (defcustom lsp-vetur-dev-vls-path ""
    233   "The vls path for development"
    234   :type 'string
    235   :group 'lsp-vetur
    236   :package-version '(lsp-mode . "6.3"))
    237 
    238 (defcustom lsp-vetur-dev-vls-port -1
    239   "The vls port for development"
    240   :type 'integer
    241   :group 'lsp-vetur
    242   :package-version '(lsp-mode . "6.3"))
    243 
    244 (defcustom lsp-vetur-dev-log-level "INFO"
    245   "The vls log level for development"
    246   :type '(choice
    247           (const "INFO")
    248           (const "DEBUG"))
    249   :group 'lsp-vetur
    250   :package-version '(lsp-mode . "6.3"))
    251 
    252 (defcustom lsp-vetur-experimental-template-interpolation-service nil
    253   "Whether to have template interpolation service"
    254   :type 'boolean
    255   :group 'lsp-vetur
    256   :package-version '(lsp-mode . "6.3"))
    257 
    258 (defcustom lsp-vetur-emmet "never"
    259   "Controls the Emmet suggestions that show up in the suggestion/completion list."
    260   :type  '(choice
    261            (const "never")
    262            (const "inMarkupAndStylesheetFilesOnly")
    263            (const "always" ))
    264   :group 'lsp-vetur
    265   :package-version '(lsp-mode . "6.1"))
    266 
    267 (lsp-register-custom-settings
    268  '(("vetur.trace.server" lsp-vetur-trace-server)
    269    ("vetur.ignoreProjectWarning" lsp-vetur-ignore-project-warning t)
    270    ("vetur.format.scriptInitialIndent" lsp-vetur-format-script-initial-indent t)
    271    ("vetur.format.styleInitialIndent" lsp-vetur-format-style-initial-indent t)
    272    ("vetur.format.defaultFormatterOptions" lsp-vetur-format-default-formatter-options)
    273    ("vetur.format.defaultFormatter.ts" lsp-vetur-format-default-formatter-ts)
    274    ("vetur.format.defaultFormatter.js" lsp-vetur-format-default-formatter-js)
    275    ("vetur.format.defaultFormatter.stylus" lsp-vetur-format-default-formatter-stylus)
    276    ("vetur.format.defaultFormatter.less" lsp-vetur-format-default-formatter-less)
    277    ("vetur.format.defaultFormatter.scss" lsp-vetur-format-default-formatter-scss)
    278    ("vetur.format.defaultFormatter.postcss" lsp-vetur-format-default-formatter-postcss)
    279    ("vetur.format.defaultFormatter.css" lsp-vetur-format-default-formatter-css)
    280    ("vetur.format.defaultFormatter.html" lsp-vetur-format-default-formatter-html)
    281    ("vetur.format.options.useTabs" lsp-vetur-format-options-use-tabs t)
    282    ("vetur.format.options.tabSize" lsp-vetur-format-options-tab-size)
    283    ("vetur.format.enable" lsp-vetur-format-enable t)
    284    ("vetur.validation.script" lsp-vetur-validation-script t)
    285    ("vetur.validation.style" lsp-vetur-validation-style t)
    286    ("vetur.validation.template" lsp-vetur-validation-template t)
    287    ("vetur.languageFeatures.codeActions" lsp-vetur-language-features-code-actions t)
    288    ("vetur.grammar.customBlocks" lsp-vetur-grammar-custom-blocks)
    289    ("vetur.completion.tagCasing" lsp-vetur-completion-tag-casing)
    290    ("vetur.completion.scaffoldSnippetSources" lsp-vetur-completion-scaffold-snippet-sources)
    291    ("vetur.completion.autoImport" lsp-vetur-completion-auto-import t)
    292    ("vetur.useWorkspaceDependencies" lsp-vetur-use-workspace-dependencies t)
    293    ("vetur.dev.vlsPath" lsp-vetur-dev-vls-path)
    294    ("vetur.dev.vlsPort" lsp-vetur-dev-vls-port)
    295    ("vetur.dev.logLevel" lsp-vetur-dev-log-level)
    296    ("vetur.experimental.templateInterpolationService" lsp-vetur-experimental-template-interpolation-service t)
    297    ("emmet.showExpandedAbbreviation" lsp-vetur-emmet)))
    298 
    299 (define-obsolete-variable-alias
    300   'lsp-vetur-server
    301   'lsp-vetur-server-command
    302   "lsp-mode 6.1")
    303 
    304 (defcustom lsp-vetur-global-snippets-dir (expand-file-name (locate-user-emacs-file ".snippets/vetur"))
    305   "Path to snippets dir."
    306   :type 'file
    307   :risky t
    308   :package-version '(lsp-mode . "6.2"))
    309 
    310 (defcustom lsp-vetur-server-command '("vls")
    311   "Command to start vetur."
    312   :type '(repeat string)
    313   :risky t
    314   :package-version '(lsp-mode . "6.1"))
    315 
    316 (lsp-dependency 'vetur-language-server
    317                 '(:system "vls")
    318                 '(:npm :package "vls" :path "vls"))
    319 
    320 (lsp-register-client
    321  (make-lsp-client :new-connection (lsp-stdio-connection
    322                                    (lambda ()
    323                                      `(,(or (executable-find (cl-first lsp-vetur-server-command))
    324                                             (lsp-package-path 'vetur-language-server))
    325                                        ,@(cl-rest lsp-vetur-server-command))))
    326                   :activation-fn (lambda (filename _mode)
    327                                    (string= (file-name-extension filename) "vue"))
    328                   :priority -1
    329                   :multi-root t
    330                   :ignore-messages '("readFile .*? requested by Vue but content not available")
    331                   :server-id 'vls
    332                   :initialization-options (lambda () (ht-merge (lsp-configuration-section "vetur")
    333                                                                (lsp-configuration-section "html")
    334                                                                (lsp-configuration-section "javascript")
    335                                                                (lsp-configuration-section "typescript")
    336                                                                (lsp-configuration-section "emmet")
    337                                                                (ht ("globalSnippetDir" lsp-vetur-global-snippets-dir))))
    338                   :initialized-fn (lambda (workspace)
    339                                     (with-lsp-workspace workspace
    340                                       (lsp--set-configuration
    341                                        (ht-merge (lsp-configuration-section "vetur")
    342                                                  (lsp-configuration-section "html")
    343                                                  (lsp-configuration-section "javascript")
    344                                                  (lsp-configuration-section "emmet")
    345                                                  (lsp-configuration-section "typescript")))))
    346                   :download-server-fn (lambda (_client callback error-callback _update?)
    347                                         (lsp-package-ensure 'vetur-language-server
    348                                                             callback error-callback))))
    349 
    350 (lsp-consistency-check lsp-vetur)
    351 
    352 (provide 'lsp-vetur)
    353 ;;; lsp-vetur.el ends here