forked from ztlevi/doom-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
+lsp.el
141 lines (126 loc) · 5.89 KB
/
+lsp.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
;;; +lsp.el -*- lexical-binding: t; -*-
(after! lsp-clangd
(setq lsp-clients-clangd-args '("-j=3"
"--background-index"
"--clang-tidy"
"--completion-style=detailed"
"--header-insertion=never"
"--header-insertion-decorators=0"))
(set-lsp-priority! 'clangd 2)
(after! dap-mode
(require 'dap-codelldb)))
;; Typescript
(setq lsp-clients-typescript-init-opts
'(:importModuleSpecifierPreference "relative"))
;; Java
;; jdtls mirror in China
;; (setq lsp-java-jdt-download-url "http://mirrors.ustc.edu.cn/eclipse/jdtls/milestones/1.1.2/jdt-language-server-1.1.2-202105191944.tar.gz")
;; current VSCode defaults
(setq lsp-java-vmargs '("-XX:+UseParallelGC" "-XX:GCTimeRatio=4" "-XX:AdaptiveSizePolicyWeight=90" "-Dsun.zip.disableMemoryMapping=true" "-Xmx2G" "-Xms100m"))
(after! lsp-java
;; eclipse.jdt.ls needs java 17+
;; Not sure why brew openjdk cannot be recognized by lsp-java, use linux version instead.
;; Install with `sudo yum install java-17-amazon-corretto-devel`
(dolist (java_path `(
"/usr/lib/jvm/java-17-amazon-corretto.x86_64/"
,(string-trim (shell-command-to-string "brew --prefix openjdk@17"))
))
(if (file-directory-p java_path)
(setq lsp-java-configuration-runtimes `[(:name "JavaSE-17"
:path ,java_path
:default t)]
lsp-java-java-path (concat java_path "/bin/java")
dap-java-java-command (concat java_path "/bin/java"))))
)
;; Use format-all by default
(setq +format-with-lsp nil)
(setq +lsp-prompt-to-install-server 'quiet)
(after! lsp-mode
(add-hook! 'lsp-help-mode-hook (visual-line-mode 1))
(setq lsp-log-io nil
lsp-file-watch-threshold 4000
lsp-headerline-breadcrumb-enable t
lsp-headerline-breadcrumb-icons-enable nil
lsp-headerline-breadcrumb-segments '(file symbols)
lsp-imenu-index-symbol-kinds '(File Module Namespace Package Class Method Enum Interface
Function Variable Constant Struct Event Operator TypeParameter)
)
(dolist (dir '("[/\\\\]\\.ccls-cache\\'"
"[/\\\\]\\.mypy_cache\\'"
"[/\\\\]\\.pytest_cache\\'"
"[/\\\\]\\.cache\\'"
"[/\\\\]\\.clwb\\'"
"[/\\\\]\\.env\\'"
"[/\\\\]__pycache__\\'"
"[/\\\\]bazel-bin\\'"
"[/\\\\]bazel-code\\'"
"[/\\\\]bazel-genfiles\\'"
"[/\\\\]bazel-out\\'"
"[/\\\\]bazel-testlogs\\'"
"[/\\\\]third_party\\'"
"[/\\\\]third-party\\'"
"[/\\\\]buildtools\\'"
"[/\\\\]out\\'"
"[/\\\\]build\\'"
))
(push dir lsp-file-watch-ignored-directories))
)
(after! lsp-ui
(setq lsp-ui-doc-enable nil
lsp-lens-enable nil
lsp-ui-sideline-enable nil
lsp-ui-doc-include-signature t
lsp-ui-doc-max-height 15
lsp-ui-doc-max-width 100))
(use-package lsp-docker
:when (not (modulep! :tools lsp +eglot))
:defer t
:commands lsp-docker-init-clients
:config
(defvar lsp-docker-client-packages
'(lsp-css lsp-clients lsp-bash lsp-go lsp-pyls lsp-html lsp-typescript
lsp-terraform lsp-cpp))
(defvar lsp-docker-client-configs
(list
(list :server-id 'bash-ls :docker-server-id 'bashls-docker :server-command "bash-language-server start")
(list :server-id 'clangd :docker-server-id 'clangd-docker :server-command "ccls")
(list :server-id 'css-ls :docker-server-id 'cssls-docker :server-command "css-languageserver --stdio")
(list :server-id 'dockerfile-ls :docker-server-id 'dockerfilels-docker :server-command "docker-langserver --stdio")
(list :server-id 'gopls :docker-server-id 'gopls-docker :server-command "gopls")
(list :server-id 'html-ls :docker-server-id 'htmls-docker :server-command "html-languageserver --stdio")
(list :server-id 'pyls :docker-server-id 'pyls-docker :server-command "pyls")
(list :server-id 'ts-ls :docker-server-id 'tsls-docker :server-command "typescript-language-server --stdio")))
;; (lsp-docker-init-clients
;; :path-mappings `((,(file-truename "~/av") . "/code"))
;; ;; :docker-image-id "my-lsp-docker-container:1.0"
;; :client-packages '(lsp-pyls)
;; :client-configs lsp-docker-client-configs)
)
;; https://github.com/blahgeek/emacs-lsp-booster?tab=readme-ov-file
(defun lsp-booster--advice-json-parse (old-fn &rest args)
"Try to parse bytecode instead of json."
(or
(when (equal (following-char) ?#)
(let ((bytecode (read (current-buffer))))
(when (byte-code-function-p bytecode)
(funcall bytecode))))
(apply old-fn args)))
(advice-add (if (progn (require 'json)
(fboundp 'json-parse-buffer))
'json-parse-buffer
'json-read)
:around
#'lsp-booster--advice-json-parse)
(defun lsp-booster--advice-final-command (old-fn cmd &optional test?)
"Prepend emacs-lsp-booster command to lsp CMD."
(let ((orig-result (funcall old-fn cmd test?)))
(if (and (not test?) ;; for check lsp-server-present?
(not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper
lsp-use-plists
(not (functionp 'json-rpc-connection)) ;; native json-rpc
(executable-find "emacs-lsp-booster"))
(progn
(message "Using emacs-lsp-booster for %s!" orig-result)
(cons "emacs-lsp-booster" orig-result))
orig-result)))
(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)