Skip to content

Commit 42246b5

Browse files
committed
Browse classpath
1 parent 9692335 commit 42246b5

25 files changed

+616
-98
lines changed

README.md

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[![MELPA](https://melpa.org/packages/lsp-java-badge.svg)](https://melpa.org/#/lsp-java)
22
[![Build Status](https://travis-ci.com/emacs-lsp/lsp-java.svg?branch=master)](https://travis-ci.com/emacs-lsp/lsp-java)
3-
4-
Java support for lsp-mode using the [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).
5-
3+
[![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)
4+
Emacs Java IDE using [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).
65
## Features
76
LSP java mode supports the following JDT Features:
87
* 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))
@@ -18,7 +17,9 @@ LSP java mode supports the following JDT Features:
1817
* Limited Gradle support
1918
* Visual debugger - [dap-mode](https://github.com/yyoncho/dap-mode/)
2019
* Test runner - [dap-mode](https://github.com/yyoncho/dap-mode/)
21-
20+
* Project explorer integration - [treemacs](https://github.com/Alexander-Miller/treemacs)
21+
## Screenshot
22+
![demo](images/demo.png)
2223
## Installation
2324
### Spacemacs
2425
[lsp-java](https://github.com/emacs-lsp/lsp-java) is included in spacemacs (for now only on the dev branch). If you are using the development version of
@@ -35,14 +36,13 @@ Then add the following lines to your `.emacs` and open a file from the any of th
3536
```emacs-lisp
3637
(require 'lsp-java)
3738
(add-hook 'java-mode-hook #'lsp-java-enable)
38-
3939
```
4040
### [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls)
4141

4242
[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`.
4343

44-
#### Quick start
45-
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/). Make sure you have replaced the XXX placeholder with the list of the projects you want to import. Now you can explore the methods under `lsp-java-*`, `dap-java-*`, `dap-*`, and `lsp-*`
44+
### Quick start
45+
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-*`
4646
```elisp
4747
(require 'cc-mode)
4848
@@ -86,93 +86,85 @@ Minimal configuration with [company-lsp](https://github.com/tigersoldier/company
8686
8787
(use-package lsp-java
8888
:ensure t
89-
:requires (lsp-ui-flycheck lsp-ui-sideline)
9089
:config
9190
(add-hook 'java-mode-hook 'lsp-java-enable)
9291
(add-hook 'java-mode-hook 'flycheck-mode)
9392
(add-hook 'java-mode-hook 'company-mode)
94-
(add-hook 'java-mode-hook (lambda () (lsp-ui-flycheck-enable t)))
9593
(add-hook 'java-mode-hook 'lsp-ui-mode))
9694
```
9795
## Supported commands
9896
### LSP Mode commands
99-
| Command name | Description |
100-
|------------------------------|--------------------------------------------------------------|
101-
| lsp-execute-code-action | Execute code action. |
102-
| lsp-rename | Rename symbol at point |
103-
| lsp-describe-thing-at-point | Display help for the thing at point. |
104-
| lsp-goto-type-definition | Go to type definition |
105-
| lsp-goto-implementation | Go to implementation |
106-
| lsp-workspace-restart | Restart project |
107-
| lsp-format-buffer | Format current buffer |
108-
| lsp-symbol-highlight | Highlight all relevant references to the symbol under point. |
109-
| lsp-workspace-folders-add | Add workspace folder |
110-
| lsp-workspace-folders-remove | Remove workspace folder |
111-
| lsp-workspace-folders-switch | Switch workspace folder |
97+
* `lsp-execute-code-action` - Execute code action.
98+
* `lsp-rename` - Rename symbol at point
99+
* `lsp-describe-thing-at-point` - Display help for the thing at point.
100+
* `lsp-goto-type-definition` - Go to type definition
101+
* `lsp-goto-implementation` - Go to implementation
102+
* `lsp-workspace-restart` - Restart project
103+
* `lsp-format-buffer` - Format current buffer
104+
* `lsp-symbol-highlight` - Highlight all relevant references to the symbol under point.
105+
* `lsp-workspace-folders-add` - Add workspace folder
106+
* `lsp-workspace-folders-remove` - Remove workspace folder
107+
* `lsp-workspace-folders-switch` - Switch workspace folder
112108
### LSP Java commands
113-
114-
| Command name | Description |
115-
|---------------------------------------|---------------------------------------------------------------|
116-
| lsp-java-organize-imports | Organize imports |
117-
| lsp-java-build-project | Perform partial or full build for the projects |
118-
| lsp-java-update-project-configuration | Update project configuration |
119-
| lsp-java-actionable-notifications | Resolve actionable notifications |
120-
| lsp-java-update-user-settings | Update user settings (Check the options in the table bellow.) |
121-
| lsp-java-update-server | Update server instalation. |
109+
* `lsp-java-organize-imports` - Organize imports
110+
* `lsp-java-build-project` - Perform partial or full build for the projects
111+
* `lsp-java-update-project-configuration` - Update project configuration
112+
* `lsp-java-actionable-notifications` - Resolve actionable notifications
113+
* `lsp-java-update-user-settings` - Update user settings (Check the options in the table bellow.)
114+
* `lsp-java-update-server` - Update server instalation.
122115
#### Refactoring
123-
124116
LSP Java provides rich set of refactorings via [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) code actions and
125117
some of them are bound to Emacs commands:
126-
127-
| Command name | Description |
128-
|------------------------------------|------------------------------|
129-
| lsp-java-extract-to-constant | Extract constant refactoring |
130-
| lsp-java-add-unimplemented-methods | Extract constant refactoring |
131-
| lsp-java-create-parameter | Create parameter refactoring |
132-
| lsp-java-create-field | Create field refactoring |
133-
| lsp-java-create-local | Create local refactoring |
134-
| lsp-java-extract-method | Extract method refactoring |
135-
| lsp-java-add-import | Add missing import |
118+
* `lsp-java-extract-to-constant` - Extract constant refactoring
119+
* `lsp-java-add-unimplemented-methods` - Extract constant refactoring
120+
* `lsp-java-create-parameter` - Create parameter refactoring
121+
* `lsp-java-create-field` - Create field refactoring
122+
* `lsp-java-create-local` - Create local refactoring
123+
* `lsp-java-extract-method` - Extract method refactoring
124+
* `lsp-java-add-import` - Add missing import
125+
#### Treemacs
126+
[lsp-java](https://github.com/emacs-lsp/lsp-java) provides integration with [treemacs](https://github.com/Alexander-Miller/treemacs) which provides option to navigate through package dependecies, namespaces, classes and resources.
127+
* `lsp-java-treemacs-register` activates [lsp-java](https://github.com/emacs-lsp/lsp-java)/[treemacs](https://github.com/Alexander-Miller/treemacs) integration.
128+
* `lsp-java-treemacs-unregister` deactivates [lsp-java](https://github.com/emacs-lsp/lsp-java)/[treemacs](https://github.com/Alexander-Miller/treemacs) integration.
129+
* `lsp-java-update-project-uris`
130+
#### Classpath browsing
131+
[lsp-java](https://github.com/emacs-lsp/lsp-java) the command `lsp-java-browse-classpath` which allows users to browse the structure of current projects classpath. From that view the users could go to the particular item.
132+
![Classpath](images/classpath.png)
136133
## Supported settings
137-
| Setting | Description |
138-
|---------------------------------------|-----------------------------------------------------------------------------------------------------------------|
139-
| lsp-java-server-install-dir | Install directory for eclipsejdtls-server |
140-
| lsp-java-java-path | Path of the java executable |
141-
| lsp-java-workspace-dir | LSP java workspace directory |
142-
| lsp-java-workspace-cache-dir | LSP java workspace cache directory |
143-
| lsp-java-vmargs | Specifies extra VM arguments used to launch the Java Language Server |
144-
| lsp-java-incomplete-classpath | Specifies the severity of the message when the classpath is incomplete for a Java file |
145-
| lsp-java-update-build-configuration | Specifies how modifications on build files update the Java classpath/configuration |
146-
| lsp-java-import-exclusions | Configure glob patterns for excluding folders |
147-
| lsp-java-favorite-static-members | Defines a list of static members or types with static members |
148-
| lsp-java-import-order | Defines the sorting order of import statements |
149-
| lsp-java-trace-server | Traces the communication between Emacs and the Java language server |
150-
| lsp-java-enable-file-watch | Defines whether the client will monitor the files for changes |
151-
| lsp-java-format-enabled | Specifies whether or not formatting is enabled on the language server |
152-
| lsp-java-format-settings-url | Specifies the file path to the formatter xml url |
153-
| lsp-java-format-settings-profile | Specifies the formatter profile name |
154-
| lsp-java-format-comments-enabled | Preference key used to include the comments during the formatting |
155-
| lsp-java-save-action-organize-imports | Organize imports on save |
156-
| lsp-java-bundles | List of bundles that will be loaded in the JDT server |
157-
| lsp-java-import-gradle-enabled | Enable/disable the Gradle importer |
158-
| lsp-java-import-maven-enabled | Enable/disable the Maven importer |
159-
| lsp-java-auto-build | Enable/disable the 'auto build' |
160-
| lsp-java-progress-report | [Experimental] Enable/disable progress reports from background processes on the server |
161-
| lsp-java-completion-guess-arguments | When set to true, method arguments are guessed when a method is selected from as list of code assist proposals. |
162-
## Screenshot
163-
![demo](images/demo.png)
134+
* `lsp-java-server-install-dir` - Install directory for eclipsejdtls-server
135+
* `lsp-java-java-path` - Path of the java executable
136+
* `lsp-java-workspace-dir` - LSP java workspace directory
137+
* `lsp-java-workspace-cache-dir` - LSP java workspace cache directory
138+
* `lsp-java-vmargs` - Specifies extra VM arguments used to launch the Java Language Server
139+
* `lsp-java-incomplete-classpath` - Specifies the severity of the message when the classpath is incomplete for a Java file
140+
* `lsp-java-update-build-configuration` - Specifies how modifications on build files update the Java classpath/configuration
141+
* `lsp-java-import-exclusions` - Configure glob patterns for excluding folders
142+
* `lsp-java-favorite-static-members` - Defines a list of static members or types with static members
143+
* `lsp-java-import-order` - Defines the sorting order of import statements
144+
* `lsp-java-trace-server` - Traces the communication between Emacs and the Java language server
145+
* `lsp-java-enable-file-watch` - Defines whether the client will monitor the files for changes
146+
* `lsp-java-format-enabled` - Specifies whether or not formatting is enabled on the language server
147+
* `lsp-java-format-settings-url` - Specifies the file path to the formatter xml url
148+
* `lsp-java-format-settings-profile` - Specifies the formatter profile name
149+
* `lsp-java-format-comments-enabled` - Preference key used to include the comments during the formatting
150+
* `lsp-java-save-action-organize-imports` - Organize imports on save
151+
* `lsp-java-bundles` - List of bundles that will be loaded in the JDT server
152+
* `lsp-java-import-gradle-enabled` - Enable/disable the Gradle importer
153+
* `lsp-java-import-maven-enabled` - Enable/disable the Maven importer
154+
* `lsp-java-auto-build` - Enable/disable the 'auto build'
155+
* `lsp-java-progress-report` - [Experimental] Enable/disable progress reports from background processes on the server
156+
* `lsp-java-completion-guess-arguments` - When set to true, method arguments are guessed when a method is selected from as list of code assist proposals.
164157
## Additional packages
165158
* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) : Flycheck, documentation and code actions support.
166159
* [company-lsp](https://github.com/tigersoldier/company-lsp) : LSP company backend.
160+
* [treemacs](https://github.com/Alexander-Miller/treemacs) : Project viewer.
167161
## FAQ
168162
* LSP Java is showing to many debug messages, how to stop that?
169-
170163
Add the following configuration.
171164
```emacs-lisp
172165
(setq lsp-inhibit-message t)
173166
```
174167
* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) does not display all of the actions on the current point(e. g "Extract constant")?
175-
176168
LSP UI by default sends current line bounds for action region which breaks forces JDT server to return only "Extract method action."
177169
```emacs-lisp
178170
(setq lsp-ui-sideline-update-mode 'point)

features/BrowseClasspath.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: Browse classpaths
2+
@Classpath
3+
Scenario: Organize imports
4+
Given I have maven project "m" in "tmp"
5+
And I add project "m" folder "tmp" to the list of workspace folders
6+
And I have a java file "tmp/m/src/main/java/temp/App.java"
7+
And I clear the buffer
8+
And I insert:
9+
"""
10+
package temp;
11+
12+
import java.util.HashMap;
13+
14+
class App {
15+
ArrayList<String> al = new ArrayList<>();
16+
}
17+
"""
18+
And I call "save-buffer"
19+
And I start lsp-java
20+
And The server status must become "LSP::Started"
21+
When I call "lsp-java-classpath-browse"
22+
Then I should see:
23+
"""
24+
org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER
25+
"""

features/OrganizeImports.feature

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ Feature: Organize imports
3030
}
3131
"""
3232

33-
Feature: Organize imports save action
3433
@Imports
35-
Scenario: Organize imports
34+
Scenario: Organize imports save action
3635
Given I have maven project "m" in "tmp"
3736
And I add project "m" folder "tmp" to the list of workspace folders
3837
And I have a java file "tmp/m/src/main/java/temp/App.java"
@@ -61,9 +60,8 @@ Feature: Organize imports save action
6160
}
6261
"""
6362

64-
Feature: Disable organize imports save action
6563
@Imports
66-
Scenario: Organize imports
64+
Scenario: Disable organize imports save action
6765
Given I have maven project "m" in "tmp"
6866
And I add project "m" folder "tmp" to the list of workspace folders
6967
And I have a java file "tmp/m/src/main/java/temp/App.java"

features/step-definitions/lsp-java-steps.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878

7979
(And "^I add project \"\\([^\"]+\\)\" folder \"\\([^\"]+\\)\" to the list of workspace folders$"
8080
(lambda (project dir-name)
81-
(add-to-list 'lsp-java--workspace-folders (f-join lsp-java-test-root dir-name project))))
81+
(mkdir lsp-java-workspace-dir t)
82+
(lsp--persist (f-join lsp-java-workspace-dir ".folders")
83+
(list (f-join lsp-java-test-root dir-name project)))))
8284

8385
(And "^I start lsp-java$"
8486
(lambda ()

features/support/env.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
(Before
3434
(require 'lsp-java)
3535
(setq lsp-java-workspace-dir (f-join lsp-java-test-root "workspace")
36+
lsp-java-pop-buffer-function 'pop-to-buffer
3637
lsp-java-workspace-cache-dir (f-join lsp-java-test-root "workspace-cache")
3738
lsp-java-server-install-dir (locate-user-emacs-file "eclipse.jdt.ls/server/")
3839
lsp-response-timeout 30)

icons/vscode/default_folder.png

352 Bytes
Loading
504 Bytes
Loading
643 Bytes
Loading
749 Bytes
Loading

icons/vscode/error.png

602 Bytes
Loading

0 commit comments

Comments
 (0)