config

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

lsp-angular.el (3533B)


      1 ;;; lsp-angular.el --- description -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2020 emacs-lsp maintainers
      4 
      5 ;; Author: emacs-lsp maintainers
      6 ;; Keywords: lsp,
      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 Clients for the Angular Web application framework.
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 (require 'f)
     29 
     30 
     31 ;;; Angular
     32 (defgroup lsp-angular nil
     33   "Angular LSP client, provided by the Angular Language Service Server."
     34   :group 'lsp-mode
     35   :version "8.0.0"
     36   :link '(url-link "https://github.com/angular/vscode-ng-language-service"))
     37 
     38 (defcustom lsp-clients-angular-language-server-command
     39   nil
     40   "The command that starts the angular language server."
     41   :group 'lsp-angular
     42   :type '(choice
     43           (string :tag "Single string value")
     44           (repeat :tag "List of string values"
     45                   string)))
     46 
     47 (defcustom lsp-clients-angular-node-get-prefix-command
     48   "npm config get --global prefix"
     49   "The shell command that returns the path of NodeJS's prefix.
     50 Has no effects when `lsp-clients-angular-language-server-command' is set."
     51   :group 'lsp-angular
     52   :type 'string)
     53 
     54 (defun lsp-client--angular-start-loading (_workspace params)
     55   (lsp--info "Started loading project %s" params))
     56 
     57 (defun lsp-client--angular-finished-loading (_workspace params)
     58   (lsp--info "Finished loading project %s" params))
     59 
     60 (lsp-register-client
     61  (make-lsp-client
     62   :new-connection
     63   (lsp-stdio-connection
     64    (lambda ()
     65      (if lsp-clients-angular-language-server-command
     66          lsp-clients-angular-language-server-command
     67        (let ((node-modules-path
     68               (f-join
     69                (string-trim
     70                 (shell-command-to-string lsp-clients-angular-node-get-prefix-command))
     71                (if (eq system-type 'windows-nt)
     72                    "node_modules"
     73                  "lib/node_modules"))))
     74          ;; The shell command takes a significant time to run,
     75          ;; so we "cache" its results after running once
     76          (setq lsp-clients-angular-language-server-command
     77                (list
     78                 "node"
     79                 (f-join node-modules-path "@angular/language-server")
     80                 "--ngProbeLocations"
     81                 node-modules-path
     82                 "--tsProbeLocations"
     83                 node-modules-path
     84                 "--stdio"))
     85          lsp-clients-angular-language-server-command))))
     86   :activation-fn
     87   (lambda (&rest _args)
     88     (and (string-match-p "\\(\\.html\\|\\.ts\\)\\'" (buffer-file-name))
     89          (lsp-workspace-root)
     90          (file-exists-p (f-join (lsp-workspace-root) "angular.json"))))
     91   :priority -1
     92   :notification-handlers
     93   (ht ("angular/projectLoadingStart" #'lsp-client--angular-start-loading)
     94       ("angular/projectLoadingFinish" #'lsp-client--angular-finished-loading)
     95       ("angular/projectLanguageService" #'ignore))
     96   :add-on? t
     97   :server-id 'angular-ls))
     98 
     99 
    100 (lsp-consistency-check lsp-angular)
    101 
    102 (provide 'lsp-angular)
    103 ;;; lsp-angular.el ends here