Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] support multi-module java projects #541

Open
ukaszg opened this issue Sep 21, 2020 · 4 comments
Open

[Feature request] support multi-module java projects #541

ukaszg opened this issue Sep 21, 2020 · 4 comments

Comments

@ukaszg
Copy link

ukaszg commented Sep 21, 2020

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.

@mkcms
Copy link
Collaborator

mkcms commented Sep 22, 2020

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?

eglot/eglot.el

Lines 2629 to 2640 in 61b71ea

`(:workspaceFolders
[,@(cl-delete-duplicates
(mapcar #'eglot--path-to-uri
(let* ((root (project-root (eglot--project server))))
(cons root
(mapcar
#'file-name-directory
(append
(file-expand-wildcards (concat root "*/pom.xml"))
(file-expand-wildcards (concat root "*/build.gradle"))
(file-expand-wildcards (concat root "*/.project")))))))
:test #'string=)]

@ukaszg
Copy link
Author

ukaszg commented Sep 22, 2020

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.

@mkcms
Copy link
Collaborator

mkcms commented Sep 22, 2020

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

@ukaszg
Copy link
Author

ukaszg commented Sep 26, 2020

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 --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants