diff --git a/.gitignore b/.gitignore index 1881c08..c4afe86 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ byte-compile.el *.jar meghanada-autoloads.el meghanada-pkg.el +*.txt \ No newline at end of file diff --git a/README.md b/README.md index 651e623..ae4119b 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ ## A Better Java Development Environment for Emacs `Meghanada` is a new minor-mode (`meghanada-mode`) that aims at improving the editing -experience for the Java. It works by using a combination of an Emacs +experience for Java. It works by using a combination of an Emacs package and [meghanada-server][]. **Features:** * Easy install -* Auto update server module +* Auto-update server module * [Gradle][] and [Maven][] and Eclipse project support * No need build tool's plugin * Run build tool task @@ -21,13 +21,13 @@ package and [meghanada-server][]. * Code completion with [company-mode][] (`company-meghanada`) * Optimize import and sort * Jump declaration -* Run [Junit][] test (include test runner) +* 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 -`Meghanada` is tested under `linux`, `Windows` and `macOS`. +`Meghanada` is tested under `Linux`, `Windows` and `macOS`. (Welcome contributions !) @@ -48,12 +48,12 @@ Meghanada has been developed Emacs 25.1.1 `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 +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 client server model. +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. @@ -94,25 +94,41 @@ If you open a java file and set `meghanada-mode`, a [meghanada-server][] process ### Updating -The server will be automatically updated.To manually update bellows, type +The server will be automatically updated. To manually update bellows, type ``` M-x meghanada-update-server ``` -## Auto completion +### Manual Server Installation -Auto completion is supported by `comapany-mode`. +The server will be installed and updated automatically. + +If you set it up manually, please follow the instructions below. + +#### Download meghanada-setup.jar + +A meghanada-setup.jar is a small program that automatically updates the server. + +This can be downloaded from: + +https://github.com/mopemope/meghanada-server/releases/download/v1.0.13/meghanada-setup-0.0.2.jar + +Move the downloaded setup.jar to .emacs.d/meghanada/. +Start Emacs and enable meghanada-mode. + +## Autocompletion + +Auto-completion is supported by `company-mode`. Completion matcher is selectable. see type `M-x customize-group RET meghanada`. ## Syntax/error checking - Error checking is supported by `flycheck`. ## 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`. ## Usage @@ -124,11 +140,11 @@ Download and install [meghanada-server] jar. ### meghanada-update-server -Download and update [meghanada-server] jar. and restart server process. +Download and update [meghanada-server] jar. and restart the server process. ### meghanada-server-start -Start [meghanada-server][] process and connect to server. +Start [meghanada-server][] process and connect to the server. `meghanada-mode` call this function by default. when open java file and set `meghanada-mode`. @@ -192,7 +208,7 @@ Compile project (full build and reindex). ### meghanada-switch-testcase (C-M-,) -Switch testcase or source. +Switch test case or source. ### meghanada-exec-main @@ -208,11 +224,11 @@ Find usage (method call, field access, class). ### meghanada-search-everywhere -It does a full text search based search (class, method, symbol (field)). +It does a full-text search based search (class, method, symbol (field)). ### meghanada-search-everywhere-ex -It does a full text search expert-mode (Enter a query for Lucene). +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. @@ -221,9 +237,9 @@ Here is a list of fields that can be used in the search. * method * symbol * usage -* dc (method's or field's declaringClass) +* dc (method's or field's declaring class) -ex. Seach class name contains `Search` . +ex. Seach class name contains `Search`. ``` class:*Search* @@ -242,19 +258,19 @@ Show type hierarchies and implements interfaces. ### meghanada-run-junit-class (C-c C-c C-t) -Run Junit test class. +Run JUnit test class. ### meghanada-run-junit-test-case (C-c C-c t) -Run Junit testcase (select from imenu). +Run JUnit test case (select from imenu). ### meghanada-debug-junit-class (C-c C-c C-t) -Debug Junit test class. +Debug JUnit test class. ### meghanada-debug-junit-test-case (C-c C-c t) -Debug Junit testcase (select from imenu). +Debug JUnit test case (select from imenu). ### meghanada-run-task (C-c C-v t) @@ -276,15 +292,15 @@ Format buffer code. The default formatter is `google-java-format` `meghanada-mode` uses `google-java-format` by default for formatter. -It also supports eclipse formatter. -If you want to customize the formatter, you uses the exported eclipse format settings. +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, external debugger is supported. +`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. +if you want to debug your code, execute `meghanada-debug-xxxx` function and then use [realgud][], etc. ``` # in Emacs now: @@ -304,7 +320,7 @@ if you want to debug your code, execute `meghanada-debug-xxxx` function and then ## Troubleshooting -See `*meghanada-server-log*` buffer. or `/tmp/meghanada_server.log`. +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. @@ -409,6 +425,6 @@ GPL v3, See [LICENSE](LICENSE) file. [Gradle]: https://gradle.org [company-mode]: http://company-mode.github.io/ [flycheck]: http://flycheck.org -[Junit]: http://www.junit.org/ +[JUnit]: http://www.junit.org/ [yasnippet]: http://joaotavora.github.io/yasnippet/ [realgud]: https://github.com/realgud/realgud diff --git a/RELEASES.md b/RELEASES.md index 2fbd649..42852c6 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,11 @@ +# Version 1.0.14 (2019-04-26) + +* works without the project tool (mvn, gradle, etc). +* support java 12 (experimental). +* add jvm option setting (meghanada-jvm-option). +* support company-box. +* fix some bugs and improve stability. + # Version 1.0.13 (2019-02-25) * support build.gradle.kts. diff --git a/company-meghanada.el b/company-meghanada.el index 3c83b2f..29f5786 100644 --- a/company-meghanada.el +++ b/company-meghanada.el @@ -26,7 +26,8 @@ ;;; Code: (eval-when-compile - (require 'cl-lib)) + (require 'cl-lib) + (require 'pcase)) (require 'company) (require 'company-template) @@ -61,8 +62,6 @@ (defun meghanada-company-enable () "Enable auto completion with company." (company-mode t) - (set (make-local-variable 'company-backends) nil) - (set (make-local-variable 'company-transformers) nil) (if company-meghanada-prefix-length (set (make-local-variable 'company-minimum-prefix-length) company-meghanada-prefix-length) (set (make-local-variable 'company-meghanada-prefix-length) company-minimum-prefix-length)) @@ -75,6 +74,17 @@ (yas-minor-mode t) (make-local-variable 'yas-minor-mode-map)) +(defun make-icon-hash (type) + (let ((kind-val (pcase type + ("VARIABLE" 6) + ("METHOD" 2) + ("CONSTRUCTOR" 2) + ("FIELD" 5) + ("CLASS" 22))) + (ht (make-hash-table :test 'equal))) + (puthash "kind" kind-val ht) + ht)) + (defun company-meghanada--to-candidate (result) (mapcar (lambda (candidate) (propertize (nth 1 candidate) @@ -87,7 +97,9 @@ 'return-type (nth 4 candidate) 'extra - (nth 5 candidate))) result)) + (nth 5 candidate) + 'lsp-completion-item + (make-icon-hash (nth 0 candidate)))) result)) (defun company-meghanada--to-candidates (output) (when (> (length output) 0) @@ -213,7 +225,6 @@ (concat "*" var "#" prefix))) (t match)))) - ;; (message (format "match:%s send-keyword:%s" match keyword)) (setq meghanada--sp-prefix keyword) (cons symbol t)) symbol))))) @@ -285,9 +296,7 @@ (beginning-of-thing 'symbol) (end-of-thing 'symbol) (list 'return-type return-t 'meta meta 'type 'method)))) - (when anno - (insert anno) (company-template-c-like-templatify anno) (when (and (> (length extra) 1) @@ -340,7 +349,6 @@ (meta (get-text-property 0 'meta arg)) (desc (get-text-property 0 'desc arg)) (anno (company-meghanada--annotation arg))) - ;;(message (format "@ arg:%s meta:%s desc:%s anno:%s" arg meta desc anno)) (meghanada-autocomplete-resolve-async type arg @@ -362,8 +370,7 @@ (backward-word) (insert meta) (insert ";") - (delete-region (point) (+ (point) (length arg))) - ))))) + (delete-region (point) (+ (point) (length arg)))))))) (defun company-meghanada (command &optional arg &rest ignored) (cl-case command @@ -378,10 +385,7 @@ (ignore-case t) (sorted t) (no-cache - (unless - (and - (string= "prefix" meghanada-completion-matcher) - (string= "prefix" meghanada-class-completion-matcher)) + (unless (and (string= "prefix" meghanada-completion-matcher) (string= "prefix" meghanada-class-completion-matcher)) t)) (require-match 'never) (post-completion diff --git a/meghanada.el b/meghanada.el index 0e204b1..dc12f43 100644 --- a/meghanada.el +++ b/meghanada.el @@ -6,7 +6,7 @@ ;; Author: Yutaka Matsubara (yutaka.matsubara@gmail.com) ;; Homepage: https://github.com/mopemope/meghanada-emacs ;; Keywords: languages java -;; Package-Version: 1.0.13 +;; Package-Version: 1.0.14 ;; Package-Requires: ((emacs "24.3") (yasnippet "0.6.1") (company "0.9.0") (flycheck "0.23")) ;; This program is free software; you can redistribute it and/or modify @@ -48,7 +48,7 @@ ;; Const ;; -(defconst meghanada-version "1.0.13") +(defconst meghanada-version "1.0.14") (defconst meghanada-setup-version "0.0.2") (defconst meghanada--eot "\n;;EOT\n") (defconst meghanada--junit-buf-name "*meghanada-junit*") @@ -170,6 +170,14 @@ In linux or macOS, it can be \"mvn\"; In Windows, it can be \"mvn.cmd\". " :group 'meghanada :type 'boolean) +(defcustom meghanada-jvm-option nil + "Set to all meghanada java process jvm option. + +Example. (setq meghanada-jvm-option \"-Dhttp.proxyHost=test.proxy.com -Dhttp.proxyPort=8080\") +" + :group 'meghanada + :type 'string) + (defcustom meghanada-server-jvm-option "-Xms128m -XX:ReservedCodeCacheSize=240m -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false" "Set to meghanada server process jvm option." :group 'meghanada @@ -210,8 +218,8 @@ In linux or macOS, it can be \"mvn\"; In Windows, it can be \"mvn.cmd\". " :group 'meghanada :type 'function) -(defcustom meghanada-cache-in-project t - "If true, create a cache in the project.otherwise, create in cache root directory (~/.cache/meghanada)." +(defcustom meghanada-cache-in-project nil + "If true, create a cache in the project.otherwise, create in cache root directory (~/.cache/meghanada). default nil" :group 'meghanada :type 'boolean) @@ -374,13 +382,20 @@ function." (meghanada--download-setup-jar) (meghanada--run-setup)) +(defun meghanada--setup-options () + (let ((options '())) + (when meghanada-jvm-option + (push meghanada-jvm-option options)) + (mapconcat 'identity options " "))) + (defun meghanada--run-setup () "Setup meghanada server module." (let ((jar (meghanada--locate-setup-jar)) (dest meghanada-server-install-dir)) (if (file-exists-p jar) - (let ((cmd (format "%s -jar %s --dest %s --server-version %s --simple" + (let ((cmd (format "%s %s -jar %s --dest %s --server-version %s --simple" (shell-quote-argument meghanada-java-path) + (meghanada--setup-options) (shell-quote-argument jar) (expand-file-name dest) meghanada-version))) @@ -500,10 +515,10 @@ function." (push (format "-Dmeghanada.completion.matcher=%s" meghanada-completion-matcher) options)) (when meghanada-class-completion-matcher (push (format "-Dmeghanada.class.completion.matcher=%s" meghanada-class-completion-matcher) options)) + (when meghanada-jvm-option + (push meghanada-jvm-option options)) (push "-Djava.net.preferIPv4Stack=true" options) - (mapconcat 'identity - options - " "))) + (mapconcat 'identity options " "))) (defun meghanada--start-server-process () "TODO: FIX DOC ." @@ -511,13 +526,14 @@ function." (if (file-exists-p jar) (let ((process-connection-type nil) (process-adaptive-read-buffering nil) - (cmd (format "%s %s %s -Dfile.encoding=UTF-8 -jar %s -p %d %s" + (cmd (format "%s %s %s -Dfile.encoding=UTF-8 -jar %s -p %d %s %s" (shell-quote-argument meghanada-java-path) (meghanada--server-options) meghanada-server-jvm-option (shell-quote-argument jar) meghanada-port - (if meghanada-debug "-v" ""))) + (if meghanada-debug "-v" "") + (concat "-l " (temporary-file-directory) "meghanada_server_" (number-to-string (user-uid)) ".log"))) process) (message (format "launch server cmd:%s" cmd)) (setq process