我尝试设置这样通过initializationOption关闭autobuild选项, 但每次保存java文件的时候仍然会自动编译生成target目录.
(defun my/eglot-setup ()
(message "execute my/eglot-setup")
(define-key eglot-mode-map (kbd "C-c C-t") 'my/pop-documentation-at-point)
(define-key eglot-mode-map (kbd "C-g") #'my/keyboard-quit)
(add-to-list 'eglot-server-programs '((c++-mode c-mode) "clangd"))
(add-to-list 'eglot-server-programs '(latex-mode "texlab"))
(add-to-list
'eglot-server-programs
`(java-mode . ("jdtls"
:initializationOptions (:settings
(:java
(:autobuild (:enabled :json-false)
)))))))
jdtls有关initialize request的文档: Running the JAVA LS server from the command line · eclipse-jdtls/eclipse.jdt.ls Wiki · GitHub
eglot有关initializationOption文档: Eglot: The Emacs Client for the Language Server Protocol
帮帮弟弟🙏
(setq-local eglot-workspace-configuration
'((:java :autobuild (:enabled :json-false))))
jdtls这玩意儿就没想过给vscode以外的东西用。这是我看别人在jdtls项目里提issue时贴的json日志才搞明白的。
1 个赞
你说的是不是不下载代码,而不是自动build?之前那样的确是可以关自动build的,关掉下载dependencies还需要别的设置。
1 个赞
感谢你的再次回复, 不过我说的就是自动build(每次C-x C-s
后自动编译项目). 我在项目文件执行你发的的表达式:
通过
C-h v
检查
eglot-workspace-configuration
:
已经被设置成功:
这样设置, 编辑后再保存还是会build(在target目录中生成class).
请问可以给我看一下你的配置吗? 或者你还记得jdtls相关issue的关键字吗?
再次表示感谢.
这是eglot的日志
[client-request] (id:1) Wed Aug 9 17:03:17 2023:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
(:processId 11809 :rootPath "/Users/xxx/WorkSpace/compiler/" :rootUri "file:///Users/xxx/WorkSpace/compiler" :initializationOptions
(:settings
(:java
(:contentProvider
(:preferred "fernflower")
:autobuild
(:enabled :json-false))))
:capabilities
(:workspace
(:applyEdit t :executeCommand
(:dynamicRegistration :json-false)
:workspaceEdit
(:documentChanges t)
:didChangeWatchedFiles
(:dynamicRegistration t)
:symbol
(:dynamicRegistration :json-false)
:configuration t :workspaceFolders t)
:textDocument
(:synchronization
(:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
:completion
(:dynamicRegistration :json-false :completionItem
(:snippetSupport t :deprecatedSupport t :resolveSupport
(:properties
["documentation" "details" "additionalTextEdits"])
:tagSupport
(:valueSet
[1]))
:contextSupport t)
:hover
(:dynamicRegistration :json-false :contentFormat
["markdown" "plaintext"])
:signatureHelp
(:dynamicRegistration :json-false :signatureInformation
(:parameterInformation
(:labelOffsetSupport t)
:activeParameterSupport t))
:references
(:dynamicRegistration :json-false)
:definition
(:dynamicRegistration :json-false :linkSupport t)
:declaration
(:dynamicRegistration :json-false :linkSupport t)
:implementation
(:dynamicRegistration :json-false :linkSupport t)
:typeDefinition
(:dynamicRegistration :json-false :linkSupport t)
:documentSymbol
(:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind
(:valueSet
[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]))
:documentHighlight
(:dynamicRegistration :json-false)
:codeAction
(:dynamicRegistration :json-false :codeActionLiteralSupport
(:codeActionKind
(:valueSet
["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
:isPreferredSupport t)
:formatting
(:dynamicRegistration :json-false)
:rangeFormatting
(:dynamicRegistration :json-false)
:rename
(:dynamicRegistration :json-false)
:inlayHint
(:dynamicRegistration :json-false)
:publishDiagnostics
(:relatedInformation :json-false :codeDescriptionSupport :json-false :tagSupport
(:valueSet
[1 2])))
:window
(:workDoneProgress t)
:general
(:positionEncodings
["utf-32" "utf-8" "utf-16"])
:experimental #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
()))
:workspaceFolders
[(:uri "file:///Users/xxx/WorkSpace/compiler" :name "~/WorkSpace/compiler/")]))
这个变量的设置得加在java-mode-hook里,eglot启动前。
我看了看我的配置,发现在设置这个变量后,还需要
(letrec ((b (current-buffer))
(conf (lambda (s)
(with-current-buffer b
(eglot-signal-didChangeConfiguration s))
(remove-hook 'eglot-connect-hook conf))))
(add-hook 'eglot-connect-hook conf)))
手机操作,格式不太好看,都加在java-mode-hook里。
看了以下eglot的log, 通过 eglot-workspace-configuration
的方式是在启动以后再给server发送请求更新配置; 在server启动时发送 initializationOption
请求的方式不起作用. 这行为太奇怪了.
再次感谢你的帮助, 要不是你我根本想不到再试一试workspace-configuration.
不过我还是没理解这个配置, 这和官方文档的介绍完全不同.
'((:java :autobuild (:enabled :json-false)))
这个列表的含义是什么呢?
我最后的方案, 明天再解释我为什么这么做:
(setq eglot-workspace-configuration
'(:java
(:autobuild
(:enabled :json-false))))