|
44 | 44 | (repeat :tag "List of string values"
|
45 | 45 | string)))
|
46 | 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 | + |
47 | 54 | (defun lsp-client--angular-start-loading (_workspace params)
|
48 | 55 | (lsp--info "Started loading project %s" params))
|
49 | 56 |
|
50 | 57 | (defun lsp-client--angular-finished-loading (_workspace params)
|
51 | 58 | (lsp--info "Finished loading project %s" params))
|
52 | 59 |
|
53 | 60 | (lsp-register-client
|
54 |
| - (make-lsp-client :new-connection (lsp-stdio-connection |
55 |
| - (lambda () (if lsp-clients-angular-language-server-command |
56 |
| - lsp-clients-angular-language-server-command |
57 |
| - (let ((node-modules-path |
58 |
| - (concat (string-trim (shell-command-to-string "npm config get --global prefix")) |
59 |
| - "/lib/node_modules"))) |
60 |
| - (list |
61 |
| - "node" |
62 |
| - (concat node-modules-path "/@angular/language-server") |
63 |
| - "--ngProbeLocations" |
64 |
| - node-modules-path |
65 |
| - "--tsProbeLocations" |
66 |
| - node-modules-path |
67 |
| - "--stdio"))))) |
68 |
| - :activation-fn (lambda (&rest _args) |
69 |
| - (and (string-match-p "\\(\\.html\\|\\.ts\\)\\'" (buffer-file-name)) |
70 |
| - (lsp-workspace-root) |
71 |
| - (file-exists-p (f-join (lsp-workspace-root) "angular.json")))) |
72 |
| - :priority -1 |
73 |
| - :notification-handlers (ht ("angular/projectLoadingStart" #'lsp-client--angular-start-loading) |
74 |
| - ("angular/projectLoadingFinish" #'lsp-client--angular-finished-loading)) |
75 |
| - :add-on? t |
76 |
| - :server-id 'angular-ls)) |
| 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 | + "lib/node_modules"))) |
| 72 | + ;; The shell command takes a significant time to run, |
| 73 | + ;; so we "cache" its results after running once |
| 74 | + (setq lsp-clients-angular-language-server-command |
| 75 | + (list |
| 76 | + "node" |
| 77 | + (f-join node-modules-path "@angular/language-server") |
| 78 | + "--ngProbeLocations" |
| 79 | + node-modules-path |
| 80 | + "--tsProbeLocations" |
| 81 | + node-modules-path |
| 82 | + "--stdio")) |
| 83 | + lsp-clients-angular-language-server-command)))) |
| 84 | + :activation-fn |
| 85 | + (lambda (&rest _args) |
| 86 | + (and (string-match-p "\\(\\.html\\|\\.ts\\)\\'" (buffer-file-name)) |
| 87 | + (lsp-workspace-root) |
| 88 | + (file-exists-p (f-join (lsp-workspace-root) "angular.json")))) |
| 89 | + :priority -1 |
| 90 | + :notification-handlers |
| 91 | + (ht ("angular/projectLoadingStart" #'lsp-client--angular-start-loading) |
| 92 | + ("angular/projectLoadingFinish" #'lsp-client--angular-finished-loading)) |
| 93 | + :add-on? t |
| 94 | + :server-id 'angular-ls)) |
77 | 95 |
|
78 | 96 |
|
79 | 97 | (lsp-consistency-check lsp-angular)
|
|
0 commit comments