From 05554f1e0d02596d8f1e198c2389c8c2978f64e8 Mon Sep 17 00:00:00 2001 From: mopemope Date: Wed, 6 May 2020 22:21:20 +0900 Subject: [PATCH] update --- README.md | 292 +++++++++++++++++++----------------------------------- 1 file changed, 103 insertions(+), 189 deletions(-) diff --git a/README.md b/README.md index a5794cb..d17d2bd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Meghanada-Mode [![MELPA](https://melpa.org/packages/meghanada-badge.svg)](https://melpa.org/#/meghanada) [![MELPA](http://melpa-stable.milkbox.net/packages/meghanada-badge.svg)](http://melpa-stable.milkbox.net/#/meghanada) -[![Join the chat at https://gitter.im/mopemope/meghanada-emacs](https://badges.gitter.im/mopemope/meghanada-emacs.svg)](https://gitter.im/mopemope/meghanada-emacs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Patreon](https://img.shields.io/badge/patreon-become%20a%20patron-red.svg)](https://www.patreon.com/mopemope) +[![Patreon](https://img.shields.io/badge/patreon-become%20a%20patron-red.svg)](https://www.patreon.com/mopemope) ## A Better Java Development Environment for Emacs @@ -10,22 +10,21 @@ package and [meghanada-server][]. **Features:** -* Easy install -* Auto-update server module -* [Gradle][] and [Maven][] and Eclipse project support -* No need build tool's plugin -* Run build tool task -* Compile your project -* Syntax check and analyze java source (`flycheck-meghanada`) -* Support `Generic Types` -* Code completion with [company-mode][] (`company-meghanada`) -* Optimize import and sort -* Jump declaration -* Run [JUnit][] test (include test runner) -* Diagnostic reporting with [flycheck][] (`flycheck-meghanada`) -* Show symbol's type info with `el-doc` -* Search references -* Full-featured text search +- Easy install +- Auto-update server module +- [Gradle][] and [Maven][] and [Eclipse][] project support +- No need build tool's plugin +- Run build tool task +- Compile your project +- Syntax check and analyze java source (`flycheck-meghanada`) +- Support `Generic Types` and `Lambda` +- Code completion with [company-mode][] (`company-meghanada`) +- Optimize import and sort +- Find definitions and references using builtin [xref][] +- Run [JUnit][] test (include test runner) +- Diagnostic reporting with [flycheck][] (`flycheck-meghanada`) +- Show symbol's type info with `el-doc` +- Full-featured text search `Meghanada` is tested under `Linux`, `Windows` and `macOS`. @@ -37,33 +36,24 @@ Meghanada has been developed Emacs 25.1.1 ### Elisp dependencies -| Package | Version | -| -------------------- | --------------------------------- | -| `cl-lib` | 0.5 | -| [yasnippet][] | 0.6.1 | -| [company-mode][] | 0.9.0 | -| [flycheck][] | 0.23 | +| Package | Version | +| ---------------- | ------- | +| `cl-lib` | 0.5 | +| [yasnippet][] | 0.6.1 | +| [company-mode][] | 0.9.0 | +| [flycheck][] | 0.23 | -### Meghanada-Server +### Language Server `meghanada-mode` require [meghanada-server][] and JDK (not JRE). -[meghanada-server][] provides an interface to `meghanada-mode`. It uses a simple protocol -based on S-expressions. This server, written in Java, requires the following -packages to be installed on your system: - -* JDK 1.8 or later - -The Meghanada architecture is almost the same as `ensime`. It is a client-server model. - -Meghanada updates any information when saving and compile the java file. - -If the completion candidate and others are incorrect, please fix the compile error. - -### Telemetry -If you can help improve server performance etc. please enable Telemetry. +[meghanada-server][] is The language server. +The language server provides a simple interface between `meghanada-mode` and It is a protocol based on a simple S-expression. +This server is developed in Java and supports Java version 8 or later. -If you allow Meghanada to submit performance data, the Telemetry system will collect and submit various measurement data from the user environment, such as Meghanada's performance. +The architecture between the server and the client is very similar to the language server protocol. +The server retrieves and updates all information in the Java project at file save time and at compile time. +If the autocompletion information is not displayed correctly, please try to fix the compilation error first. ## Installation @@ -73,14 +63,14 @@ Install meghanada from melpa. #### Configuration +An example is shown below. + ```elisp (require 'meghanada) (add-hook 'java-mode-hook (lambda () ;; meghanada-mode on (meghanada-mode t) - ;; enable telemetry - (meghanada-telemetry-enable t) (flycheck-mode +1) (setq c-basic-offset 2) ;; use code format @@ -98,7 +88,7 @@ Install meghanada from melpa. The server will be automatically installed to `~/.emacs.d/meghanada/meghanada-x.x.jar`. -If you open a java file and set `meghanada-mode`, a [meghanada-server][] process starts automatically and connects to your emacs. +If you open a java file and set `meghanada-mode`, a [meghanada-server][] process starts automatically and connects to your Emacs. ### Updating @@ -127,21 +117,76 @@ Start Emacs and enable meghanada-mode. ## Autocompletion -Auto-completion is supported by `company-mode`. +Autocompletion is supported by company-mode. +Supported autocompletions are as follows + +- Import Class +- Class +- Method +- Field +- Local Variable + +If the completion candidates are not displayed correctly, try to fix the compilation error first. +Auto-completion matching is optional. Try typing the following to find out more. -Completion matcher is selectable. see type `M-x customize-group RET meghanada`. +`M-x customize-group RET meghanada` and `M-x customize-group RET company-meghanada`. ## Syntax/error checking -Error checking is supported by `flycheck`. + +Syntax checks, such as compile errors, are supported by `flycheck`. +This includes `-Xlint` warnings. + +## Code formatter + +`meghanada-mode` uses `google-java-format` by default for formatter. + +It also support [Eclipse][] formatter. + +If you want to customize and use the [Eclipse][] formatter please export the formatter settings from [Eclipse][] to a file. + +Then rename the file to `meghanadaFormatter.xml` and place it in the project root or subproject root. +`Meghanada` will automatically load and import it. + +If you want to use a system wide formatter, deploy the file to `$HOME/.emacs.d/meghanada/meghanadaFormatter.xml`. + +## Debug + +`meghanada-mode` has no debugger yet. However, the external debugger is supported. + +if you want to debug your code, execute `meghanada-debug-xxxx` function and then use [realgud][], etc. + +``` +# in Emacs now: + M-x meghanada-debug-junit-class + Please wait ... + M-x realgud:jdb + Run jdb (like this): jdb -attach 6006 + Set uncaught java.lang.Throwable + Set deferred uncaught java.lang.Throwable + Initializing jdb ... + > + VM Started: No frames on the current call stack + + main[1] stop at example.MyClass:100 // set breakpoint + main[1] run +``` ## Customize -To customize other aspects of its behavior, type `M-x customize-group RET meghanada`. +To customize other aspects of its behavior, type `M-x customize-group RET meghanada` and `M-x customize-group RET company-meghanada`. + +## Troubleshooting + +See `*meghanada-server-log*` buffer. or `(temporary-file-directory)meghanada_server_(user-uid).log`, e.g. `/tmp/meghanada_server_1000.log`. + +Please press `C-g` when emacs seems to hang. ## Usage Here is a list of available interactive commands. +Definitions and references can be found from the [xref][] command. + ### meghanada-install-server Download and install [meghanada-server] jar. @@ -226,10 +271,6 @@ Run main class. Debug main class. -### meghanada-reference - -Find usage (method call, field access, class). - ### meghanada-search-everywhere It does a full-text search based search (class, method, symbol (field)). @@ -240,12 +281,12 @@ It does a full-text search expert-mode (Enter a query for Lucene). Here is a list of fields that can be used in the search. -* package -* class -* method -* symbol -* usage -* dc (method's or field's declaring class) +- package +- class +- method +- symbol +- usage +- dc (method's or field's declaring class) ex. Seach class name contains `Search`. @@ -259,7 +300,6 @@ It can also use `AND operator`. dc:*Optional* AND usage:get ``` - ### meghanada-typeinfo Show type hierarchies and implements interfaces. @@ -284,139 +324,13 @@ Debug JUnit test case (select from imenu). Run build tool task. -### meghanada-jump-declaration (M-.) - -Goto declaration. - -### meghanada-back-jump (M-,) - -Go back from declaration position. - ### meghanada-code-beautify Format buffer code. The default formatter is `google-java-format` -## Customize code formatter - -`meghanada-mode` uses `google-java-format` by default for formatter. - -It also supports Eclipse formatter. -If you want to customize the formatter, you use the exported eclipse format settings. -To import the settings, change the name of the exported file to `meghanadaFormatter.xml` and put it in the `project root` or `subproject root`. - -## Debug - -`meghanada-mode` has no debugger yet. However, the external debugger is supported. - -if you want to debug your code, execute `meghanada-debug-xxxx` function and then use [realgud][], etc. - -``` -# in Emacs now: - M-x meghanada-debug-junit-class - Please wait ... - M-x realgud:jdb - Run jdb (like this): jdb -attach 6006 - Set uncaught java.lang.Throwable - Set deferred uncaught java.lang.Throwable - Initializing jdb ... - > - VM Started: No frames on the current call stack - - main[1] stop at example.MyClass:100 // set breakpoint - main[1] run -``` - -## Troubleshooting - -See `*meghanada-server-log*` buffer. or `(temporary-file-directory)meghanada_server_(user-uid).log`, e.g. `/tmp/meghanada_server_1000.log`. - -Please press `C-g` when emacs seems to hang. - -## Setting example - -```elisp -(use-package autodisass-java-bytecode - :ensure t - :defer t) - -(use-package google-c-style - :defer t - :ensure t - :commands - (google-set-c-style)) - -(use-package meghanada - :defer t - :init - (add-hook 'java-mode-hook - (lambda () - (google-set-c-style) - (google-make-newline-indent) - (meghanada-mode t) - (smartparens-mode t) - (rainbow-delimiters-mode t) - (highlight-symbol-mode t) - (add-hook 'before-save-hook 'meghanada-code-beautify-before-save))) - - :config - (use-package realgud - :ensure t) - (setq indent-tabs-mode nil) - (setq tab-width 2) - (setq c-basic-offset 2) - (setq meghanada-server-remote-debug t) - (setq meghanada-javac-xlint "-Xlint:all,-processing") - :bind - (:map meghanada-mode-map - ("C-S-t" . meghanada-switch-testcase) - ("M-RET" . meghanada-local-variable) - ("C-M-." . helm-imenu) - ("M-r" . meghanada-reference) - ("M-t" . meghanada-typeinfo) - ("C-z" . hydra-meghanada/body)) - :commands - (meghanada-mode)) - -(defhydra hydra-meghanada (:hint nil :exit t) -" -^Edit^ ^Tast or Task^ -^^^^^^------------------------------------------------------- -_f_: meghanada-compile-file _m_: meghanada-restart -_c_: meghanada-compile-project _t_: meghanada-run-task -_o_: meghanada-optimize-import _j_: meghanada-run-junit-test-case -_s_: meghanada-switch-test-case _J_: meghanada-run-junit-class -_v_: meghanada-local-variable _R_: meghanada-run-junit-recent -_i_: meghanada-import-all _r_: meghanada-reference -_g_: magit-status _T_: meghanada-typeinfo -_l_: helm-ls-git-ls -_q_: exit -" - ("f" meghanada-compile-file) - ("m" meghanada-restart) - - ("c" meghanada-compile-project) - ("o" meghanada-optimize-import) - ("s" meghanada-switch-test-case) - ("v" meghanada-local-variable) - ("i" meghanada-import-all) - - ("g" magit-status) - ("l" helm-ls-git-ls) - - ("t" meghanada-run-task) - ("T" meghanada-typeinfo) - ("j" meghanada-run-junit-test-case) - ("J" meghanada-run-junit-class) - ("R" meghanada-run-junit-recent) - ("r" meghanada-reference) - - ("q" exit) - ("z" nil "leave")) -``` - ## TODO -* Refactoring +- Refactoring ## Contributing @@ -426,13 +340,13 @@ Contributions are extremely welcome! Please push PR to `dev` branch. GPL v3, See [LICENSE](LICENSE) file. - - [meghanada-server]: https://github.com/mopemope/meghanada-server -[Maven]: http://maven.apache.org/ -[Gradle]: https://gradle.org +[maven]: http://maven.apache.org/ +[gradle]: https://gradle.org +[eclipse]: https://www.eclipse.org/ [company-mode]: http://company-mode.github.io/ [flycheck]: https://www.flycheck.org/ -[JUnit]: http://www.junit.org/ +[junit]: http://www.junit.org/ [yasnippet]: http://joaotavora.github.io/yasnippet/ [realgud]: https://github.com/realgud/realgud +[xref]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html