eglot icon indicating copy to clipboard operation
eglot copied to clipboard

[Feature request] support multi-module java projects

Open ukaszg opened this issue 3 years ago • 4 comments

eglot-initialization-options should first find root of project (going up a directory and looking for pom.xml), and than scan recursively for pom.xml (if child dir has no pom.xml it should stop going further) and than add everything to :workspaceFolders.

or you could maybe allow for setting :workspaceFolders manually (for example variable containing alist of "root dir" '(list of project roots)), if you would like to pick this option I'm willing to work on a pull request for this.

ukaszg avatar Sep 21 '20 20:09 ukaszg

eglot-initialization-options should first find root of project (going up a directory and looking for pom.xml), and than scan recursively for pom.xml (if child dir has no pom.xml it should stop going further) and than add everything to :workspaceFolders.

This is exactly how eglot works now. Is it not correct?

https://github.com/joaotavora/eglot/blob/61b71ea769fa14887465517f70832861f7052816/eglot.el#L2629-L2640

mkcms avatar Sep 22 '20 05:09 mkcms

I have a project with multiple nested subrepos and 3 levels deep hierarchy. I doesn't work properly there. Current code only looks 1 level deep and doesn't open root of project.

ukaszg avatar Sep 22 '20 05:09 ukaszg

Oh right, indeed the single-* wildcard won't find files nested more deeply.

mkcms avatar Sep 22 '20 09:09 mkcms

so far I'm using this for supporting recursive projects:

((cl-defmethod eglot-initialization-options ((server eglot-eclipse-jdt))
    "Passes through required jdt initialization options"
    `(:workspaceFolders
      [,@(mapcar #'eglot--path-to-uri
                 (let* ((root (expand-file-name (project-root (eglot--project server))))
                        projects
                        candidate)
                   (while (or (file-exists-p (setq candidate (expand-file-name "../pom.xml" root)))
                              (file-exists-p (setq candidate (expand-file-name "../build.gradle" root)))
                              (file-exists-p (setq candidate (expand-file-name "../.project" root))))
                     (setq root (file-name-directory candidate)))
                   (setq projects (list root)
                         candidate projects)
                   (cl-flet ((dig-deeper (dir)
                                         (append (file-expand-wildcards (concat dir "*/pom.xml"))
                                                 (file-expand-wildcards (concat dir "*/build.gradle"))
                                                 (file-expand-wildcards (concat dir "*/.project")))))
                     (while (setq candidate
                                  (cl-delete-duplicates
                                   (mapcar #'file-name-directory (apply #'append (mapcar #'dig-deeper candidate)))
                                   :test #'string=))
                       (setq projects (append projects candidate))))
                   projects))]
      ,@(if-let ((home (or (getenv "JAVA_HOME")
                           (ignore-errors
                             (expand-file-name
                              ".."
                              (file-name-directory
                               (file-chase-links (executable-find "javac"))))))))
            `(:settings (:java (:home ,home)))
          (ignore (eglot--warn "JAVA_HOME env var not set")))))```


Haven't checked yet if sorting (from root to leaves) is required.
--edit: switch to pure elisp solution --

ukaszg avatar Sep 26 '20 09:09 ukaszg