config

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

lsp-css.el (8183B)


      1 ;;; lsp-css.el --- CSS language server 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 ;;
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-protocol)
     28 (require 'lsp-mode)
     29 
     30 (defgroup lsp-css nil
     31   "LSP support for CSS."
     32   :group 'lsp-mode
     33   :link '(url-link
     34           "https://github.com/microsoft/vscode/tree/main/extensions/css-language-features/server"))
     35 
     36 (defcustom lsp-css-experimental-custom-data nil
     37   "A list of JSON file paths that define custom CSS data that
     38 loads custom properties, at directives, pseudo classes /
     39 elements."
     40   :type '(repeat string))
     41 
     42 (defcustom lsp-css-completion-trigger-property-value-completion t
     43   "By default, VS Code triggers property value completion after
     44 selecting a CSS property. Use this setting to disable this
     45 behavior."
     46   :type 'boolean)
     47 
     48 (defcustom lsp-css-validate t
     49   "Enables or disables all validations."
     50   :type 'boolean)
     51 
     52 (defcustom lsp-css-lint-compatible-vendor-prefixes "ignore"
     53   "When using a vendor-specific prefix make sure to also include
     54 all other vendor-specific properties."
     55   :type '(choice
     56           (const "ignore")
     57           (const "warning")
     58           (const "error")))
     59 
     60 (defcustom lsp-css-lint-vendor-prefix "warning"
     61   "When using a vendor-specific prefix, also include the standard
     62 property."
     63   :type '(choice
     64           (const "ignore")
     65           (const "warning")
     66           (const "error")))
     67 
     68 (defcustom lsp-css-lint-duplicate-properties "ignore"
     69   "Do not use duplicate style definitions."
     70   :type '(choice
     71           (const "ignore")
     72           (const "warning")
     73           (const "error")))
     74 
     75 (defcustom lsp-css-lint-empty-rules "warning"
     76   "Do not use empty rulesets."
     77   :type '(choice
     78           (const "ignore")
     79           (const "warning")
     80           (const "error")))
     81 
     82 (defcustom lsp-css-lint-import-statement "ignore"
     83   "Import statements do not load in parallel."
     84   :type '(choice
     85           (const "ignore")
     86           (const "warning")
     87           (const "error")))
     88 
     89 (defcustom lsp-css-lint-box-model "ignore"
     90   nil
     91   :type '(choice
     92           (const "ignore")
     93           (const "warning")
     94           (const "error")))
     95 
     96 (defcustom lsp-css-lint-universal-selector "ignore"
     97   nil
     98   :type '(choice
     99           (const "ignore")
    100           (const "warning")
    101           (const "error")))
    102 
    103 (defcustom lsp-css-lint-zero-units "ignore"
    104   "No unit for zero needed."
    105   :type '(choice
    106           (const "ignore")
    107           (const "warning")
    108           (const "error")))
    109 
    110 (defcustom lsp-css-lint-font-face-properties "warning"
    111   nil
    112   :type '(choice
    113           (const "ignore")
    114           (const "warning")
    115           (const "error")))
    116 
    117 (defcustom lsp-css-lint-hex-color-length "error"
    118   "Hex colors must consist of three or six hex numbers."
    119   :type '(choice
    120           (const "ignore")
    121           (const "warning")
    122           (const "error")))
    123 
    124 (defcustom lsp-css-lint-arguments-in-color-function "error"
    125   "Invalid number of parameters."
    126   :type '(choice
    127           (const "ignore")
    128           (const "warning")
    129           (const "error")))
    130 
    131 (defcustom lsp-css-lint-unknown-properties "warning"
    132   "Unknown property."
    133   :type '(choice
    134           (const "ignore")
    135           (const "warning")
    136           (const "error")))
    137 
    138 (defcustom lsp-css-lint-valid-properties nil
    139   "A list of properties that are not validated against the
    140 `unknownProperties` rule."
    141   :type '(repeat string))
    142 
    143 (defcustom lsp-css-lint-ie-hack "ignore"
    144   "IE hacks are only necessary when supporting IE7 and older."
    145   :type '(choice
    146           (const "ignore")
    147           (const "warning")
    148           (const "error")))
    149 
    150 (defcustom lsp-css-lint-unknown-vendor-specific-properties "ignore"
    151   "Unknown vendor specific property."
    152   :type '(choice
    153           (const "ignore")
    154           (const "warning")
    155           (const "error")))
    156 
    157 (defcustom lsp-css-lint-property-ignored-due-to-display "warning"
    158   nil
    159   :type '(choice
    160           (const "ignore")
    161           (const "warning")
    162           (const "error")))
    163 
    164 (defcustom lsp-css-lint-important "ignore"
    165   nil
    166   :type '(choice
    167           (const "ignore")
    168           (const "warning")
    169           (const "error")))
    170 
    171 (defcustom lsp-css-lint-float "ignore"
    172   nil
    173   :type '(choice
    174           (const "ignore")
    175           (const "warning")
    176           (const "error")))
    177 
    178 (defcustom lsp-css-lint-id-selector "ignore"
    179   "Selectors should not contain IDs because these rules are too
    180 tightly coupled with the HTML."
    181   :type '(choice
    182           (const "ignore")
    183           (const "warning")
    184           (const "error")))
    185 
    186 (defcustom lsp-css-lint-unknown-at-rules "warning"
    187   "Unknown at-rule."
    188   :type '(choice
    189           (const "ignore")
    190           (const "warning")
    191           (const "error")))
    192 
    193 (defcustom lsp-css-trace-server "off"
    194   "Traces the communication between VS Code and the CSS language
    195 server."
    196   :type '(choice
    197           (const "off")
    198           (const "messages")
    199           (const "verbose")))
    200 
    201 (lsp-register-custom-settings
    202  '(("css.trace.server" lsp-css-trace-server)
    203    ("css.lint.unknownAtRules" lsp-css-lint-unknown-at-rules)
    204    ("css.lint.idSelector" lsp-css-lint-id-selector)
    205    ("css.lint.float" lsp-css-lint-float)
    206    ("css.lint.important" lsp-css-lint-important)
    207    ("css.lint.propertyIgnoredDueToDisplay" lsp-css-lint-property-ignored-due-to-display)
    208    ("css.lint.unknownVendorSpecificProperties" lsp-css-lint-unknown-vendor-specific-properties)
    209    ("css.lint.ieHack" lsp-css-lint-ie-hack)
    210    ("css.lint.validProperties" lsp-css-lint-valid-properties)
    211    ("css.lint.unknownProperties" lsp-css-lint-unknown-properties)
    212    ("css.lint.argumentsInColorFunction" lsp-css-lint-arguments-in-color-function)
    213    ("css.lint.hexColorLength" lsp-css-lint-hex-color-length)
    214    ("css.lint.fontFaceProperties" lsp-css-lint-font-face-properties)
    215    ("css.lint.zeroUnits" lsp-css-lint-zero-units)
    216    ("css.lint.universalSelector" lsp-css-lint-universal-selector)
    217    ("css.lint.boxModel" lsp-css-lint-box-model)
    218    ("css.lint.importStatement" lsp-css-lint-import-statement)
    219    ("css.lint.emptyRules" lsp-css-lint-empty-rules)
    220    ("css.lint.duplicateProperties" lsp-css-lint-duplicate-properties)
    221    ("css.lint.vendorPrefix" lsp-css-lint-vendor-prefix)
    222    ("css.lint.compatibleVendorPrefixes" lsp-css-lint-compatible-vendor-prefixes)
    223    ("css.validate" lsp-css-validate t)
    224    ("css.completion.triggerPropertyValueCompletion" lsp-css-completion-trigger-property-value-completion t)
    225    ("css.experimental.customData" lsp-css-experimental-custom-data)))
    226 
    227 (defun lsp-css--server-command ()
    228   "Generate startup command for CSS language server."
    229   (list (lsp-package-path 'css-languageserver) "--stdio"))
    230 
    231 ;;; CSS
    232 (lsp-defun lsp-css--apply-code-action ((&Command :arguments?))
    233   "Apply ACTION as workspace edit command."
    234   (lsp--apply-text-edits (cl-caddr arguments?) 'code-action))
    235 
    236 (lsp-dependency 'css-languageserver
    237                 '(:system "vscode-css-language-server")
    238                 '(:npm :package "vscode-langservers-extracted"
    239                        :path "vscode-css-language-server"))
    240 
    241 (lsp-register-client
    242  (make-lsp-client
    243   :new-connection (lsp-stdio-connection #'lsp-css--server-command)
    244   :activation-fn (lsp-activate-on "css" "scss" "sass" "less")
    245   :priority -1
    246   :action-handlers (lsp-ht ("_css.applyCodeAction" #'lsp-css--apply-code-action))
    247   :server-id 'css-ls
    248   :download-server-fn (lambda (_client callback error-callback _update?)
    249                         (lsp-package-ensure 'css-languageserver callback error-callback))))
    250 
    251 (lsp-consistency-check lsp-css)
    252 
    253 (provide 'lsp-css)
    254 ;;; lsp-css.el ends here