怎样配置eglot 是其能够打开maven 依赖的源代码呢?

我现在的eglot jdtls 配置只能跳转到工程内的源代码,没法查看maven 依赖的源代码,也没法查看jdk的源代码。

谢谢! 只jarchive 不工作,是不是必须配合eglot-java 呢?

当然是看一眼源码,有没有require了。。。

1 个赞

确认了,是需要搭配的,虽然没有相应的require. 差不多看来了2小时关于这个的讨论!

eglot-java 里有对 jdt:// 文件协议的解析方法,jarchive 里有对 clojure jar包依赖的解析方法,另外如果你不想把打开的源代码当成新项目新开一个lsp server的话,把 eglot-extend-to-xref 设为 t

If you want eglot to manage the opened jar’d file in your project’s current lsp session, set

(setq eglot-extend-to-xref t)

This will allow xref to work across your project and the opened file. If you do not want that, the eglot will probably start a new server to manage the newly opened file. There are legitimate reasons to do this, because including it in the current LSP session will mean it is included when looking up references. Large files, like the clojure core library, could create a lot of noise in xref lookups. Another recommendation if you don’t want them managed by eglot is to set

2 个赞

hot code replace 支持吗?

我不想使用eglot-java这个包,尝试从这个包里复制如下代码到我的init.el里面,但是不工作,你知道是什么原因吗?emacs 30, eglot 1.18, 1.19都尝试了。这个handler没有被调用。

(defun eglot-java--jdt-uri-handler (_operation &rest args)
  "Support Eclipse jdtls `jdt://' uri scheme."
  (message "jdt uri handler")
  (let* ((uri (car args))
         (cache-dir (expand-file-name ".eglot-java" (project-root (project-current t))))
         (source-file
          (expand-file-name
           (eglot-java--make-path
            cache-dir
            (save-match-data
              (when (string-match "jdt://contents/\\(.*?\\)/\\(.*\\)\.class\\?" uri)
                (format "%s.java" (replace-regexp-in-string "/" "." (match-string 2 uri) t t))))))))
    (unless (file-readable-p source-file)
      (let ((content (jsonrpc-request (eglot-current-server) :java/classFileContents (list :uri uri)))
            (metadata-file (format "%s.%s.metadata"
                                   (file-name-directory source-file)
                                   (file-name-base source-file))))
        (unless (file-directory-p cache-dir) (make-directory cache-dir t))
        (with-temp-file source-file (insert content))
        (with-temp-file metadata-file (insert uri))))
    source-file))

(add-to-list 'file-name-handler-alist '("\\`jdt://" . eglot-java--jdt-uri-handler))

这个变量也设置了的。

'(eglot-extend-to-xref t)

initialization options 的 extendedClientCapabilities classFileContentsSupport 没设置?

1 个赞

谢谢,加上这个就工作了。我原以为eglot 默认启用了所有的功能。

为什么不想用这个包,这个包已经好久没更新了,pr 也不处理。

是啊,作者也说了,他现在基本上不写java 代码了,这个包启动server 用的是java 命令,不是用的jdtls 命令,不知道会不会有些潜在的冲突。但是上面的那段代码很有价值

1 个赞