Skip to content

Commit

Permalink
[Dependencies] Initial version of java dependency explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
yyoncho committed Aug 15, 2019
1 parent f407a9a commit bb55273
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 281 deletions.
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,9 @@ some of them are bound to Emacs commands:
* `lsp-java-create-local` - Create local refactoring
* `lsp-java-extract-method` - Extract method refactoring
* `lsp-java-add-import` - Add missing import
#### Treemacs
__NOTE__ It works only when using Eclipse Che Language Server.

[lsp-java](https://github.com/emacs-lsp/lsp-java) provides experimental integration with [treemacs](https://github.com/Alexander-Miller/treemacs) which provides option to navigate through package dependecies, namespaces, classes and resources.
* `lsp-java-treemacs-register` activates [lsp-java](https://github.com/emacs-lsp/lsp-java)/[treemacs](https://github.com/Alexander-Miller/treemacs) integration.
* `lsp-java-treemacs-unregister` deactivates [lsp-java](https://github.com/emacs-lsp/lsp-java)/[treemacs](https://github.com/Alexander-Miller/treemacs) integration.
* `lsp-java-update-project-uris` refresh the project URIs.
#### Classpath browsing
__NOTE__ It works only when using Eclipse Che Language Server.

[lsp-java](https://github.com/emacs-lsp/lsp-java) the command `lsp-java-classpath-browse` which allows users to browse the structure of current projects classpath. From that view the users could go to the particular item.
![Classpath](images/classpath.png)
#### Dependency viewer
* `lsp-java-dependency-list` - View java dependencies

#### STS4 Integration (experimental)

LSP java has integration with [STS4](https://github.com/spring-projects/sts4/) providing the following functionality.
Expand Down
Binary file added icons/vscode/classfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/folder-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-flat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-hierarchical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/icon-unlink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/jar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/package.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/packagefolder-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/packagefolder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/project-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/vscode/project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion install/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</execution>
<execution>
<phase>process-resources</phase>
<id>download-vscode</id>
<id>download-spring-boot</id>
<goals>
<goal>wget</goal>
</goals>
Expand All @@ -53,6 +53,18 @@
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-dependency</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/vscjava.vscode-java-dependency-0.5.1.vsix</url>
<outputFileName>java-dependency.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand All @@ -67,6 +79,7 @@
<tasks>
<untar src="${project.build.directory}/jdt-language-server-latest.tar.gz" compression="gzip" dest="${jdt.js.server.root}" />
<unzip src="${project.build.directory}/vscode-extension.zip" dest="${project.build.directory}/vscode-extension-extracted" />
<unzip src="${project.build.directory}/java-dependency.zip" dest="${project.build.directory}/java-dependency" />
</tasks>
</configuration>
<goals>
Expand Down Expand Up @@ -150,6 +163,24 @@
</resources>
</configuration>
</execution>
<execution>
<id>copy-dep-bundles</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/java-dependency/extension/server/</directory>
<includes>
<include>com.microsoft.jdtls.ext.core-0.5.1.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
181 changes: 181 additions & 0 deletions lsp-java-dependency.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
;;; lsp-java-dependency.el --- LSP Java treemacs integration -*- lexical-binding: t; -*-

;; Copyright (C) 2018 Ivan Yonchovski

;; Author: Ivan Yonchovski <[email protected]>
;; Keywords: lsp

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Provides integration between `lsp-java' and `treemacs' which aims to provide
;; ide like project explorer.

;;; Code:

(with-eval-after-load 'treemacs
(require 'dash)
(require 'lsp-mode)
(require 'lsp-java)
(require 'dash-functional)

(defun lsp-java-dependency--goto-element (&rest _args)
(if-let ((dep (-some-> (treemacs-node-at-point)
(button-get :dep))))
(--doto (find-file-noselect (or (-some-> (gethash "uri" dep)
(lsp--uri-to-path))
(gethash "path" dep)))

(select-window (get-mru-window nil nil t))
(switch-to-buffer it))
(user-error "No element under point.")))

(treemacs-modify-theme "Default"
:icon-directory (f-join (f-dirname (or load-file-name buffer-file-name)) "icons/vscode")
:config
(progn
(treemacs-create-icon :file "classfile.png" :extensions (classfile) :fallback "-")
(treemacs-create-icon :file "default_folder_opened.png" :extensions (default-folder-opened) :fallback "-")
(treemacs-create-icon :file "default_folder.png" :extensions (default-folder) :fallback "-")
(treemacs-create-icon :file "default_root_folder_opened.png" :extensions (default-root-folder-opened) :fallback "-")
(treemacs-create-icon :file "default_root_folder.png" :extensions (default-root-folder) :fallback "-")
(treemacs-create-icon :file "file_type_class.png" :extensions ("class") :fallback "-")
(treemacs-create-icon :file "file_type_jar.png" :extensions (file-type-jar) :fallback "-")
(treemacs-create-icon :file "folder-open.png" :extensions (folder-open) :fallback "-")
(treemacs-create-icon :file "folder.png" :extensions (folder) :fallback "-")
(treemacs-create-icon :file "folder_type_component_opened.png" :extensions (folder-type-component-opened) :fallback "-")
(treemacs-create-icon :file "folder_type_component.png" :extensions (folder-type-component) :fallback "-")
(treemacs-create-icon :file "folder_type_library_opened.png" :extensions (folder-type-library-opened) :fallback "-")
(treemacs-create-icon :file "folder_type_library.png" :extensions (folder-type-library) :fallback "-")
(treemacs-create-icon :file "folder_type_maven_opened.png" :extensions (folder-type-maven-opened) :fallback "-")
(treemacs-create-icon :file "folder_type_maven.png" :extensions (folder-type-maven) :fallback "-")
(treemacs-create-icon :file "folder_type_package_opened.png" :extensions (folder-type-package-opened) :fallback "-")
(treemacs-create-icon :file "folder_type_package.png" :extensions (folder-type-package) :fallback "-")
(treemacs-create-icon :file "icon-create.png" :extensions (icon-create) :fallback "-")
(treemacs-create-icon :file "icon-flat.png" :extensions (icon-flat) :fallback "-")
(treemacs-create-icon :file "icon-hierarchical.png" :extensions (icon-hierarchical) :fallback "-")
(treemacs-create-icon :file "icon-link.png" :extensions (icon-link) :fallback "-")
(treemacs-create-icon :file "icon-refresh.png" :extensions (icon-refresh) :fallback "-")
(treemacs-create-icon :file "icon-unlink.png" :extensions (icon-unlink) :fallback "-")
(treemacs-create-icon :file "jar.png" :extensions (jar) :fallback "-")
(treemacs-create-icon :file "library.png" :extensions (library) :fallback "-")
(treemacs-create-icon :file "packagefolder-open.png" :extensions (packagefolder-open) :fallback "-")
(treemacs-create-icon :file "packagefolder.png" :extensions (packagefolder) :fallback "-")
(treemacs-create-icon :file "package.png" :extensions (package) :fallback "-")
(treemacs-create-icon :file "project.png" :extensions (java-project) :fallback "-")))

(defun lsp-java-dependency--icon (dep expanded)
"Get the symbol for the the kind."
(-let (((&hash "uri" "name" "kind" "entryKind" entry-kind) dep))
(concat
(if (or (= kind 6)
(= kind 8))
" "
(treemacs-get-icon-value
(if expanded 'expanded 'collapsed)
nil
lsp-treemacs-theme))
(if (or (= kind 8)
(= kind 6))
(treemacs-icon-for-file uri)
(treemacs-get-icon-value
(cond
((eq kind 5) 'namespace)
((eq kind 4) 'jar)
((eq kind 2) 'java-project)
((eq entry-kind 1) 'package)
((eq entry-kind 3) 'packagefolder)
((eq entry-kind 5) 'library))
nil
lsp-treemacs-theme)))))

(defun lsp-java-dependency--get-children (dep)
(lsp-java-with-jdtls
(-let (((&hash "projectUri" project-uri "rootPath" root-path "path" "kind" "name") dep))
(unless (or (= kind 6)
(= kind 8))
(--map (--doto it
(puthash "projectUri" project-uri it)
(when (= kind 4)
(puthash "rootPath" path it)))
(lsp-send-execute-command "java.getPackageData"
(vector (ht ("kind" kind)
("path" (unless (eq kind 2)
(if (= 5 kind)
name
path)))
("rootPath" (unless (eq kind 2)
(or root-path path)))
("projectUri" project-uri)))))))))

(treemacs-define-expandable-node lsp-java-dependency
:icon-open-form (lsp-java-dependency--icon (treemacs-button-get node :dep) t)
:icon-closed-form (lsp-java-dependency--icon (treemacs-button-get node :dep) nil)
:query-function (lsp-java-dependency--get-children (treemacs-button-get node :dep))
:ret-action 'lsp-java-dependency--goto-element
:render-action
(treemacs-render-node
:icon (lsp-java-dependency--icon item nil)
:label-form (propertize (gethash "name" item) 'face 'default)
:state treemacs-lsp-java-dependency-closed-state
:key-form (gethash "name" item)
:more-properties (:dep item)))

(defun lsp-java-dependency--root-folders ()
(lsp-java-with-jdtls
(-mapcat (lambda (root-path)
(let ((project-uri (lsp--path-to-uri root-path)))
(->> project-uri
(lsp-send-execute-command "java.project.list")
(--map (--doto it (puthash "projectUri" project-uri it))))))
(lsp-session-folders (lsp-session)))))

(treemacs-define-variadic-node lsp-java-dependency-list
:query-function (lsp-java-dependency--root-folders)
:render-action
(treemacs-render-node
:icon (lsp-java-dependency--icon item nil)
:label-form (propertize (gethash "name" item) 'face 'default)
:state treemacs-lsp-java-dependency-closed-state
:key-form item
:more-properties (:dep item))
:root-key-form 'LSP-Java-Dependency)

(defun lsp-java-dependency-refresh ()
"Refresh dependecy list."
(interactive)
(condition-case _err
(let ((inhibit-read-only t))
(with-current-buffer "*LSP Dependency List*"
(treemacs-update-node '(:custom LSP-Symbols) t)))
(error)))

(defun lsp-java-dependency-list ()
"Display error list."
(interactive)
(lsp-java-with-jdtls
(let* ((buffer (get-buffer-create "*LSP Dependency List*"))
(window (display-buffer-in-side-window buffer '((side . right)))))
(select-window window)
(set-window-dedicated-p window t)
(treemacs-initialize)
(setq-local treemacs-default-visit-action 'treemacs-RET-action)
(treemacs-LSP-JAVA-DEPENDENCY-LIST-extension)))))

(provide 'lsp-java-dependency)

;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End:
Loading

0 comments on commit bb55273

Please sign in to comment.