-
Notifications
You must be signed in to change notification settings - Fork 215
/
lsp-bridge.el
3215 lines (2766 loc) · 140 KB
/
lsp-bridge.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; lsp-bridge.el --- LSP bridge -*- lexical-binding: t -*-
;; Filename: lsp-bridge.el
;; Description: LSP bridge
;; Author: Andy Stewart <[email protected]>
;; Maintainer: Andy Stewart <[email protected]>
;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-06-15 14:10:12
;; Version: 0.5
;; Last-Updated: 2022-10-10 15:23:53 +0800
;; By: Gong Qijian
;; URL: https://github.com/manateelazycat/lsp-bridge
;; Keywords:
;; Compatibility: emacs-version >= 28
;; Package-Requires: ((emacs "28") (markdown-mode "2.6"))
;;
;; Features that might be required by this library:
;;
;; Please check README
;;
;;; This file is NOT part of GNU Emacs
;;; License
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Lsp-Bridge
;;
;;; Installation:
;;
;; Please check README
;;
;;; Customize:
;;
;;
;;
;; All of the above can customize by:
;; M-x customize-group RET lsp-bridge RET
;;
;;; Change log:
;;
;;
;;; Acknowledgements:
;;
;;
;;
;;; TODO
;;
;;
;;
;;; Code:
(require 'cl-lib)
(require 'json)
(require 'map)
(require 'seq)
(require 'subr-x)
(require 'markdown-mode)
(require 'diff)
(defvar acm-library-path (expand-file-name "acm" (if load-file-name
(file-name-directory load-file-name)
default-directory)))
(add-to-list 'load-path acm-library-path t)
(require 'acm-frame)
(require 'lsp-bridge-epc)
(require 'lsp-bridge-ref)
(require 'lsp-bridge-jdtls)
(require 'lsp-bridge-peek)
(require 'lsp-bridge-call-hierarchy)
(require 'lsp-bridge-code-action)
(require 'lsp-bridge-diagnostic)
(require 'lsp-bridge-lsp-installer)
(require 'lsp-bridge-org-babel)
(require 'lsp-bridge-inlay-hint)
(require 'lsp-bridge-dart)
(require 'lsp-bridge-semantic-tokens)
(require 'lsp-bridge-rust)
(defgroup lsp-bridge nil
"LSP-Bridge group."
:group 'applications)
(require 'acm)
(require 'tramp)
(defvar lsp-bridge-tramp-alias-alist nil)
(defvar lsp-bridge-tramp-connection-info nil)
(setq acm-backend-lsp-fetch-completion-item-func 'lsp-bridge-fetch-completion-item-info)
(defun lsp-bridge-fetch-completion-item-info (candidate)
(let ((kind (plist-get candidate :icon))
(server-name (plist-get candidate :server))
(key (plist-get candidate :key)))
;; Try send `completionItem/resolve' request to fetch `documentation' and `additionalTextEdits' information.
(unless (equal acm-backend-lsp-fetch-completion-item-ticker (list acm-backend-lsp-filepath key kind))
(if (lsp-bridge-is-remote-file)
(lsp-bridge-remote-send-func-request "fetch_completion_item_info" (list acm-backend-lsp-filepath key server-name))
(lsp-bridge-call-async "fetch_completion_item_info" acm-backend-lsp-filepath key server-name))
(setq-local acm-backend-lsp-fetch-completion-item-ticker (list acm-backend-lsp-filepath key kind)))))
(defcustom lsp-bridge-completion-popup-predicates '(
lsp-bridge--not-delete-command
lsp-bridge--not-follow-complete
lsp-bridge--not-match-stop-commands
lsp-bridge--not-match-hide-characters
lsp-bridge--not-match-hide-keywords
lsp-bridge--not-only-blank-before-cursor
lsp-bridge--not-in-string
lsp-bridge--not-in-org-table
lsp-bridge--not-execute-macro
lsp-bridge--not-in-multiple-cursors
lsp-bridge--not-in-mark-macro
lsp-bridge--is-evil-state
lsp-bridge--is-meow-state
lsp-brige--not-in-chatgpt-response
lsp-bridge--not-complete-manually
)
"A list of predicate functions with no argument to enable popup completion in callback."
:type '(repeat function)
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-predicates '(
lsp-bridge--not-acm-doc-markdown-buffer
lsp-bridge--not-mind-wave-chat-buffer
lsp-bridge--not-zsh-buffer
)
"A list of predicate functions with no argument to enable lsp-bridge in `lsp-bridge-default-mode-hooks'."
:type '(repeat function)
:group 'lsp-bridge)
(defcustom lsp-bridge-flash-region-delay .3
"How many seconds to flash `lsp-bridge-font-lock-flash' after navigation.
Setting this to nil or 0 will turn off the indicator."
:type 'number
:group 'lsp-bridge)
(defcustom lsp-bridge-remote-heartbeat-interval nil
"Interval for sending heartbeat to server in seconds.
Setting this to nil or 0 will turn off the heartbeat mechanism."
:type 'number
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-mode-line t
"Whether display LSP-bridge's server info in mode-line ."
:type 'boolean
:group 'lsp-bridge)
(defcustom lsp-bridge-completion-stop-commands
'("undo-tree-undo" "undo-tree-redo"
"undo-tree-visualize-redo" "undo-tree-visualize-undo"
"kill-region" "delete-block-backward"
"python-black-buffer" "acm-complete-or-expand-yas-snippet" "acm-insert-number-or-complete-candiate"
"yank" "string-rectangle" "query-replace" "grammatical-edit-unwrap")
"If last command is match this option, stop popup completion ui."
:type '(repeat string)
:safe #'listp
:group 'lsp-bridge)
(defcustom lsp-bridge-completion-hide-characters '(":" ";" "(" ")" "[" "]" "{" "}" "," "\"" ">")
"If character before match this option, stop popup completion ui.
To make this option works, you need set option `lsp-bridge-completion-obey-trigger-characters-p' with nil first.
After set `lsp-bridge-completion-obey-trigger-characters-p' to nil, you need use `setq' set this value, don't use `custom-set-variables'."
:type '(repeat string)
:safe #'listp
:group 'lsp-bridge)
(defcustom lsp-bridge-completion-obey-trigger-characters-p t
"If non-nil makes trigger characters a higher priority than `lsp-bridge-completion-hide-characters'."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-popup-documentation-buffer " *lsp-bridge-hover*"
"Buffer for display hover information."
:type 'string
:safe #'stringp
:group 'lsp-bridge)
(defcustom lsp-bridge-buffer-documentation-buffer "*lsp-bridge-doc*"
"Buffer for display documentation information."
:type 'string
:safe #'stringp
:group 'lsp-bridge)
(defcustom lsp-bridge-disable-backup t
"Default disable backup feature, include `make-backup-files' `auto-save-default' and `create-lockfiles'."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-signature-help t
"Whether to enable signature-help."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-signature-help-fetch-idle 0.5
"The idle seconds to fetch signature help.."
:type 'float
:safe #'floatp
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-search-words t
"Whether to enable search words of files."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-search-words-prohibit-file-extensions '("png" "jpg" "jpeg" "gif" "pdf")
"The file extensions to prohibit search words."
:type '(repeat string)
:safe #'listp
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-auto-format-code nil
"Whether to auto format code."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-auto-format-code-idle 1
"The idle seconds to auto format code."
:type 'float
:safe #'floatp
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-diagnostics t
"Whether to enable diagnostics."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-elisp-symbols-update-idle 3
"The idle seconds to update elisp symbols."
:type 'float
:safe #'floatp
:group 'lsp-bridge)
(defcustom lsp-bridge-user-langserver-dir nil
"The directory where the user place langserver configuration."
:type '(choice (const nil)
(string))
:safe (lambda (v) (or (null v) (stringp v)))
:group 'lsp-bridge)
(defcustom lsp-bridge-user-multiserver-dir nil
"The directory where the user place multiserver configuration."
:type '(choice (const nil)
(string))
:safe (lambda (v) (or (null v) (stringp v)))
:group 'lsp-bridge)
(defcustom lsp-bridge-user-ssh-private-key nil
"custom SSH private key path for use in SSH connections."
:type '(choice (const nil)
(string))
:safe (lambda (v) (or (null v) (stringp v)))
:group 'lsp-bridge)
(defcustom lsp-bridge-symbols-enable-which-func nil
"Wether use lsp-bridge in which-func."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-enable-completion-in-string nil
"Whether to enable completion in string, default is disable."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defcustom lsp-bridge-completion-in-string-file-types '("vue" "dart")
"File types where completion in string is allowed.
This is a list of file extensions for which
LSP-Bridge will enable completion inside string literals."
:type '(repeat string)
:group 'lsp-bridge)
(defface lsp-bridge-font-lock-flash
'((t (:inherit highlight)))
"Face to flash the current line."
:group 'lsp-bridge)
(defcustom lsp-bridge-tramp-blacklist nil
"tramp hosts that don't use lsp-bridge"
:type '(repeat string)
:safe #'listp
:group 'lsp-bridge)
(defcustom lsp-bridge-remote-python-command "python3"
"Python command on remote host."
:type 'string
:safe #'stringp
:group 'lsp-bridge)
(defcustom lsp-bridge-remote-python-file "~/lsp-bridge/lsp_bridge.py"
"Full path of lsp_bridge.py file on remote host."
:type 'string
:safe #'stringp
:group 'lsp-bridge)
(defcustom lsp-bridge-remote-log "~/lsp-bridge/lbr_log.txt"
"Full path of log file on remote host."
:type 'string
:safe #'stringp
:group 'lsp-bridge)
(defcustom lsp-bridge-remote-start-automatically nil
"Whether start remote lsp-bridge.py automatically."
:type 'boolean
:safe #'booleanp
:group 'lsp-bridge)
(defvar lsp-bridge-last-change-command nil)
(defvar lsp-bridge-last-change-position nil)
(defvar lsp-bridge-last-change-is-delete-command-p nil)
(defvar lsp-bridge-server nil
"The LSP-Bridge Server.")
(defvar lsp-bridge-python-file (expand-file-name "lsp_bridge.py" (if load-file-name
(file-name-directory load-file-name)
default-directory)))
(defvar-local lsp-bridge-mark-ring nil
"The list of saved lsp-bridge marks, most recent first.")
(defvar lsp-bridge-server-port nil)
(defun lsp-bridge--start-epc-server ()
"Function to start the EPC server."
(unless (process-live-p lsp-bridge-server)
(setq lsp-bridge-server
(lsp-bridge-epc-server-start
(lambda (mngr)
(let ((mngr mngr))
(lsp-bridge-epc-define-method mngr 'eval-in-emacs 'lsp-bridge--eval-in-emacs-func)
(lsp-bridge-epc-define-method mngr 'get-emacs-vars 'lsp-bridge--get-emacs-vars-func)
(lsp-bridge-epc-define-method mngr 'get-project-path 'lsp-bridge--get-project-path-func)
(lsp-bridge-epc-define-method mngr 'get-language-id 'lsp-bridge--get-language-id-func)
(lsp-bridge-epc-define-method mngr 'get-workspace-folder 'lsp-bridge--get-workspace-folder-func)
(lsp-bridge-epc-define-method mngr 'get-multi-lang-server 'lsp-bridge--get-multi-lang-server-func)
(lsp-bridge-epc-define-method mngr 'get-single-lang-server 'lsp-bridge--get-single-lang-server-func)
(lsp-bridge-epc-define-method mngr 'get-user-emacs-directory 'lsp-bridge--user-emacs-directory-func)
(lsp-bridge-epc-define-method mngr 'get-user-tsdk-path 'lsp-bridge--user-tsdk-path-func)
(lsp-bridge-epc-define-method mngr 'get-buffer-content 'lsp-bridge--get-buffer-content-func)
(lsp-bridge-epc-define-method mngr 'get-current-line 'lsp-bridge--get-current-line-func)
(lsp-bridge-epc-define-method mngr 'get-ssh-password 'lsp-bridge--get-ssh-password-func)
))))
(if lsp-bridge-server
(setq lsp-bridge-server-port (process-contact lsp-bridge-server :service))
(error "[LSP-Bridge] lsp-bridge-server failed to start")))
lsp-bridge-server)
(defun lsp-bridge--eval-in-emacs-func (sexp-string)
(eval (read sexp-string))
;; Return nil to avoid epc error `Got too many arguments in the reply'.
nil)
(defun lsp-bridge--get-emacs-var-func (var-name)
(let* ((var-symbol (intern var-name))
(var-value (symbol-value var-symbol))
;; We need convert result of booleanp to string.
;; Otherwise, python-epc will convert all `nil' to [] at Python side.
(var-is-bool (prin1-to-string (booleanp var-value))))
(list var-value var-is-bool)))
(defun lsp-bridge--get-emacs-vars-func (&rest vars)
(mapcar #'lsp-bridge--get-emacs-var-func vars))
(defvar lsp-bridge-epc-process nil)
(defvar lsp-bridge-internal-process nil)
(defvar lsp-bridge-internal-process-prog nil)
(defvar lsp-bridge-internal-process-args nil)
(defvar lsp-bridge-position-before-jump nil)
(defcustom lsp-bridge-name "*lsp-bridge*"
"Name of LSP-Bridge buffer."
:type 'string)
(defcustom lsp-bridge-python-command (cond ((memq system-type '(cygwin windows-nt ms-dos))
(cond ((executable-find "pypy3.exe")
"pypy3.exe")
((executable-find "python3.exe")
"python3.exe")
((executable-find "python.exe")
"python.exe")))
(t (cond ((executable-find "pypy3")
"pypy3")
((executable-find "python3")
"python3")
((executable-find "python")
"python"))))
"The Python interpreter used to run lsp_bridge.py."
:type 'string)
(defcustom lsp-bridge-enable-debug nil
"If you got segfault error, please turn this option.
Then LSP-Bridge will start by gdb, please send new issue with `*lsp-bridge*' buffer content when next crash."
:type 'boolean)
(defcustom lsp-bridge-enable-log nil
"Enable this option to print log message in `*lsp-bridge*' buffer, default only print message header."
:type 'boolean)
(defcustom lsp-bridge-enable-profile nil
"Enable this option to output performance data to ~/lsp-bridge.prof."
:type 'boolean)
(defcustom lsp-bridge-enable-completion-in-minibuffer nil
"Enable this option to completion in minibuffer."
:type 'boolean)
(defcustom lsp-bridge-multi-lang-server-extension-list
'(
(("vue") . "volar_emmet")
(("ts") . "typescript_eslint")
(("tsx") . "typescriptreact_eslint")
)
"The multi lang server rule for file extension."
:type 'cons)
(defcustom lsp-bridge-single-lang-server-extension-list
'(
(("wxml") . "wxml-language-server")
(("html") . "vscode-html-language-server")
(("astro") . "astro-ls")
(("typ") . "tinymist")
)
"The lang server rule for file extension."
:type 'cons)
(defcustom lsp-bridge-c-lsp-server "clangd"
"Default LSP server for C language, you can choose `clangd' or `ccls'."
:type 'string)
(defcustom lsp-bridge-elixir-lsp-server "elixirLS"
"Default LSP server for Elixir language, you can choose `elixirLS', `lexical' or `nextls'."
:type 'string
:safe #'stringp)
(defcustom lsp-bridge-php-lsp-server "intelephense"
"Default LSP server for PHP language, you can choose `intelephense' or `phpactor'."
:type 'string
:safe #'stringp)
(defcustom lsp-bridge-python-lsp-server "basedpyright"
"Default LSP server for Python.
Possible choices are basedpyright, pyright, pyright-background-analysis, jedi, python-ms, pylsp, and ruff."
:type 'string)
(defcustom lsp-bridge-python-multi-lsp-server "basedpyright_ruff"
"Default Multi LSP server for Python.
Possible choices are basedpyright_ruff, pyright_ruff, pyright-background-analysis_ruff, jedi_ruff, python-ms_ruff, and pylsp_ruff."
:type 'string)
(defcustom lsp-bridge-tex-lsp-server "texlab"
"Default LSP server for (la)tex, you can choose `texlab', `digestif' or `ltex-ls'."
:type 'string)
(defcustom lsp-bridge-csharp-lsp-server "omnisharp-dotnet"
"Default LSP server for C#, you can choose `omnisharp-mono', `omnisharp-dotnet' or `csharp-ls'."
:type 'string)
(defcustom lsp-bridge-nix-lsp-server "nixd"
"Default LSP server for nix, you can choose `nixd' `rnix-lsp' or `nil'."
:type 'string)
(defcustom lsp-bridge-markdown-lsp-server "vale-ls"
"Default LSP server for markdown, you can choose `vale-ls' or `marksman'."
:type 'string)
(defcustom lsp-bridge-lua-lsp-server "sumneko"
"Default LSP server for Lua, you can choose `sumneko' or `lua-lsp'"
:type 'string)
(defcustom lsp-bridge-verilog-lsp-server "verible"
"Default LSP server for Verilog, you can choose `verible', `svls'"
:type 'string)
(defcustom lsp-bridge-xml-lsp-server "lemminx"
"Default LSP server for XML, you can choose `lemminx', `camells'"
:type 'string)
(defcustom lsp-bridge-tsdk-path nil
"Tsserver lib*.d.ts directory path in current system needed by some lsp servers.
If nil, lsp-bridge would try to detect by default."
:type '(choice (const nil)
(string)))
(defcustom lsp-bridge-use-wenls-in-org-mode nil
"Use `wen' lsp server in org-mode, default is disable.")
(defcustom lsp-bridge-use-ds-pinyin-in-org-mode nil
"Use `ds-pinyin' lsp server in org-mode, default is disable.")
(defcustom lsp-bridge-complete-manually nil
"Only popup completion menu when user call `lsp-bridge-popup-complete-menu' command.")
(defcustom lsp-bridge-multi-lang-server-mode-list
'(((python-mode python-ts-mode) . lsp-bridge-python-multi-lsp-server)
((qml-mode qml-ts-mode) . "qmlls_javascript"))
"The multi lang server rule for file mode."
:type 'cons)
(defcustom lsp-bridge-single-lang-server-mode-list
'(
((c-mode c-ts-mode c++-mode c++-ts-mode objc-mode c-or-c++-ts-mode) . lsp-bridge-c-lsp-server)
((cmake-mode cmake-ts-mode) . "cmake-language-server")
((java-mode java-ts-mode) . "jdtls")
((julia-mode) . "julials")
((python-mode python-ts-mode) . lsp-bridge-python-lsp-server)
((ruby-mode ruby-ts-mode) . "solargraph")
((rust-mode rustic-mode rust-ts-mode) . "rust-analyzer")
(move-mode . "move-analyzer")
((elixir-mode elixir-ts-mode heex-ts-mode) . lsp-bridge-elixir-lsp-server)
((go-mode go-ts-mode) . "gopls")
(groovy-mode . "groovy-language-server")
(haskell-mode . "hls")
(lua-mode . lsp-bridge-lua-lsp-server)
(markdown-mode . lsp-bridge-markdown-lsp-server)
(dart-mode . "dart-analysis-server")
(scala-mode . "metals")
((js2-mode js-mode js-ts-mode rjsx-mode) . "javascript")
(js-jsx-mode . "javascriptreact")
((typescript-tsx-mode tsx-ts-mode) . "typescriptreact")
((typescript-mode typescript-ts-mode) . "typescript")
((js-json-mode json-ts-mode json-mode) . "vscode-json-language-server")
(tuareg-mode . "ocamllsp")
(erlang-mode . "erlang-ls")
((LaTeX-mode latex-mode Tex-latex-mode texmode context-mode texinfo-mode bibtex-mode) . lsp-bridge-tex-lsp-server)
((clojure-mode
clojurec-mode
clojurescript-mode
clojurex-mode
clojure-ts-mode
clojure-ts-clojurec-mode
clojure-ts-clojurescript-mode
clojure-ts-clojuredart-mode) . "clojure-lsp")
((sh-mode bash-mode bash-ts-mode) . "bash-language-server")
((css-mode css-ts-mode) . "vscode-css-language-server")
(elm-mode . "elm-language-server")
((php-mode php-ts-mode) . lsp-bridge-php-lsp-server)
((yaml-mode yaml-ts-mode) . "yaml-language-server")
(zig-mode . "zls")
((dockerfile-mode dockerfile-ts-mode) . "docker-langserver")
(d-mode . "serve-d")
((fortran-mode f90-mode) . "fortls")
((nix-mode nix-ts-mode) . lsp-bridge-nix-lsp-server)
(nickel-mode . "nls")
(ess-r-mode . "rlanguageserver")
((graphql-mode graphql-ts-mode) . "graphql-lsp")
(swift-mode . "swift-sourcekit")
((csharp-mode csharp-ts-mode) . lsp-bridge-csharp-lsp-server)
(kotlin-mode . "kotlin-language-server")
(verilog-mode . lsp-bridge-verilog-lsp-server)
(vhdl-mode . "vhdl-tool")
(svelte-mode . "svelteserver")
(fsharp-mode . "fsautocomplete")
(beancount-mode . "beancount-language-server")
(racket-mode . "racket-langserver")
(mojo-mode . "mojo-lsp-server")
(solidity-mode . "solidity")
(gleam-ts-mode . "gleam")
(ada-mode . "ada-language-server")
(scad-mode . "openscad-lsp")
(sml-mode . "millet")
(fuzion-mode . "fuzion-language-server")
(fennel-mode . "fennel-ls")
(ttcn3-mode . "ntt")
(v-mode . "v-analyzer")
(cwl-mode . "benten")
(odin-mode . "ols")
(ballerina-mode . "ballerina-lang-server")
(bibtex-mode . "citation-langserver")
(feature-mode . "cucumber-language-server")
(rego-mode . "regal")
(puppet-mode . "puppet-languageserver")
(nxml-mode . lsp-bridge-xml-lsp-server)
(robot-mode . "vscode-rf-language-server")
(vimrc-mode . "vim-language-server")
(terraform-mode . "terraform-ls")
(jsonnet-mode . "jsonnet-language-server")
(glsl-mode . "glsl-language-server")
(cobol-mode . "che-che4z-lsp-for-cobol")
(hlasm-mode . "che-che4z-lsp-for-hlasm")
(yang-mode . "yang-lsp")
(mint-mode . "mint-ls")
(purescript-mode . "purescript-language-server")
(perl-mode . "perl-language-server")
(futhark-mode . "futhark-lsp")
)
"The lang server rule for file mode."
:type 'cons)
(defcustom lsp-bridge-default-mode-hooks
'(c-mode-hook
c++-mode-hook
cmake-mode-hook
java-mode-hook
julia-mode-hook
python-mode-hook
ruby-mode-hook
ruby-ts-mode-hook
lua-mode-hook
move-mode-hook
rust-mode-hook
markdown-mode-hook
rust-ts-mode-hook
rustic-mode-hook
erlang-mode-hook
elixir-mode-hook
go-mode-hook
haskell-mode-hook
haskell-literate-mode-hook
dart-mode-hook
scala-mode-hook
typescript-mode-hook
typescript-tsx-mode-hook
js2-mode-hook
js-mode-hook
rjsx-mode-hook
tuareg-mode-hook
latex-mode-hook
LaTeX-mode-hook
Tex-latex-mode-hook
texmode-hook
context-mode-hook
texinfo-mode-hook
bibtex-mode-hook
clojure-mode-hook
clojurec-mode-hook
clojurescript-mode-hook
clojurex-mode-hook
clojure-ts-mode-hook
clojurec-ts-mode-hook
clojurescript-ts-mode-hook
clojure-dart-ts-mode-hook
sh-mode-hook
bash-mode-hook
web-mode-hook
css-mode-hook
elm-mode-hook
emacs-lisp-mode-hook
ielm-mode-hook
lisp-interaction-mode-hook
org-mode-hook
php-mode-hook
php-ts-mode-hook
yaml-mode-hook
zig-mode-hook
groovy-mode-hook
dockerfile-mode-hook
dockerfile-ts-mode-hook
d-mode-hook
f90-mode-hook
fortran-mode-hook
nix-mode-hook
nix-ts-mode-hook
nickel-mode-hook
ess-r-mode-hook
verilog-mode-hook
swift-mode-hook
csharp-mode-hook
csharp-ts-mode-hook
telega-chat-mode-hook
markdown-mode-hook
kotlin-mode-hook
vhdl-mode-hook
typst-mode-hook
typst-ts-mode-hook
graphql-mode-hook
graphql-ts-mode-hook
c-ts-mode-hook
c++-ts-mode-hook
cmake-ts-mode-hook
elixir-ts-mode-hook
toml-ts-mode-hook
css-ts-mode-hook
java-ts-mode-hook
js-ts-mode-hook
json-ts-mode-hook
python-ts-mode-hook
bash-ts-mode-hook
typescript-ts-mode-hook
tsx-ts-mode-hook
go-ts-mode-hook
yaml-ts-mode-hook
svelte-mode-hook
fsharp-mode-hook
beancount-mode-hook
mojo-mode-hook
solidity-mode-hook
gleam-ts-mode-hook
ada-mode-hook
scad-mode-hook
sml-mode-hook
fuzion-mode-hook
fennel-mode-hook
ttcn3-mode-hook
v-mode-hook
cwl-mode-hook
odin-mode-hook
ballerina-mode-hook
bibtex-mode-hook
feature-mode-hook
rego-mode-hook
puppet-mode-hook
nxml-mode-hook
robot-mode-hook
vimrc-mode-hook
terraform-mode-hook
jsonnet-mode-hook
glsl-mode-hook
cobol-mode-hook
hlasm-mode-hook
yang-mode-hook
mint-mode-hook
purescript-mode-hook
perl-mode-hook
futhark-mode-hook
)
"The default mode hook to enable lsp-bridge."
:type '(repeat variable))
(defcustom lsp-bridge-get-single-lang-server-by-project nil
"Get lang server with project path and file path.")
(defcustom lsp-bridge-get-multi-lang-server-by-project nil
"Get lang server with project path and file path.")
(defcustom lsp-bridge-get-language-id nil
"Function to get language id for multi-server.
Some LSP server like emmet-ls or tailwindcss need to get language id dynamicly according to different framework and project.
When server start, lsp-bridge would call this function to get returned string value as languageId.
If this customize function return nil, lsp-bridge will parse languageId from file langserver/*.json.")
(defcustom lsp-bridge-get-project-path-by-filepath nil
"Default use command 'git rev-parse --show-toplevel' get project path,
you can customize `lsp-bridge-get-project-path-by-filepath' to return project path by give file path.")
(defcustom lsp-bridge-get-workspace-folder nil
"In Java, sometimes, we need return same workspace folder for multiple projects,
you can customize `lsp-bridge-get-workspace-folder' to return workspace folder path by give project path.")
(defvar lsp-bridge-indent-two-level 2)
(defvar lsp-bridge-indent-four-level 4)
(defvar lsp-bridge-indent-eight-level 8)
(defvar lsp-bridge-formatting-indent-alist
'((c-mode . c-basic-offset) ; C
(c-ts-mode . c-basic-offset) ; C
(c++-mode . c-basic-offset) ; C++
(markdown-mode . c-basic-offset) ; Markdown.
(csharp-mode . c-basic-offset) ; C#
(csharp-ts-mode . csharp-ts-mode-indent-offset) ; C#
(d-mode . c-basic-offset) ; D
(julia-mode . c-basic-offset) ; Julia
(java-mode . c-basic-offset) ; Java
(java-ts-mode . java-ts-mode-indent-offset) ; Java
(jde-mode . c-basic-offset) ; Java (JDE)
(js-mode . js-indent-level) ; JavaScript
(js2-mode . js2-basic-offset) ; JavaScript-IDE
(js3-mode . js3-indent-level) ; JavaScript-IDE
(json-mode . js-indent-level) ; JSON
(json-ts-mode . js-indent-level) ; JSON
(lua-mode . lua-indent-level) ; Lua
(objc-mode . c-basic-offset) ; Objective C
(php-mode . c-basic-offset) ; PHP
(php-ts-mode . php-ts-mode-indent-offset) ; PHP
(perl-mode . perl-indent-level) ; Perl
(cperl-mode . cperl-indent-level) ; Perl
(raku-mode . raku-indent-offset) ; Perl6/Raku
(erlang-mode . erlang-indent-level) ; Erlang
(ada-mode . ada-indent) ; Ada
(scad-mode . lsp-bridge-indent-two-level) ; OpenSCAD
(sml-mode . sml-indent-level) ; Standard ML
(fuzion-mode . lsp-bridge-indent-two-level) ; Fuzion
(fennel-mode . lsp-bridge-indent-two-level) ; Fennel
(ttcn3-mode . lsp-bridge-indent-four-level) ; TTCN3
(v-mode . lsp-bridge-indent-four-level) ; V
(cwl-mode . lsp-bridge-indent-four-level) ; Common Workflow
(odin-mode . lsp-bridge-indent-eight-level) ; Odin
(ballerina-mode . ballerina-indent-offset) ; Ballerina
(bibtex-mode . lsp-bridge-indent-two-level) ; BibTex
(feature-mode . feature-indent-level) ; Cucumber
(rego-mode . lsp-bridge-indent-two-level) ; Rego
(puppet-mode . puppet-indent-level) ; Puppet
(nxml-mode . lsp-bridge-indent-two-level) ; XML
(robot-mode . robot-mode-basic-offset) ; Robot
(vimrc-mode . lsp-bridge-indent-four-level) ; Vim
(terraform-mode . terraform-indent-level) ; Terraform
(jsonnet-mode . jsonnet-indent-level) ; Jsonnet
(glsl-mode . lsp-bridge-indent-two-level) ; GLSL
(cobol-mode . lsp-bridge-indent-four-level) ; Cobol
(hlasm-mode . lsp-bridge-indent-eight-level) ; HLASM
(yang-mode . lsp-bridge-indent-two-level) ; Yang
(mint-mode . lsp-bridge-indent-two-level) ; Mint
(purescript-mode . purescript-indent-offset) ; PureScript
(futhark-mode . futhark-indent-level) ; Futhark
(sgml-mode . sgml-basic-offset) ; SGML
(nxml-mode . nxml-child-indent) ; XML
(nickel-mode . c-basic-offset)
(nix-ts-mode . nix-ts-mode-indent-offset) ; Nix
(pascal-mode . pascal-indent-level) ; Pascal
(typescript-mode . typescript-indent-level) ; Typescript
(typescript-ts-mode . typescript-ts-mode-indent-offset) ; Typescript
(tsx-ts-mode . typescript-ts-mode-indent-offset) ; Typescript[TSX]
(sh-mode . sh-basic-offset) ; Shell Script
(ruby-mode . ruby-indent-level) ; Ruby
(ruby-ts-mode . ruby-indent-level) ; Ruby
(enh-ruby-mode . enh-ruby-indent-level) ; Ruby
(crystal-mode . crystal-indent-level) ; Crystal (Ruby)
(css-mode . css-indent-offset) ; CSS
(move-mode . move-indent-offset) ; Move
(rust-mode . rust-indent-offset) ; Rust
(rust-ts-mode . rust-ts-mode-indent-offset) ; Rust
(rustic-mode . rustic-indent-offset) ; Rust
(scala-mode . scala-indent:step) ; Scala
(powershell-mode . powershell-indent) ; PowerShell
(ess-mode . ess-indent-offset) ; ESS (R)
(yaml-mode . yaml-indent-offset) ; YAML
(hack-mode . hack-indent-offset) ; Hack
(kotlin-mode . c-basic-offset) ; Kotlin
(verilog-mode . verilog-indent-level) ; Verilog
(vhdl-mode . vhdl-basic-offset) ; VHDL
(go-mode . c-basic-offset) ;Golang
(go-ts-mode . c-basic-offset) ;Golang
(svelte-mode . js-indent-level) ;Svelte
(fsharp-mode . fsharp-indent-offset) ; F#
(gleam-ts-mode . gleam-ts-indent-offset) ; Gleam
(default . standard-indent)) ; default fallback
"A mapping from `major-mode' to its indent variable.")
(defcustom lsp-bridge-string-interpolation-open-chars-alist
'(;; For {}
(python-mode . "[^\$]\{")
(python-ts-mode . "[^\$]\{")
;; For ${}
(js-mode . "\$\{")
(js-ts-mode . "\$\{")
(js2-mode . "\$\{")
(js3-mode . "\$\{")
(typescript-mode . "\$\{")
(typescript-ts-mode . "\$\{")
(sh-mode . "\$\{")
(bash-mode . "\$\{")
(bash-ts-mode . "\$\{")
(typst-ts-mode . "\$\{")
(typst--base-mode . "\$\{")
(typst--code-mode . "\$\{")
(typst--math-mode . "\$\{")
(typst--markup-mode . "\$\{")
;; For #{}
(elixir-mode . "\#\{")
(elixir-ts-mode . "\#\{")
(ruby-mode . "\#\{")
(ruby-ts-mode . "\#\{")
;; For {{}}
(yaml-mode . "\{\{"))
"Open characters for string interpolation. The elements are cons cell (major-mode . open-char-regexp)"
:type 'cons)
(defvar lsp-bridge-enable-with-tramp t
"Whether enable lsp-bridge when editing tramp file.")
(defvar lsp-bridge-remote-save-password nil
"Whether save password in netrc file.")
(defun lsp-bridge-find-file-hook-function ()
(when (and lsp-bridge-enable-with-tramp (file-remote-p (buffer-file-name)))
(lsp-bridge-sync-tramp-remote nil)))
(defun lsp-bridge--setup-tramp-docker-buffer (tramp-file-name)
"Setup the buffer of TRAMP-FILE-NAME as if it is a non-file buffer."
(with-current-buffer (get-file-buffer tramp-file-name)
(setq buffer-file-name nil)
(setq buffer-file-truename nil)
(message "set buffer %s buffer-file-name to nil" (buffer-name))))
(add-hook 'find-file-hook #'lsp-bridge-find-file-hook-function)
(defun lsp-bridge--get-indent-width (mode)
"Get indentation offset for MODE."
(or (alist-get mode lsp-bridge-formatting-indent-alist)
(lsp-bridge--get-indent-width (or (get mode 'derived-mode-parent) 'default))))
(cl-defmacro lsp-bridge--with-file-buffer (filename filehost &rest body)
"Evaluate BODY in buffer with FILEPATH."
(declare (indent 1))
`(when-let* ((buffer (pcase ,filehost
("" (lsp-bridge-get-match-buffer-by-filepath ,filename))
(_ (lsp-bridge-get-match-buffer-by-remote-file ,filehost ,filename)))))
(with-current-buffer buffer
,@body)))
(cl-defmacro lsp-bridge-save-position (&rest body)
"`save-excursion' not enough for LSP code format.
So we build this macro to restore postion after code format."
`(let* ((current-buf (current-buffer))
(current-line (line-number-at-pos nil t))
(current-column (lsp-bridge--calculate-column))
(indent-column (save-excursion
(back-to-indentation)
(lsp-bridge--calculate-column))))
,@body
(switch-to-buffer current-buf)
(goto-line current-line)
(back-to-indentation)
(forward-char (max (- current-column indent-column) 0))))
(defun lsp-bridge-is-remote-file ()
(and (boundp 'lsp-bridge-remote-file-flag)
lsp-bridge-remote-file-flag))
(defun lsp-bridge-get-buffer-file-name-text ()
(lsp-bridge-buffer-file-name buffer-file-name))
(defun lsp-bridge-buffer-file-name (name)
;; `buffer-file-name' may contain face property, we need use `substring-no-properties' remove those face from buffer name.
(when (stringp name)
(substring-no-properties name)))
(defun lsp-bridge-get-buffer-truename (&optional filename)
(if (lsp-bridge-is-remote-file)
lsp-bridge-remote-file-path
(let ((name (or filename
(lsp-bridge-get-buffer-file-name-text))))
(when name
(file-truename name)))))
(defun lsp-bridge-get-match-buffer-by-remote-file (host path)
(cl-dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (and (boundp 'lsp-bridge-remote-file-path)
(lsp-bridge-path-equal lsp-bridge-remote-file-path path)
(boundp 'lsp-bridge-remote-file-host)
(or (string-equal lsp-bridge-remote-file-host host)
;; host is "127.0.0.1" sent from get_lsp_file_host() when server running inside container
;; client connect to lsp bridge server from local host
(string-equal "127.0.0.1" host)))
(cl-return buffer)))))
(defun lsp-bridge-get-match-buffer-by-filepath (name)
(cl-dolist (buffer (buffer-list))
(with-current-buffer buffer
(when-let* ((file-name (buffer-file-name buffer))
(match-buffer (or (lsp-bridge-path-equal file-name name)
(lsp-bridge-path-equal (file-truename file-name) name))))
(cl-return buffer)))))
(defun lsp-bridge-path-equal (path-a path-b)
(cond ((memq system-type '(cygwin windows-nt ms-dos))
(string-equal (downcase path-a) (downcase path-b)))
(t (string-equal path-a path-b))))
(defun lsp-bridge--get-project-path-func (filename)
"Get project root path, search order:
1. Follow the rule of `lsp-bridge-get-project-path-by-filepath'
2. Search up `.dir-locals.el'
3. Search up `.git'"
(if lsp-bridge-get-project-path-by-filepath
;; Fetch project root path by `lsp-bridge-get-project-path-by-filepath' if it set by user.