Skip to content

Commit c3308a8

Browse files
authored
Improve the Angular client (#3042)
* [angular] Improve the client * Speedup the 2nd Angular server connection onwards Set lsp-clients-angular-language-server-command after the first run to avoid the lag introduced by running the shell command. * Make Angular server's NodeJS prefix path configurable. Because sometimes we don't use npm, and maybe there are multiple installed versions of NodeJS, too (nvm, asdf & so on). * Use f-join instead of concat * Clean up for lsp-angular.
1 parent 34d7716 commit c3308a8

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

CHANGELOG.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
* Changelog
22
** Release 7.1
3+
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.
4+
* Set ~lsp-clients-angular-language-server-command~ after the first connection to speed up subsequent connections.
35
* Add ~lsp-sql-execute-paragraph~ to execute the current paragraph (like ~sql-send-paragraph~).
46
* Breaking change: bindings for commands under ~s~ (like ~lsp-workspace-shutdown~) were moved under ~w~ for better compatibility with =Spacemacs=
57
* removed ~lsp-print-performance~

clients/lsp-angular.el

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,54 @@
4444
(repeat :tag "List of string values"
4545
string)))
4646

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+
4754
(defun lsp-client--angular-start-loading (_workspace params)
4855
(lsp--info "Started loading project %s" params))
4956

5057
(defun lsp-client--angular-finished-loading (_workspace params)
5158
(lsp--info "Finished loading project %s" params))
5259

5360
(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))
7795

7896

7997
(lsp-consistency-check lsp-angular)

0 commit comments

Comments
 (0)