Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: emacs-lsp/lsp-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.2
Choose a base ref
...
head repository: emacs-lsp/lsp-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 3,224 additions and 1,191 deletions.
  1. +33 −0 .github/workflows/docs.yml
  2. +50 −0 .github/workflows/test.yml
  3. +4 −1 .gitignore
  4. +0 −33 .travis.yml
  5. +0 −10 Cask
  6. +34 −0 Eask
  7. +25 −0 Makefile
  8. +71 −39 README.md
  9. +393 −0 dap-java.el
  10. +17 −0 docs/stylesheets/extra.css
  11. BIN icons/vscode/class.png
  12. BIN icons/vscode/debug.png
  13. BIN icons/vscode/default_folder.png
  14. BIN icons/vscode/default_folder_opened.png
  15. BIN icons/vscode/default_root_folder.png
  16. BIN icons/vscode/default_root_folder_opened.png
  17. BIN icons/vscode/error.png
  18. BIN icons/vscode/file_type_class.png
  19. BIN icons/vscode/file_type_jar.png
  20. BIN icons/vscode/folder_type_component.png
  21. BIN icons/vscode/folder_type_component_opened.png
  22. BIN icons/vscode/folder_type_library.png
  23. BIN icons/vscode/folder_type_library_opened.png
  24. BIN icons/vscode/folder_type_maven.png
  25. BIN icons/vscode/folder_type_maven_opened.png
  26. BIN icons/vscode/folder_type_package.png
  27. BIN icons/vscode/folder_type_package_opened.png
  28. BIN icons/vscode/history.png
  29. BIN icons/vscode/info.png
  30. BIN icons/vscode/method.png
  31. BIN icons/vscode/package.png
  32. BIN icons/vscode/pass.png
  33. BIN icons/vscode/placeholder.png
  34. BIN icons/vscode/refresh.png
  35. BIN icons/vscode/run.png
  36. BIN icons/vscode/running.png
  37. BIN icons/vscode/test-error.png
  38. BIN icons/vscode/warning.png
  39. BIN images/class.png
  40. BIN images/debug.png
  41. BIN images/logo.png
  42. BIN images/method.png
  43. BIN images/package.png
  44. BIN images/placeholder.png
  45. BIN images/refresh.png
  46. BIN images/run.png
  47. +237 −154 install/pom.xml
  48. +45 −31 lsp-java-boot.el
  49. +0 −268 lsp-java-treemacs.el
  50. +1,635 −655 lsp-java.el
  51. +635 −0 lsp-jt.el
  52. +45 −0 mkdocs.yml
33 changes: 33 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docs

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: purcell/setup-emacs@master
with:
version: 27.1

- uses: conao3/setup-cask@master
with:
version: 0.8.4

- name: MkDocs
run: |
cp -rf README.md images docs
docker login docker.pkg.github.com --username $GITHUB_ACTOR --password ${{ secrets.GITHUB_TOKEN }}
docker run --rm -v ${PWD}:/docs docker.pkg.github.com/emacs-lsp/docs-image/docs-image -- build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
emacs-version:
- 27.2
- 28.2
- 29.4
experimental: [false]
include:
- os: ubuntu-latest
emacs-version: snapshot
experimental: true
- os: macos-latest
emacs-version: snapshot
experimental: true
- os: windows-latest
emacs-version: snapshot
experimental: true
exclude:
- os: macos-latest
emacs-version: 27.2

steps:
- uses: actions/checkout@v3

- uses: jcs090218/setup-emacs@master
with:
version: ${{ matrix.emacs-version }}

- uses: emacs-eask/setup-eask@master
with:
version: 'snapshot'

- name: Run tests
run: 'make ci'
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.cask
.eask
/dist
*.elc
tmp/
/install/.mvn/wrapper/maven-wrapper.jar
/install/target
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

10 changes: 0 additions & 10 deletions Cask

This file was deleted.

34 changes: 34 additions & 0 deletions Eask
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(package "lsp-java"
"3.0"
"Java support for lsp-mode")

(website-url "https://github.com/emacs-lsp/lsp-java")
(keywords "languages" "tools")

;; XXX: Linter will report errors because of the package main file; let's
;; disable this for now!
;;(package-file "lsp-java.el")

(files "*.el")

(script "test" "echo \"Error: no test specified\" && exit 1")

(source "gnu")
(source "melpa")

(depends-on "emacs" "27.1")
(depends-on "lsp-mode")
(depends-on "markdown-mode")
(depends-on "dash")
(depends-on "f")
(depends-on "ht")
(depends-on "request")
(depends-on "treemacs")
(depends-on "dap-mode")

(development
(depends-on "spinner")
(depends-on "ecukes")
(depends-on "espuds"))

