config

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

lsp-svelte.el (12432B)


      1 ;;; lsp-svelte.el --- LSP Svelte integration -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2020 Stepan Lusnikov
      4 
      5 ;; Author: Stepan Lusnikov <endenwer@gmail.com>
      6 ;; Keywords: lsp svelte
      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 ;; LSP client for Svelte
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-svelte nil
     30   "LSP support for Svelte."
     31   :group 'lsp-mode
     32   :link '(url-link
     33           "https://github.com/sveltejs/language-tools"))
     34 
     35 (lsp-dependency 'svelte-language-server
     36                 '(:system "svelteserver")
     37                 '(:npm :package "svelte-language-server"
     38                        :path "svelteserver"))
     39 
     40 (defcustom lsp-svelte-plugin-typescript-enable t
     41   "Enable the TypeScript plugin"
     42   :type 'boolean
     43   :package-version '(lsp-mode . "8.0.0"))
     44 
     45 (defcustom lsp-svelte-plugin-typescript-diagnostics-enable t
     46   "Enable diagnostic messages for TypeScript"
     47   :type 'boolean
     48   :package-version '(lsp-mode . "8.0.0"))
     49 
     50 (defcustom lsp-svelte-plugin-typescript-hover-enable t
     51   "Enable hover info for TypeScript"
     52   :type 'boolean
     53   :package-version '(lsp-mode . "8.0.0"))
     54 
     55 (defcustom lsp-svelte-plugin-typescript-document-symbols-enable t
     56   "Enable document symbols for TypeScript"
     57   :type 'boolean
     58   :package-version '(lsp-mode . "8.0.0"))
     59 
     60 (defcustom lsp-svelte-plugin-typescript-completions-enable t
     61   "Enable completions for TypeScript"
     62   :type 'boolean
     63   :package-version '(lsp-mode . "8.0.0"))
     64 
     65 (defcustom lsp-svelte-plugin-typescript-find-references-enable t
     66   "Enable find-references for TypeScript"
     67   :type 'boolean
     68   :package-version '(lsp-mode . "8.0.0"))
     69 
     70 (defcustom lsp-svelte-plugin-typescript-definitions-enable t
     71   "Enable go to definition for TypeScript"
     72   :type 'boolean
     73   :package-version '(lsp-mode . "8.0.0"))
     74 
     75 (defcustom lsp-svelte-plugin-typescript-code-actions-enable t
     76   "Enable code actions for TypeScript"
     77   :type 'boolean
     78   :package-version '(lsp-mode . "8.0.0"))
     79 
     80 (defcustom lsp-svelte-plugin-typescript-selection-range-enable t
     81   "Enable selection range for TypeScript"
     82   :type 'boolean
     83   :package-version '(lsp-mode . "8.0.0"))
     84 
     85 (defcustom lsp-svelte-plugin-typescript-signature-help-enable t
     86   "Enable signature help (parameter hints) for TypeScript"
     87   :type 'boolean
     88   :package-version '(lsp-mode . "8.0.0"))
     89 
     90 (defcustom lsp-svelte-plugin-typescript-rename-enable t
     91   "Enable rename functionality for JS/TS variables inside Svelte files"
     92   :type 'boolean
     93   :package-version '(lsp-mode . "8.0.0"))
     94 
     95 (defcustom lsp-svelte-plugin-css-enable t
     96   "Enable the CSS plugin"
     97   :type 'boolean
     98   :package-version '(lsp-mode . "8.0.0"))
     99 
    100 (defcustom lsp-svelte-plugin-css-globals ""
    101   "Which css files should be checked for global variables
    102 (`--global-var: value;`).
    103 
    104 These variables are added to the css completions.  String of comma-separated
    105 file paths or globs relative to workspace root."
    106   :type 'string
    107   :package-version '(lsp-mode . "8.0.0"))
    108 
    109 (defcustom lsp-svelte-plugin-css-diagnostics-enable t
    110   "Enable diagnostic messages for CSS"
    111   :type 'boolean
    112   :package-version '(lsp-mode . "8.0.0"))
    113 
    114 (defcustom lsp-svelte-plugin-css-hover-enable t
    115   "Enable hover info for CSS"
    116   :type 'boolean
    117   :package-version '(lsp-mode . "8.0.0"))
    118 
    119 (defcustom lsp-svelte-plugin-css-completions-enable t
    120   "Enable auto completions for CSS"
    121   :type 'boolean
    122   :package-version '(lsp-mode . "8.0.0"))
    123 
    124 (defcustom lsp-svelte-plugin-css-completions-emmet t
    125   "Enable emmet auto completions for CSS"
    126   :type 'boolean
    127   :package-version '(lsp-mode . "8.0.0"))
    128 
    129 (defcustom lsp-svelte-plugin-css-document-colors-enable t
    130   "Enable document colors for CSS"
    131   :type 'boolean
    132   :package-version '(lsp-mode . "8.0.0"))
    133 
    134 (defcustom lsp-svelte-plugin-css-color-presentations-enable t
    135   "Enable color picker for CSS"
    136   :type 'boolean
    137   :package-version '(lsp-mode . "8.0.0"))
    138 
    139 (defcustom lsp-svelte-plugin-css-document-symbols-enable t
    140   "Enable document symbols for CSS"
    141   :type 'boolean
    142   :package-version '(lsp-mode . "8.0.0"))
    143 
    144 (defcustom lsp-svelte-plugin-css-selection-range-enable t
    145   "Enable selection range for CSS"
    146   :type 'boolean
    147   :package-version '(lsp-mode . "8.0.0"))
    148 
    149 (defcustom lsp-svelte-plugin-html-enable t
    150   "Enable the HTML plugin"
    151   :type 'boolean
    152   :package-version '(lsp-mode . "8.0.0"))
    153 
    154 (defcustom lsp-svelte-plugin-html-hover-enable t
    155   "Enable hover info for HTML"
    156   :type 'boolean
    157   :package-version '(lsp-mode . "8.0.0"))
    158 
    159 (defcustom lsp-svelte-plugin-html-completions-enable t
    160   "Enable auto completions for HTML"
    161   :type 'boolean
    162   :package-version '(lsp-mode . "8.0.0"))
    163 
    164 (defcustom lsp-svelte-plugin-html-completions-emmet t
    165   "Enable emmet auto completions for HTML"
    166   :type 'boolean
    167   :package-version '(lsp-mode . "8.0.0"))
    168 
    169 (defcustom lsp-svelte-plugin-html-tag-complete-enable t
    170   "Enable HTML tag auto closing"
    171   :type 'boolean
    172   :package-version '(lsp-mode . "8.0.0"))
    173 
    174 (defcustom lsp-svelte-plugin-html-document-symbols-enable t
    175   "Enable document symbols for HTML"
    176   :type 'boolean
    177   :package-version '(lsp-mode . "8.0.0"))
    178 
    179 (defcustom lsp-svelte-plugin-svelte-enable t
    180   "Enable the Svelte plugin"
    181   :type 'boolean
    182   :package-version '(lsp-mode . "8.0.0"))
    183 
    184 (defcustom lsp-svelte-plugin-svelte-diagnostics-enable t
    185   "Enable diagnostic messages for Svelte"
    186   :type 'boolean
    187   :package-version '(lsp-mode . "8.0.0"))
    188 
    189 (defcustom lsp-svelte-plugin-svelte-compiler-warnings nil
    190   "Svelte compiler warning codes to ignore or to treat as errors.
    191 Example: `((css-unused-selector . ignore) (unused-export-let . error))"
    192   :type '(alist :key-type (symbol :tag "Warning code")
    193                 :value-type (choice
    194                              (const :tag "Ignore" ignore)
    195                              (const :tag "Treat as error" error)))
    196   :package-version '(lsp-mode . "8.0.0"))
    197 
    198 (defcustom lsp-svelte-plugin-svelte-format-enable t
    199   "Enable formatting for Svelte (includes css & js)"
    200   :type 'boolean
    201   :package-version '(lsp-mode . "8.0.0"))
    202 
    203 (defcustom lsp-svelte-plugin-svelte-completions-enable t
    204   "Enable auto completions for Svelte"
    205   :type 'boolean
    206   :package-version '(lsp-mode . "8.0.0"))
    207 
    208 (defcustom lsp-svelte-plugin-svelte-hover-enable t
    209   "Enable hover information for Svelte"
    210   :type 'boolean
    211   :package-version '(lsp-mode . "8.0.0"))
    212 
    213 (defcustom lsp-svelte-plugin-svelte-code-actions-enable t
    214   "Enable Code Actions for Svelte"
    215   :type 'boolean
    216   :package-version '(lsp-mode . "8.0.0"))
    217 
    218 (defcustom lsp-svelte-plugin-svelte-selection-range-enable t
    219   "Enable selection range for Svelte"
    220   :type 'boolean
    221   :package-version '(lsp-mode . "8.0.0"))
    222 
    223 (defcustom lsp-svelte-plugin-svelte-rename-enable t
    224   "Enable rename/move Svelte files functionality"
    225   :type 'boolean
    226   :package-version '(lsp-mode . "8.0.0"))
    227 
    228 (lsp-register-custom-settings
    229  '(("svelte.plugin.svelte.rename.enable" lsp-svelte-plugin-svelte-rename-enable t)
    230    ("svelte.plugin.svelte.selectionRange.enable" lsp-svelte-plugin-svelte-selection-range-enable t)
    231    ("svelte.plugin.svelte.codeActions.enable" lsp-svelte-plugin-svelte-code-actions-enable t)
    232    ("svelte.plugin.svelte.hover.enable" lsp-svelte-plugin-svelte-hover-enable t)
    233    ("svelte.plugin.svelte.completions.enable" lsp-svelte-plugin-svelte-completions-enable t)
    234    ("svelte.plugin.svelte.format.enable" lsp-svelte-plugin-svelte-format-enable t)
    235    ("svelte.plugin.svelte.compilerWarnings" lsp-svelte-plugin-svelte-compiler-warnings)
    236    ("svelte.plugin.svelte.diagnostics.enable" lsp-svelte-plugin-svelte-diagnostics-enable t)
    237    ("svelte.plugin.svelte.enable" lsp-svelte-plugin-svelte-enable t)
    238    ("svelte.plugin.html.documentSymbols.enable" lsp-svelte-plugin-html-document-symbols-enable t)
    239    ("svelte.plugin.html.tagComplete.enable" lsp-svelte-plugin-html-tag-complete-enable t)
    240    ("svelte.plugin.html.completions.emmet" lsp-svelte-plugin-html-completions-emmet t)
    241    ("svelte.plugin.html.completions.enable" lsp-svelte-plugin-html-completions-enable t)
    242    ("svelte.plugin.html.hover.enable" lsp-svelte-plugin-html-hover-enable t)
    243    ("svelte.plugin.html.enable" lsp-svelte-plugin-html-enable t)
    244    ("svelte.plugin.css.selectionRange.enable" lsp-svelte-plugin-css-selection-range-enable t)
    245    ("svelte.plugin.css.documentSymbols.enable" lsp-svelte-plugin-css-document-symbols-enable t)
    246    ("svelte.plugin.css.colorPresentations.enable" lsp-svelte-plugin-css-color-presentations-enable t)
    247    ("svelte.plugin.css.documentColors.enable" lsp-svelte-plugin-css-document-colors-enable t)
    248    ("svelte.plugin.css.completions.emmet" lsp-svelte-plugin-css-completions-emmet t)
    249    ("svelte.plugin.css.completions.enable" lsp-svelte-plugin-css-completions-enable t)
    250    ("svelte.plugin.css.hover.enable" lsp-svelte-plugin-css-hover-enable t)
    251    ("svelte.plugin.css.diagnostics.enable" lsp-svelte-plugin-css-diagnostics-enable t)
    252    ("svelte.plugin.css.globals" lsp-svelte-plugin-css-globals)
    253    ("svelte.plugin.css.enable" lsp-svelte-plugin-css-enable t)
    254    ("svelte.plugin.typescript.rename.enable" lsp-svelte-plugin-typescript-rename-enable t)
    255    ("svelte.plugin.typescript.signatureHelp.enable" lsp-svelte-plugin-typescript-signature-help-enable t)
    256    ("svelte.plugin.typescript.selectionRange.enable" lsp-svelte-plugin-typescript-selection-range-enable t)
    257    ("svelte.plugin.typescript.codeActions.enable" lsp-svelte-plugin-typescript-code-actions-enable t)
    258    ("svelte.plugin.typescript.definitions.enable" lsp-svelte-plugin-typescript-definitions-enable t)
    259    ("svelte.plugin.typescript.findReferences.enable" lsp-svelte-plugin-typescript-find-references-enable t)
    260    ("svelte.plugin.typescript.completions.enable" lsp-svelte-plugin-typescript-completions-enable t)
    261    ("svelte.plugin.typescript.documentSymbols.enable" lsp-svelte-plugin-typescript-document-symbols-enable t)
    262    ("svelte.plugin.typescript.hover.enable" lsp-svelte-plugin-typescript-hover-enable t)
    263    ("svelte.plugin.typescript.diagnostics.enable" lsp-svelte-plugin-typescript-diagnostics-enable t)
    264    ("svelte.plugin.typescript.enable" lsp-svelte-plugin-typescript-enable t)))
    265 
    266 (lsp-register-client
    267  (make-lsp-client
    268   :new-connection (lsp-stdio-connection
    269                    (lambda ()
    270                      `(,(lsp-package-path 'svelte-language-server)
    271                        "--stdio")))
    272   :activation-fn (lambda (file-name _mode)
    273                    (string= (f-ext file-name)
    274                             "svelte"))
    275   :initialization-options
    276   (lambda ()
    277     (list :config (ht-get* (lsp-configuration-section "svelte.plugin")
    278                            "svelte"
    279                            "plugin")
    280           :prettierConfig (lsp-configuration-section "prettier")
    281           :emmetConfig (lsp-configuration-section "emmet")
    282           :typescriptConfig: (list :typescript (lsp-configuration-section "typescript")
    283                                    :javascript (lsp-configuration-section "javascript"))
    284           :dontFilterIncompleteCompletions t))
    285   :server-id 'svelte-ls
    286   :download-server-fn (lambda (_client callback error-callback _update?)
    287                         (lsp-package-ensure 'svelte-language-server callback error-callback))
    288   :initialized-fn
    289   (lambda (workspace)
    290     (with-lsp-workspace workspace
    291       (lsp--set-configuration
    292        (ht-merge (lsp-configuration-section "svelte")
    293                  (lsp-configuration-section "javascript")
    294                  (lsp-configuration-section "typescript")))
    295       (lsp--server-register-capability
    296        (lsp-make-registration
    297         :id "js/ts/id"
    298         :method "workspace/didChangeWatchedFiles"
    299         :register-options? (lsp-make-did-change-watched-files-registration-options
    300                             :watchers
    301                             (vector (lsp-make-file-system-watcher :glob-pattern "**/*.js")
    302                                     (lsp-make-file-system-watcher :glob-pattern "**/*.ts")))))))))
    303 
    304 (lsp-consistency-check lsp-svelte)
    305 
    306 (provide 'lsp-svelte)
    307 ;;; lsp-svelte.el ends here