(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
EMACS ?= emacs
EASK ?= eask

build:
$(EASK) package
$(EASK) install

ci: build compile checkdoc lint

compile:
@echo "Compiling..."
@$(EASK) compile

lint:
@echo "package linting..."
@$(EASK) lint package

clean:
$(EASK) clean all

# TODO: do we have tests?
test:
$(EASK) install-deps --dev

.PHONY: build test compile checkdoc lint
110 changes: 71 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
[![MELPA](https://melpa.org/packages/lsp-java-badge.svg)](https://melpa.org/#/lsp-java)
[![Build Status](https://travis-ci.com/emacs-lsp/lsp-java.svg?branch=master)](https://travis-ci.com/emacs-lsp/lsp-java)
[![MELPA Stable](https://stable.melpa.org/packages/lsp-java-badge.svg)](https://stable.melpa.org/#/lsp-java)
[![Build Status](https://github.com/emacs-lsp/lsp-java/workflows/CI/badge.svg?branch=master)](https://github.com/emacs-lsp/lsp-java/actions)
[![Join the chat at https://gitter.im/emacs-lsp/lsp-mode](https://badges.gitter.im/emacs-lsp/lsp-mode.svg)](https://gitter.im/emacs-lsp/lsp-mode?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

lsp-java
========

Emacs Java IDE using [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).

__ANNOUNCEMENT__ `lsp-java` switching from Eclipse [eclipse.che.jdt](https://github.com/eclipse/che-ls-jdt) to directly using [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) due to the fact that [che-ls-jdt](https://github.com/eclipse/che-ls-jdt) does not bump upstream components often enough. As a result all Che dependent methods(Treemacs integation and browse classpath) won't work. If you still want to use [eclipse.che.jdt](https://github.com/eclipse/che-ls-jdt) functionality you may set `lsp-java-jdt-download-url` to `http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server-latest.tar.gz` and call `lsp-java-update-server`.
## Requirements
- JDK 17

## Features
LSP java mode supports the following JDT Features:

* As you type reporting of parsing and compilation errors (via [flycheck](https://github.com/flycheck/flycheck)/[lsp-ui](https://github.com/emacs-lsp/lsp-ui))
* Code completion - using [company-lsp](https://github.com/tigersoldier/company-lsp) or builtin ```complete-at-point```
* Code completion - using [company-capf](https://github.com/company-mode/company-mode) or builtin ```complete-at-point```
* Javadoc hovers - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)
* Code actions - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)
* Code outline - using builtin [imenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html)
@@ -23,6 +29,10 @@ LSP java mode supports the following JDT Features:
* Test runner - [dap-mode](https://github.com/yyoncho/dap-mode/)
* Project explorer integration - [treemacs](https://github.com/Alexander-Miller/treemacs)
* Integration with [Spring Initializr](https://start.spring.io/)
## Demo
Here it is a demo from EmacsConf2019 https://www.youtube.com/watch?v=Bbjxn9yVNJ8
## Tutorial
Here is a tutorial that covers setup and use https://xpressrazor.wordpress.com/2020/11/04/java-programming-in-emacs/
## Screenshot
![demo](images/demo.png)
## Installation
@@ -47,10 +57,9 @@ Then add the following lines to your `.emacs` and open a file from the any of th
[lsp-java](https://github.com/emacs-lsp/lsp-java) will automatically detect when the server is missing and it will download [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) before the first startup. The server installation will be in `lsp-java-server-install-dir`. It will detect whether [dap-mode](https://github.com/yyoncho/dap-mode/) is present and it will download the required server side plugins/components. If you want to update the server you can run `lsp-java-update-server`. To run specific version of [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) use `lsp-java-server-install-dir`.

### Quick start
Minimal configuration with [company-lsp](https://github.com/tigersoldier/company-lsp) and [lsp-ui](https://github.com/emacs-lsp/lsp-ui) and [dap-mode](https://github.com/yyoncho/dap-mode/). Now you can explore the methods under `lsp-java-*`, `dap-java-*`, `dap-*`, and `lsp-*`
```elisp
(require 'cc-mode)
Minimal configuration with [company-capf](https://github.com/company-mode/company-mode) and [lsp-ui](https://github.com/emacs-lsp/lsp-ui) and [dap-mode](https://github.com/yyoncho/dap-mode/). Set `lsp-java-workspace-dir` in case you have existing Java projects. Now you can explore the methods under `lsp-java-*`, `dap-java-*`, `dap-*`, and `lsp-*`.

```elisp
(condition-case nil
(require 'use-package)
(file-error
@@ -59,27 +68,24 @@ Minimal configuration with [company-lsp](https://github.com/tigersoldier/company
(package-initialize)
(package-refresh-contents)
(package-install 'use-package)
(setq use-package-always-ensure t)
(require 'use-package)))
(use-package projectile :ensure t)
(use-package treemacs :ensure t)
(use-package yasnippet :ensure t)
(use-package lsp-mode :ensure t)
(use-package hydra :ensure t)
(use-package company-lsp :ensure t)
(use-package lsp-ui :ensure t)
(use-package lsp-java :ensure t :after lsp
:config (add-hook 'java-mode-hook 'lsp))
(use-package dap-mode
:ensure t :after lsp-mode
:config
(dap-mode t)
(dap-ui-mode t))
(use-package dap-java :after (lsp-java))
(use-package lsp-java-treemacs :after (treemacs))
(use-package projectile)
(use-package flycheck)
(use-package yasnippet :config (yas-global-mode))
(use-package lsp-mode :hook ((lsp-mode . lsp-enable-which-key-integration)))
(use-package hydra)
(use-package company)
(use-package lsp-ui)
(use-package which-key :config (which-key-mode))
(use-package lsp-java :config (add-hook 'java-mode-hook 'lsp))
(use-package dap-mode :after lsp-mode :config (dap-auto-configure-mode))
(use-package dap-java :ensure nil)
(use-package helm-lsp)
(use-package helm
:config (helm-mode))
(use-package lsp-treemacs)
```
## Supported commands
### LSP Mode commands
@@ -104,28 +110,29 @@ Minimal configuration with [company-lsp](https://github.com/tigersoldier/company
* `lsp-java-generate-to-string` - Generate `toString` method.
* `lsp-java-generate-equals-and-hash-code` - Generate `equals` and `hashCode` methods.
* `lsp-java-generate-overrides` - Generate method `overrides`
* `lsp-java-generate-getters-and-setters` - Generate getters and setters.
* `lsp-java-type-hierarchy` - Open type hierarchy. Use prefix arg to specify the type of the hierarchy.
#### Refactoring
LSP Java provides rich set of refactorings via [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) code actions and
some of them are bound to Emacs commands:

* `lsp-java-extract-to-constant` - Extract constant refactoring
* `lsp-java-add-unimplemented-methods` - Extract constant refactoring
* `lsp-java-create-parameter` - Create parameter refactoring
* `lsp-java-create-field` - Create field refactoring
* `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)
#### Testing support
* `lsp-jt-browser` - Browse tests and run/debug them.
** Use `x` to run the test(s) under point; `d` to debug the tests under point. `R` to refresh.
** Support for GUI operations.
* `lsp-jt-report-open` - open test report
* `lsp-jt-lens-mode` - test lenses mode(requires `lsp-lens-mode` to be enabled.)

#### 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.
@@ -248,7 +255,10 @@ Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server
* `lsp-java-format-enabled` - Enable/disable default Java formatter
* `lsp-java-save-actions-organize-imports ` - Enable/disable auto organize imports on save action
* `lsp-java-import-exclusions` - Configure glob patterns for excluding folders
* `lsp-java-content-provider-preferred` - Preferred content provider (a 3rd party decompiler id, usually)
* `lsp-java-content-provider-preferred` - Preferred content provider (a 3rd party decompiler id, usually). We support https://github.com/dgileadi/vscode-java-decompiler. To enable it, add:
```elisp
(setq lsp-java-content-provider-preferred "fernflower")
```
* `lsp-java-autobuild-enabled` - Enable/disable the 'auto build'
* `lsp-java-max-concurrent-builds` - Max simultaneous project builds
* `lsp-java-completion-enabled` - Enable/disable code completion support
@@ -277,8 +287,9 @@ Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server
## Additional packages
* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) : Flycheck, documentation and code actions support.
* [company-lsp](https://github.com/tigersoldier/company-lsp) : LSP company backend.
* [company-capf](https://github.com/company-mode/company-mode) : Company backend support.
* [treemacs](https://github.com/Alexander-Miller/treemacs) : Project viewer.
* [lsp-treemacs](https://github.com/emacs-lsp/lsp-treemacs) : `lsp-mode` GUI controls implemented using treemacs.
## FAQ
* LSP Java is showing to many debug messages, how to stop that?
Add the following configuration.
@@ -293,3 +304,24 @@ LSP UI by default sends current line bounds for action region which breaks force
* LSP Java does not provide completion, go to definition for some of the files?

When particular file is not part of imported project [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) could not calculate the current classpath.

* How do I change the version of java used by LSP?

Have a look at `~/.emacs.d/workspace/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml`. If you updated your local java path and want LSP to use the new version, try removing the `~/.emacs.d/workspace/` directory and relaunch LSP. Also see [#114](https://github.com/emacs-lsp/lsp-java/issues/114).
If you have multiple java JDK versions installed and want to change the version of java used by LSP, also need to set `lsp-java-configuration-runtimes`. An example for setting `lsp-java-configuration-runtimes`:

```lisp
(setq lsp-java-configuration-runtimes '[(:name "JavaSE-1.8"
:path "/home/kyoncho/jdk1.8.0_201.jdk/")
(:name "JavaSE-11"
:path "/home/kyoncho/jdk-11.0.1.jdk/"
:default t)])
```

* How do I change JVM args passed to JDT server?
LSP slowness could be caused by slow JDT server, especially on large JAVA projects. Bump up the heap size maybe a good idea.

```lisp
;; current VSCode defaults
(setq lsp-java-vmargs '("-XX:+UseParallelGC" "-XX:GCTimeRatio=4" "-XX:AdaptiveSizePolicyWeight=90" "-Dsun.zip.disableMemoryMapping=true" "-Xmx2G" "-Xms100m"))
```
Loading