Lsp-mode: [Feature request] support org-mode source code blocks

Created on 11 Jun 2018  路  39Comments  路  Source: emacs-lsp/lsp-mode

It will be great if can use lsp when editing source code block in temporary buffer *Org Src FILENAME [ LANG ]* for org-mode.

enhancement

Most helpful comment

I did some research as per @stardiviner comment at https://github.com/emacs-lsp/lsp-mode/pull/409 .

Here it is how you can do it for java. This code requires

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (lsp)
  ;; other lsp-java specific stuff that you usually run with the major mode, company mode and so on.
  )

Then in the org mode file you should specify the root of the project. Note that you have to do the java specific setup as per guide in lsp-java. Configure the file-name so lsp-mode could create workspace for it.

#+BEGIN_SRC java :file-name "/home/yyoncho/Sources/lsp/dap-mode/features/fixtures/test-project/src/main/java/temp/App.java"
  package temp;

  class App {
    public static void main(String[] args) {
      System.out.print(123);
    }
  }

#+END_SRC

After that you can go into the src block and press C-c-' which will popup a buffer with autocompletion, etc. You may ping me here or in gitter if you need some help with configuring this.

All 39 comments

IMO this integration must go in org-mode similar to the other language adapters. The lsp-mode already provides the required facilities to accomplish what you want.

I did some research as per @stardiviner comment at https://github.com/emacs-lsp/lsp-mode/pull/409 .

Here it is how you can do it for java. This code requires

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (lsp)
  ;; other lsp-java specific stuff that you usually run with the major mode, company mode and so on.
  )

Then in the org mode file you should specify the root of the project. Note that you have to do the java specific setup as per guide in lsp-java. Configure the file-name so lsp-mode could create workspace for it.

#+BEGIN_SRC java :file-name "/home/yyoncho/Sources/lsp/dap-mode/features/fixtures/test-project/src/main/java/temp/App.java"
  package temp;

  class App {
    public static void main(String[] args) {
      System.out.print(123);
    }
  }

#+END_SRC

After that you can go into the src block and press C-c-' which will popup a buffer with autocompletion, etc. You may ping me here or in gitter if you need some help with configuring this.

@yyoncho After tried your method, I still can't get completion. But it does not report error on lsp workspace. Here is the value of lsp--cur-workspace:

#1=#s(lsp--workspace :parser #s(lsp--parser :waiting-for-response nil :response-result #<hash-table equal 1/65 0x5195759> :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "" :queued-notifications nil :queued-requests nil :workspace #1#)
:file-versions #<hash-table equal 0/65 0x5112261> :server-capabilities nil :registered-server-capabilities nil :root "/home/stardiviner/Org/" :client #s(lsp--client :language-id #f(compiled-function
(_)
#<bytecode 0x5110279>)
:send-sync nil :send-async nil :type nil :new-connection #f(compiled-function
(filter sentinel)
#<bytecode 0x51102c5>)
:stderr #2="*lsp-javacomp stderr*" :get-root lsp-javacomp--get-root :ignore-regexps
("^SLF4J: " "^Listening for transport dt_socket at address: ")
:ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x51102d1> :request-handlers #<hash-table equal 0/65 0x5110375> :response-handlers #<hash-table eql 0/65 0x5111779> :string-renderers nil :last-id 1 :enable-function lsp-javacomp-enable :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x5111bb9> :action-handlers #<hash-table equal 0/65 0x5111e91> :default-renderer nil :use-native-json nil)
:change-timer-disabled nil :proc #<process lsp-javacomp> :cmd-proc #<process lsp-javacomp> :buffers nil :highlight-overlays #<hash-table eq 0/65 0x5112389> :extra-client-capabilities nil :status nil :metadata #<hash-table equal 0/65 0x5112f7d> :watches #<hash-table equal 0/65 0x511331d>)

Local in buffer *Org Src Code.org[ java ]*; global value is nil

Did you enable all the modes you need as per lsp-java guide?

Here it is the full code:

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (lsp-java-enable)
  (push 'company-lsp company-backends)
  (lsp-ui-mode t)
  (flycheck-mode t)
  (company-mode t)
  (lsp-ui-flycheck-enable t))

Yes, I use lsp-javacomp instead so I use lsp-javacomp-enable instead of lsp-java-enable here.

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (lsp-javacomp-enable)
  (lsp-ui-mode t)
  ;; other lsp-java specific stuff that you usually run with the major mode, company mode and so on.
  (company-mode t))

I think lsp-ui-flycheck-enable is unrelated with this completion issue.
And here is my org source code:

#+BEGIN_SRC java :file-name "~/IdeaProjects/JavaTest/src/stardiviner/test/Main.java"
package stardiviner.test;

public class Main {

    public static void main(String[] args) {
        // write your code here
        System.out.println("Hello, World!");
    }
}
#+END_SRC

I get this error when I open source block:

Debugger entered--Lisp error: (lsp-timed-out-error)
  signal(lsp-timed-out-error nil)
  lsp--send-wait("Content-Length: 674\015\n\015\n{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"params\":{\"processId\":2407,\"rootPath\":\"/home/stardiviner/Org/\",\"rootUri\":\"file:///home/stardiviner/Org/\",\"capabilities\":{\"workspace\":{\"applyEdit\":true,\"executeCommand\":{\"dynamicRegistration\":true}},\"textDocument\":{\"synchronization\":{\"willSave\":true,\"didSave\":true,\"willSaveWaitUntil\":true},\"documentSymbol\":{\"symbolKind\":{\"valueSet\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},\"hierarchicalDocumentSymbolSupport\":true},\"formatting\":{\"dynamicRegistration\":true},\"codeAction\":{\"dynamicRegistration\":true}}},\"initializationOptions\":{\"logPath\":null,\"logLevel\":null,\"ignorePths\":null,\"typeIndexFiles\":null}},\"id\":1}" #<process lsp-javacomp> #s(lsp--parser :waiting-for-response t :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received 0 :leftovers nil :queued-notifications nil :queued-requests nil :workspace #s(lsp--workspace :parser #1 :file-versions #<hash-table equal 0/65 0x5dfbf6d> :server-capabilities nil :registered-server-capabilities nil :root "/home/stardiviner/Org/" :client #s(lsp--client :language-id #f(compiled-function (_) #<bytecode 0x2aeb181>) :send-sync nil :send-async nil :type nil :new-connection #f(compiled-function (filter sentinel) #<bytecode 0x35edae1>) :stderr "*lsp-javacomp stderr*<3>" :get-root lsp-javacomp--get-root :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x35edaed> :request-handlers #<hash-table equal 0/65 0x35eddc5> :response-handlers #<hash-table eql 0/65 0x35edde5> :string-renderers nil :last-id 1 :enable-function lsp-javacomp-enable :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x35ede05> :action-handlers #<hash-table equal 0/65 0x34a5fa9> :default-renderer nil :use-native-json nil) :change-timer-disabled nil :proc #<process lsp-javacomp> :cmd-proc #<process lsp-javacomp> :buffers nil :highlight-overlays #<hash-table eq 0/65 0x5dfc119> :extra-client-capabilities nil :status nil :metadata #<hash-table equal 0/65 0x5dfc139> :watches #<hash-table equal 0/65 0x2bad935>)))
  lsp--send-request((:jsonrpc "2.0" :method "initialize" :params (:processId 2407 :rootPath "/home/stardiviner/Org/" :rootUri "file:///home/stardiviner/Org/" :capabilities (:workspace (:applyEdit t :executeCommand (:dynamicRegistration t)) :textDocument (:synchronization (:willSave t :didSave t :willSaveWaitUntil t) :documentSymbol (:symbolKind (:valueSet [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25]) :hierarchicalDocumentSymbolSupport t) :formatting (:dynamicRegistration t) :codeAction (:dynamicRegistration t))) :initializationOptions (:logPath nil :logLevel nil :ignorePths nil :typeIndexFiles nil)) :id 1))
  lsp--start(#s(lsp--client :language-id #f(compiled-function (_) #<bytecode 0x2aeb181>) :send-sync nil :send-async nil :type nil :new-connection #f(compiled-function (filter sentinel) #<bytecode 0x35edae1>) :stderr "*lsp-javacomp stderr*<3>" :get-root lsp-javacomp--get-root :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x35edaed> :request-handlers #<hash-table equal 0/65 0x35eddc5> :response-handlers #<hash-table eql 0/65 0x35edde5> :string-renderers nil :last-id 1 :enable-function lsp-javacomp-enable :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x35ede05> :action-handlers #<hash-table equal 0/65 0x34a5fa9> :default-renderer nil :use-native-json nil) lsp-javacomp--get-init-params)
  lsp--enable-stdio-client(lsp-javacomp :language-id "java" :language-id-fn nil :root-directory-fn lsp-javacomp--get-root :command nil :command-fn lsp-javacomp--command :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :extra-init-params lsp-javacomp--get-init-params :initialize-fn nil :enable-function lsp-javacomp-enable :prefix-function nil)
  lsp-javacomp-enable()
  org-babel-edit-prep:java(("java" "package stardiviner.test;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        // write your code here\n        System.out.println(\"Hello, World!\");\n    }\n}" ((:results . "output replace") (:exports . "") (:file-name . "~/IdeaProjects/JavaTest/src/stardiviner/test/Main.java") (:eval . "never-export") (:cache . "yes") (:comments . "links") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:session . "none")) "" nil 277021 "(ref:%s)"))
  funcall(org-babel-edit-prep:java ("java" "package stardiviner.test;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        // write your code here\n        System.out.println(\"Hello, World!\");\n    }\n}" ((:results . "output replace") (:exports . "") (:file-name . "~/IdeaProjects/JavaTest/src/stardiviner/test/Main.java") (:eval . "never-export") (:cache . "yes") (:comments . "links") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:session . "none")) "" nil 277021 "(ref:%s)"))
  (progn (funcall edit-prep-func babel-info))
  (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))
  (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info))))
  (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))
  (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info))))))
  (let* ((lang (if (eq type 'src-block) (org-element-property :language element) "example")) (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang))) (babel-info (and (eq type 'src-block) (org-babel-get-src-block-info 'light))) deactivate-mark) (if (and (eq type 'src-block) (not (functionp lang-f))) (progn (error "No such language mode: %s" lang-f))) (org-src--edit-element element (or edit-buffer-name (org-src--construct-edit-buffer-name (buffer-name) lang)) lang-f (and (null code) (function (lambda nil (org-escape-code-in-region (point-min) (point-max))))) (and code (org-unescape-code-in-string code))) (set (make-local-variable 'org-coderef-label-format) (or (org-element-property :label-fmt element) org-coderef-label-format)) (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))) t)
  (let* ((element (org-element-at-point)) (type (org-element-type element))) (if (and (memq type '(example-block src-block)) (org-src--on-datum-p element)) nil (user-error "Not in a source or example block")) (let* ((lang (if (eq type 'src-block) (org-element-property :language element) "example")) (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang))) (babel-info (and (eq type 'src-block) (org-babel-get-src-block-info 'light))) deactivate-mark) (if (and (eq type 'src-block) (not (functionp lang-f))) (progn (error "No such language mode: %s" lang-f))) (org-src--edit-element element (or edit-buffer-name (org-src--construct-edit-buffer-name (buffer-name) lang)) lang-f (and (null code) (function (lambda nil (org-escape-code-in-region (point-min) (point-max))))) (and code (org-unescape-code-in-string code))) (set (make-local-variable 'org-coderef-label-format) (or (org-element-property :label-fmt element) org-coderef-label-format)) (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))) t))
  org-edit-src-code()

It reminds "time out", so I wait for a while, about 1 minute, the opened source block buffer still can't get completion.

I guss the root path is wrong (I guess from the result). It is /home/stardiviner/Org/ which is not the project root which should be ~/IdeaProjects/JavaTest/. But I don't know how to modify this in lsp--cur-workspace structured value.

@stardiviner Sorry, I do not know how javacomp work I can help you only with lsp-java.

@yyoncho I tried lsp-java now.
It reports error:

Debugger entered--Lisp error: (error "Unable to find single point of entry (/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.0.v20180207-1446.jar /home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar)")
  signal(error ("Unable to find single point of entry (/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.0.v20180207-1446.jar /home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar)"))
  error("Unable to find single point of entry (/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.0.v20180207-1446.jar /home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar)")
  lsp-java--locate-server-jar()
  lsp-java--ls-command()
  #f(compiled-function () (interactive nil) #<bytecode 0x3132685>)()
  apply(#f(compiled-function () (interactive nil) #<bytecode 0x3132685>) nil)
  #f(advice-wrapper :after #f(compiled-function () (interactive nil) #<bytecode 0x3132685>) lsp-java--after-start)()
  apply(#f(advice-wrapper :after #f(compiled-function () (interactive nil) #<bytecode 0x3132685>) lsp-java--after-start) nil)
  lsp-java-enable()

Can you delete ~/.emacs.d/eclipse.jdt.ls folder and retry? You have 2 versions of the server. Also, to make sure that lsp-java work you should have configured lsp-java--workspace-folders properly, e. g. You should include the project that contains the file you want to edit. In your case lsp-java--workspace-folders should be (list "~/IdeaProjects/JavaTest/") assuming that you have maven project in that folder.

  • [X] lsp-java--workspace-folders
  • [X] delete ~/.emacs.d/eclipse.jdt.ls/

When I open the source block, the minibuffer shows following messages, I checked out from *Messages* buffer.

using config for config_linux
lsp--set-sync-method: Wrong type argument: hash-table-p, nil
2018-10-7 18:19:36 >> document/didOpen
2018-10-7 18:19:37 Classpath is incomplete. Only syntax errors will be reported for file:///home/stardiviner/IdeaProjects/JavaTest/src/stardiviner/test/Main.java
Validate documents - 0%
Validate documents - 25%
Validate documents - 75%
Validate documents - 100% (done)
2018-10-7 18:19:39 begin problem for /Main.java
2018-10-7 18:19:39 0 problems reported for /Main.java
error in process filter: lsp--update-code-lenses: Wrong type argument: hash-table-p, nil
error in process filter: Wrong type argument: hash-table-p, nil
Building workspace - 65%
Building workspace - 100% (done) [4 times]

How can I dig deeper?

When I open the source block again:
The log is:

Error in auto-save-hook (lsp--on-auto-save): (wrong-type-argument hash-table-p nil)
/home/stardiviner/.emacs.d/workspace/: lsp-java has exited (killed)
using config for config_linux
2018-10-7 18:23:18 Main thread is waiting
2018-10-7 18:23:18 >> initialize
2018-10-7 18:23:18 Initializing Java Language Server 0.27.0.201810051359
Init...[Starting]
0% Starting Java Language Server [Starting]
Refreshing Maven model
20% Starting Java Language Server [Starting]
2018-10-7 18:23:19 Creating the default Java project
2018-10-7 18:23:19 Finished creating the default Java project
Configuring package lsp-ui...done (0.111s)
2018-10-7 18:23:19 >> initialized
Refreshing Maven model
37% Starting Java Language Server [Starting]
100% Starting Java Language Server [Starting] [2 times]
2018-10-7 18:23:20 Workspace initialized in 2115ms
Ready[Started]
2018-10-7 18:23:20 >> workspace/didChangeConfiguration
2018-10-7 18:23:20 >> registerFeature 'workspace/didChangeWatchedFiles'
2018-10-7 18:23:21 >>New configuration: {intellij={temporaryDirectory=file:///tmp/}}
2018-10-7 18:23:21 >> document/didOpen
2018-10-7 18:23:21 Classpath is incomplete. Only syntax errors will be reported for file:///home/stardiviner/IdeaProjects/JavaTest/src/stardiviner/test/Main.java
Building workspace - 0%
2018-10-7 18:23:21 >> workspace/didChangeConfiguration
2018-10-7 18:23:21 >> registerFeature 'workspace/didChangeWatchedFiles'
Building workspace - 100% (done) [2 times]
Validate documents - 0%
2018-10-7 18:23:21 >>New configuration: {java={jdt={ls={vmargs=-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication}}, errors={incompleteClasspath={severity=warning}}, configuration={updateBuildConfiguration=automatic, maven=null}, trace={server=off}, import={gradle={enabled=true}, maven={enabled=true}, exclusions=[**/node_modules/**, **/.metadata/**, **/archetype-resources/**, **/META-INF/maven/**]}, referencesCodeLens={enabled=true}, progressReports={enabled=true}, signatureHelp={enabled=true}, implementationsCodeLens={enabled=true}, format={enabled=true, settings={profile=null, url=null}, comments={enabled=false}}, saveActions={organizeImports=true}, contentProvider=null, autobuild={enabled=true}, completion={favoriteStaticMembers=[org.junit.Assert.*, org.junit.Assume.*, org.junit.jupiter.api.Assertions.*, org.junit.jupiter.api.Assumptions.*, org.junit.jupiter.api.DynamicContainer.*, org.junit.jupiter.api.DynamicTest.*], importOrder=[java, javax, com, org], guessMethodArguments=null}}}
Repository registry initialization (done)
Validate documents - 100% (done)
2018-10-7 18:23:21 begin problem for /Main.java
2018-10-7 18:23:21 0 problems reported for /Main.java
2018-10-7 18:23:21 Reconciled 0, validated: 1. Took 195 ms
Validate documents - 100% (done)
Building workspace - 0%
Building workspace - 100% (done) [2 times]
Refreshing Maven model (done) [2 times]
Building workspace - 0%
Updating indexes
Updating indexes (done) [2 times]
Building workspace - 100% (done) [4 times]
2018-10-7 18:23:22 >> document/codeAction
2018-10-7 18:23:22 >> document/hover [3 times]
2018-10-7 18:23:25 >> document/codeLens
error in process filter: lsp-intellij--render-code-lenses: Wrong type argument: hash-table-p, ("file:///home/stardiviner/IdeaProjects/JavaTest/src/stardiviner/test/Main.java" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("line" 4 "character" 23)) "references")
error in process filter: Wrong type argument: hash-table-p, ("file:///home/stardiviner/IdeaProjects/JavaTest/src/stardiviner/test/Main.java" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("line" 4 "character" 23)) "references")
2018-10-7 18:23:52 >> document/codeAction [2 times]

lsp-intellij--render-code-lenses:

This line means that you have started something that is not related to lsp-java, probably the idea lsp server. You may set lsp-code-lenses to nil.

home/stardiviner/IdeaProjects/JavaTest/src/stardiviner/test/Main.java

The path looks incorrect - the maven src folder is `/src/main/java/{project-namespace}.

You may download the following test project: https://github.com/yyoncho/dap-mode/tree/master/features/fixtures/test-project to start with.

I got another error:

Debugger entered--Lisp error: (lsp-timed-out-error)
  signal(lsp-timed-out-error nil)
  lsp--send-wait("Content-Length: 1959\015\n\015\n{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"params\":{\"processId\":19003,\"rootPath\":\"/home/stardiviner/.emacs.d/workspace/\",\"rootUri\":\"file:///home/stardiviner/.emacs.d/workspace/\",\"capabilities\":{\"workspace\":{\"applyEdit\":true,\"executeCommand\":{\"dynamicRegistration\":true}},\"textDocument\":{\"synchronization\":{\"willSave\":true,\"didSave\":true,\"willSaveWaitUntil\":true},\"documentSymbol\":{\"symbolKind\":{\"valueSet\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},\"hierarchicalDocumentSymbolSupport\":true},\"formatting\":{\"dynamicRegistration\":true},\"codeAction\":{\"dynamicRegistration\":true}}},\"initializationOptions\":{\"workspaceFolders\":[\"file:///home/stardiviner/IdeaProjects/JavaTest/\"],\"settings\":{\"java\":{\"jdt\":{\"ls\":{\"vmargs\":\"-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication\"}},\"errors\":{\"incompleteClasspath\":{\"severity\":\"warning\"}},\"configuration\":{\"updateBuildConfiguration\":\"automatic\",\"maven\":null},\"trace\":{\"server\":\"off\"},\"import\":{\"gradle\":{\"enabled\":true},\"maven\":{\"enabled\":true},\"exclusions\":[\"**/node_modules/**\",\"**/.metadata/**\",\"**/archetype-resources/**\",\"**/META-INF/maven/**\"]},\"referencesCodeLens\":{\"enabled\":true},\"progressReports\":{\"enabled\":true},\"signatureHelp\":{\"enabled\":true},\"implementationsCodeLens\":{\"enabled\":true},\"format\":{\"enabled\":true,\"settings\":{\"profile\":null,\"url\":null},\"comments\":{\"enabled\":false}},\"saveActions\":{\"organizeImports\":true},\"contentProvider\":null,\"autobuild\":{\"enabled\":true},\"completion\":{\"favoriteStaticMembers\":[\"org.junit.Assert.*\",\"org.junit.Assume.*\",\"org.junit.jupiter.api.Assertions.*\",\"org.junit.jupiter.api.Assumptions.*\",\"org.junit.jupiter.api.DynamicContainer.*\",\"org.junit.jupiter.api.DynamicTest.*\"],\"importOrder\":[\"java\",\"javax\",\"com\",\"org\"],\"guessMethodArguments\":null}}},\"extendedClientCapabilities\":{\"progressReportProvider\":true,\"classFileContentsSupport\":true},\"bundles\":[\"/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/bundles/java.debug.plugin.jar\"]}},\"id\":1}" #<process lsp-java> #s(lsp--parser :waiting-for-response t :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received 0 :leftovers nil :queued-notifications nil :queued-requests nil :workspace #s(lsp--workspace :parser #1 :file-versions #<hash-table equal 0/65 0x2749971> :server-capabilities nil :registered-server-capabilities nil :root "/home/stardiviner/.emacs.d/workspace/" :client #s(lsp--client :language-id #f(compiled-function (_) #<bytecode 0x2745959>) :send-sync nil :send-async nil :type nil :new-connection #f(compiled-function (filter sentinel) #<bytecode 0x27459a5>) :stderr "*lsp-java stderr*" :get-root #f(compiled-function () #<bytecode 0x203f681>) :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x2745cc9> :request-handlers #<hash-table equal 0/65 0x2746571> :response-handlers #<hash-table eql 0/65 0x2746591> :string-renderers (("java" . lsp-java--render-string)) :last-id 1 :enable-function lsp-java-enable :prefix-function nil :uri-handlers #<hash-table equal 1/65 0x268d669> :action-handlers #<hash-table equal 1/65 0x2748d71> :default-renderer lsp-java--render-markup :use-native-json nil) :change-timer-disabled nil :proc #<process lsp-java> :cmd-proc #<process lsp-java> :buffers nil :highlight-overlays #<hash-table eq 0/65 0x2749991> :extra-client-capabilities nil :status nil :metadata #<hash-table equal 0/65 0x2431d95> :watches #<hash-table equal 0/65 0x274bd71>)))
  lsp--send-request((:jsonrpc "2.0" :method "initialize" :params (:processId 19003 :rootPath "/home/stardiviner/.emacs.d/workspace/" :rootUri "file:///home/stardiviner/.emacs.d/workspace/" :capabilities (:workspace (:applyEdit t :executeCommand (:dynamicRegistration t)) :textDocument (:synchronization (:willSave t :didSave t :willSaveWaitUntil t) :documentSymbol (:symbolKind (:valueSet [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25]) :hierarchicalDocumentSymbolSupport t) :formatting (:dynamicRegistration t) :codeAction (:dynamicRegistration t))) :initializationOptions (:workspaceFolders ("file:///home/stardiviner/IdeaProjects/JavaTest/") :settings ((java (jdt (ls (vmargs . "-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication"))) (errors (incompleteClasspath (severity . warning))) (configuration (updateBuildConfiguration . automatic) (maven)) (trace (server . off)) (import (gradle (enabled . t)) (maven (enabled . t)) (exclusions "**/node_modules/**" "**/.metadata/**" "**/archetype-resources/**" "**/META-INF/maven/**")) (referencesCodeLens (enabled . t)) (progressReports (enabled . t)) (signatureHelp (enabled . t)) (implementationsCodeLens (enabled . t)) (format (enabled . t) (settings (profile) (url)) (comments (enabled . :json-false))) (saveActions (organizeImports . t)) (contentProvider) (autobuild (enabled . t)) (completion (favoriteStaticMembers "org.junit.Assert.*" "org.junit.Assume.*" "org.junit.jupiter.api.Assertions.*" "org.junit.jupiter.api.Assumptions.*" "org.junit.jupiter.api.DynamicContainer.*" "org.junit.jupiter.api.DynamicTest.*") (importOrder "java" "javax" "com" "org") (guessMethodArguments)))) :extendedClientCapabilities (:progressReportProvider t :classFileContentsSupport t) :bundles ("/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/bundles/java.debug.plugin.jar"))) :id 1))
  lsp--start(#s(lsp--client :language-id #f(compiled-function (_) #<bytecode 0x2745959>) :send-sync nil :send-async nil :type nil :new-connection #f(compiled-function (filter sentinel) #<bytecode 0x27459a5>) :stderr "*lsp-java stderr*" :get-root #f(compiled-function () #<bytecode 0x203f681>) :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x2745cc9> :request-handlers #<hash-table equal 0/65 0x2746571> :response-handlers #<hash-table eql 0/65 0x2746591> :string-renderers (("java" . lsp-java--render-string)) :last-id 1 :enable-function lsp-java-enable :prefix-function nil :uri-handlers #<hash-table equal 1/65 0x268d669> :action-handlers #<hash-table equal 1/65 0x2748d71> :default-renderer lsp-java--render-markup :use-native-json nil) (:workspaceFolders ("file:///home/stardiviner/IdeaProjects/JavaTest/") :settings ((java (jdt (ls (vmargs . "-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication"))) (errors (incompleteClasspath (severity . warning))) (configuration (updateBuildConfiguration . automatic) (maven)) (trace (server . off)) (import (gradle (enabled . t)) (maven (enabled . t)) (exclusions "**/node_modules/**" "**/.metadata/**" "**/archetype-resources/**" "**/META-INF/maven/**")) (referencesCodeLens (enabled . t)) (progressReports (enabled . t)) (signatureHelp (enabled . t)) (implementationsCodeLens (enabled . t)) (format (enabled . t) (settings (profile) (url)) (comments (enabled . :json-false))) (saveActions (organizeImports . t)) (contentProvider) (autobuild (enabled . t)) (completion (favoriteStaticMembers "org.junit.Assert.*" "org.junit.Assume.*" "org.junit.jupiter.api.Assertions.*" "org.junit.jupiter.api.Assumptions.*" "org.junit.jupiter.api.DynamicContainer.*" "org.junit.jupiter.api.DynamicTest.*") (importOrder "java" "javax" "com" "org") (guessMethodArguments)))) :extendedClientCapabilities (:progressReportProvider t :classFileContentsSupport t) :bundles ("/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/bundles/java.debug.plugin.jar")))
  lsp--enable-stdio-client(lsp-java :language-id "java" :language-id-fn nil :root-directory-fn #f(compiled-function () #<bytecode 0x203f681>) :command ("java" "-Declipse.application=org.eclipse.jdt.ls.core.id1" "-Dosgi.bundles.defaultStartLevel=4" "-Declipse.product=org.eclipse.jdt.ls.core.product" "-Dlog.protocol=true" "-Dlog.level=ALL" "-noverify" "-Xmx1G" "-XX:+UseG1GC" "-XX:+UseStringDeduplication" "-jar" "/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar" "-configuration" "/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/config_linux" "-data" "/home/stardiviner/.emacs.d/workspace/") :command-fn nil :ignore-regexps ("^SLF4J: " "^Listening for transport dt_socket at address: ") :ignore-messages nil :extra-init-params (:workspaceFolders ("file:///home/stardiviner/IdeaProjects/JavaTest/") :settings ((java (jdt (ls (vmargs . "-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication"))) (errors (incompleteClasspath (severity . warning))) (configuration (updateBuildConfiguration . automatic) (maven)) (trace (server . off)) (import (gradle (enabled . t)) (maven (enabled . t)) (exclusions "**/node_modules/**" "**/.metadata/**" "**/archetype-resources/**" "**/META-INF/maven/**")) (referencesCodeLens (enabled . t)) (progressReports (enabled . t)) (signatureHelp (enabled . t)) (implementationsCodeLens (enabled . t)) (format (enabled . t) (settings (profile) (url)) (comments (enabled . :json-false))) (saveActions (organizeImports . t)) (contentProvider) (autobuild (enabled . t)) (completion (favoriteStaticMembers "org.junit.Assert.*" "org.junit.Assume.*" "org.junit.jupiter.api.Assertions.*" "org.junit.jupiter.api.Assumptions.*" "org.junit.jupiter.api.DynamicContainer.*" "org.junit.jupiter.api.DynamicTest.*") (importOrder "java" "javax" "com" "org") (guessMethodArguments)))) :extendedClientCapabilities (:progressReportProvider t :classFileContentsSupport t) :bundles ("/home/stardiviner/.emacs.d/eclipse.jdt.ls/server/bundles/java.debug.plugin.jar")) :initialize-fn lsp-java--client-initialized :enable-function lsp-java-enable :prefix-function nil :use-native-json nil)
  #f(compiled-function () (interactive nil) #<bytecode 0x203f6d1>)()
  apply(#f(compiled-function () (interactive nil) #<bytecode 0x203f6d1>) nil)
  #f(advice-wrapper :after #f(compiled-function () (interactive nil) #<bytecode 0x203f6d1>) lsp-java--after-start)()
  apply(#f(advice-wrapper :after #f(compiled-function () (interactive nil) #<bytecode 0x203f6d1>) lsp-java--after-start) nil)
  lsp-java-enable()
  org-babel-edit-prep:java(("java" "package temp;\n\nclass App {\n  public static void main(String[] args) {\n    System.out.print(123);\n    foo();\n    bar();\n  }\n\n  static int foo() {\n    new App();\n    return 10;\n  }\n\n  static int bar() {\n    new App();\n    return 10;\n  }\n}\n" ((:results . "output replace") (:exports . "") (:file-name . "~/Documents/learning/Java/test-project/src/main/java/temp/App.java") (:eval . "never-export") (:cache . "yes") (:comments . "links") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:session . "none")) "" nil 288901 "(ref:%s)"))
  funcall(org-babel-edit-prep:java ("java" "package temp;\n\nclass App {\n  public static void main(String[] args) {\n    System.out.print(123);\n    foo();\n    bar();\n  }\n\n  static int foo() {\n    new App();\n    return 10;\n  }\n\n  static int bar() {\n    new App();\n    return 10;\n  }\n}\n" ((:results . "output replace") (:exports . "") (:file-name . "~/Documents/learning/Java/test-project/src/main/java/temp/App.java") (:eval . "never-export") (:cache . "yes") (:comments . "links") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:session . "none")) "" nil 288901 "(ref:%s)"))
  (progn (funcall edit-prep-func babel-info))
  (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))
  (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info))))
  (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))
  (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info))))))
  (let* ((lang (if (eq type 'src-block) (org-element-property :language element) "example")) (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang))) (babel-info (and (eq type 'src-block) (org-babel-get-src-block-info 'light))) deactivate-mark) (if (and (eq type 'src-block) (not (functionp lang-f))) (progn (error "No such language mode: %s" lang-f))) (org-src--edit-element element (or edit-buffer-name (org-src--construct-edit-buffer-name (buffer-name) lang)) lang-f (and (null code) (function (lambda nil (org-escape-code-in-region (point-min) (point-max))))) (and code (org-unescape-code-in-string code))) (set (make-local-variable 'org-coderef-label-format) (or (org-element-property :label-fmt element) org-coderef-label-format)) (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))) t)
  (let* ((element (org-element-at-point)) (type (org-element-type element))) (if (and (memq type '(example-block src-block)) (org-src--on-datum-p element)) nil (user-error "Not in a source or example block")) (let* ((lang (if (eq type 'src-block) (org-element-property :language element) "example")) (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang))) (babel-info (and (eq type 'src-block) (org-babel-get-src-block-info 'light))) deactivate-mark) (if (and (eq type 'src-block) (not (functionp lang-f))) (progn (error "No such language mode: %s" lang-f))) (org-src--edit-element element (or edit-buffer-name (org-src--construct-edit-buffer-name (buffer-name) lang)) lang-f (and (null code) (function (lambda nil (org-escape-code-in-region (point-min) (point-max))))) (and code (org-unescape-code-in-string code))) (set (make-local-variable 'org-coderef-label-format) (or (org-element-property :label-fmt element) org-coderef-label-format)) (if (eq type 'src-block) (progn (setq org-src--babel-info babel-info) (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang)))) (if (fboundp edit-prep-func) (progn (funcall edit-prep-func babel-info)))))) t))
  org-edit-src-code()
  (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))
  (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here")))))))
  (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here"))))))))
  (let ((element (org-element-at-point))) (barf-if-buffer-read-only) (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here")))))))))
  (closure (org-table-auto-blank-field org-clock-history org-agenda-current-date org-with-time org-defdecode org-def org-read-date-inactive org-ans2 org-ans1 org-columns-current-fmt-compiled org-clock-current-task org-clock-effort org-agenda-skip-function org-agenda-skip-comment-trees org-agenda-archives-mode org-end-time-was-given org-time-was-given org-log-note-extra org-log-note-purpose org-log-post-message org-last-inserted-timestamp org-last-changed-timestamp org-entry-property-inherited-from org-blocked-by-checkboxes org-state org-agenda-headline-snapshot-before-repeat org-capture-last-stored-marker org-agenda-start-on-weekday org-agenda-buffer-tmp-name clean-buffer-list-kill-buffer-names org-id-link-to-org-use-id org-agenda-buffer-name org-priority-regexp org-mode-abbrev-table org-mode-syntax-table buffer-face-mode-face org-mode-map org-tbl-menu org-org-menu org-struct-menu org-entities org-last-state org-id-track-globally org-clock-start-time texmathp-why remember-data-file org-agenda-tags-todo-honor-ignore-options iswitchb-temp-buflist calc-embedded-open-mode calc-embedded-open-formula calc-embedded-close-formula align-mode-rules-list org-emphasis-alist org-emphasis-regexp-components org-export-registered-backends org-modules org-babel-load-languages org-indent-indentation-per-level org-element-paragraph-separate ffap-url-regexp org-inlinetask-min-level t) (&optional arg) "Call a special editor for the element at point.\nWhen at a table, call the formula editor with `org-table-edit-formulas'.\nWhen in a source code block, call `org-edit-src-code'.\nWhen in a fixed-width region, call `org-edit-fixed-width-region'.\nWhen in an export block, call `org-edit-export-block'.\nWhen in a LaTeX environment, call `org-edit-latex-environment'.\nWhen at an #+INCLUDE keyword, visit the included file.\nWhen at a footnote reference, call `org-edit-footnote-reference'.\nWhen at a planning line call, `org-deadline' and/or `org-schedule'.\nWhen at an active timestamp, call `org-time-stamp'.\nWhen at an inactive timestamp, call `org-time-stamp-inactive'.\nOn a link, call `ffap' to visit the link at point.\nOtherwise, return a user error." (interactive "P") (let ((element (org-element-at-point))) (barf-if-buffer-read-only) (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here"))))))))))(nil)
  apply((closure (org-table-auto-blank-field org-clock-history org-agenda-current-date org-with-time org-defdecode org-def org-read-date-inactive org-ans2 org-ans1 org-columns-current-fmt-compiled org-clock-current-task org-clock-effort org-agenda-skip-function org-agenda-skip-comment-trees org-agenda-archives-mode org-end-time-was-given org-time-was-given org-log-note-extra org-log-note-purpose org-log-post-message org-last-inserted-timestamp org-last-changed-timestamp org-entry-property-inherited-from org-blocked-by-checkboxes org-state org-agenda-headline-snapshot-before-repeat org-capture-last-stored-marker org-agenda-start-on-weekday org-agenda-buffer-tmp-name clean-buffer-list-kill-buffer-names org-id-link-to-org-use-id org-agenda-buffer-name org-priority-regexp org-mode-abbrev-table org-mode-syntax-table buffer-face-mode-face org-mode-map org-tbl-menu org-org-menu org-struct-menu org-entities org-last-state org-id-track-globally org-clock-start-time texmathp-why remember-data-file org-agenda-tags-todo-honor-ignore-options iswitchb-temp-buflist calc-embedded-open-mode calc-embedded-open-formula calc-embedded-close-formula align-mode-rules-list org-emphasis-alist org-emphasis-regexp-components org-export-registered-backends org-modules org-babel-load-languages org-indent-indentation-per-level org-element-paragraph-separate ffap-url-regexp org-inlinetask-min-level t) (&optional arg) "Call a special editor for the element at point.\nWhen at a table, call the formula editor with `org-table-edit-formulas'.\nWhen in a source code block, call `org-edit-src-code'.\nWhen in a fixed-width region, call `org-edit-fixed-width-region'.\nWhen in an export block, call `org-edit-export-block'.\nWhen in a LaTeX environment, call `org-edit-latex-environment'.\nWhen at an #+INCLUDE keyword, visit the included file.\nWhen at a footnote reference, call `org-edit-footnote-reference'.\nWhen at a planning line call, `org-deadline' and/or `org-schedule'.\nWhen at an active timestamp, call `org-time-stamp'.\nWhen at an inactive timestamp, call `org-time-stamp-inactive'.\nOn a link, call `ffap' to visit the link at point.\nOtherwise, return a user error." (interactive "P") (let ((element (org-element-at-point))) (barf-if-buffer-read-only) (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here")))))))))) nil)
  org-edit-latex--wrap-maybe((closure (org-table-auto-blank-field org-clock-history org-agenda-current-date org-with-time org-defdecode org-def org-read-date-inactive org-ans2 org-ans1 org-columns-current-fmt-compiled org-clock-current-task org-clock-effort org-agenda-skip-function org-agenda-skip-comment-trees org-agenda-archives-mode org-end-time-was-given org-time-was-given org-log-note-extra org-log-note-purpose org-log-post-message org-last-inserted-timestamp org-last-changed-timestamp org-entry-property-inherited-from org-blocked-by-checkboxes org-state org-agenda-headline-snapshot-before-repeat org-capture-last-stored-marker org-agenda-start-on-weekday org-agenda-buffer-tmp-name clean-buffer-list-kill-buffer-names org-id-link-to-org-use-id org-agenda-buffer-name org-priority-regexp org-mode-abbrev-table org-mode-syntax-table buffer-face-mode-face org-mode-map org-tbl-menu org-org-menu org-struct-menu org-entities org-last-state org-id-track-globally org-clock-start-time texmathp-why remember-data-file org-agenda-tags-todo-honor-ignore-options iswitchb-temp-buflist calc-embedded-open-mode calc-embedded-open-formula calc-embedded-close-formula align-mode-rules-list org-emphasis-alist org-emphasis-regexp-components org-export-registered-backends org-modules org-babel-load-languages org-indent-indentation-per-level org-element-paragraph-separate ffap-url-regexp org-inlinetask-min-level t) (&optional arg) "Call a special editor for the element at point.\nWhen at a table, call the formula editor with `org-table-edit-formulas'.\nWhen in a source code block, call `org-edit-src-code'.\nWhen in a fixed-width region, call `org-edit-fixed-width-region'.\nWhen in an export block, call `org-edit-export-block'.\nWhen in a LaTeX environment, call `org-edit-latex-environment'.\nWhen at an #+INCLUDE keyword, visit the included file.\nWhen at a footnote reference, call `org-edit-footnote-reference'.\nWhen at a planning line call, `org-deadline' and/or `org-schedule'.\nWhen at an active timestamp, call `org-time-stamp'.\nWhen at an inactive timestamp, call `org-time-stamp-inactive'.\nOn a link, call `ffap' to visit the link at point.\nOtherwise, return a user error." (interactive "P") (let ((element (org-element-at-point))) (barf-if-buffer-read-only) (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here")))))))))) nil)
  apply(org-edit-latex--wrap-maybe (closure (org-table-auto-blank-field org-clock-history org-agenda-current-date org-with-time org-defdecode org-def org-read-date-inactive org-ans2 org-ans1 org-columns-current-fmt-compiled org-clock-current-task org-clock-effort org-agenda-skip-function org-agenda-skip-comment-trees org-agenda-archives-mode org-end-time-was-given org-time-was-given org-log-note-extra org-log-note-purpose org-log-post-message org-last-inserted-timestamp org-last-changed-timestamp org-entry-property-inherited-from org-blocked-by-checkboxes org-state org-agenda-headline-snapshot-before-repeat org-capture-last-stored-marker org-agenda-start-on-weekday org-agenda-buffer-tmp-name clean-buffer-list-kill-buffer-names org-id-link-to-org-use-id org-agenda-buffer-name org-priority-regexp org-mode-abbrev-table org-mode-syntax-table buffer-face-mode-face org-mode-map org-tbl-menu org-org-menu org-struct-menu org-entities org-last-state org-id-track-globally org-clock-start-time texmathp-why remember-data-file org-agenda-tags-todo-honor-ignore-options iswitchb-temp-buflist calc-embedded-open-mode calc-embedded-open-formula calc-embedded-close-formula align-mode-rules-list org-emphasis-alist org-emphasis-regexp-components org-export-registered-backends org-modules org-babel-load-languages org-indent-indentation-per-level org-element-paragraph-separate ffap-url-regexp org-inlinetask-min-level t) (&optional arg) "Call a special editor for the element at point.\nWhen at a table, call the formula editor with `org-table-edit-formulas'.\nWhen in a source code block, call `org-edit-src-code'.\nWhen in a fixed-width region, call `org-edit-fixed-width-region'.\nWhen in an export block, call `org-edit-export-block'.\nWhen in a LaTeX environment, call `org-edit-latex-environment'.\nWhen at an #+INCLUDE keyword, visit the included file.\nWhen at a footnote reference, call `org-edit-footnote-reference'.\nWhen at a planning line call, `org-deadline' and/or `org-schedule'.\nWhen at an active timestamp, call `org-time-stamp'.\nWhen at an inactive timestamp, call `org-time-stamp-inactive'.\nOn a link, call `ffap' to visit the link at point.\nOtherwise, return a user error." (interactive "P") (let ((element (org-element-at-point))) (barf-if-buffer-read-only) (let* ((val (org-element-type element))) (cond ((eq val 'src-block) (if (not arg) (org-edit-src-code) (let* ((info (org-babel-get-src-block-info)) (lang (nth 0 info)) (params (nth 2 info)) (session (cdr (assq :session params)))) (if (not session) (org-edit-src-code) (switch-to-buffer (funcall (intern (concat "org-babel-prep-session:" lang)) session params)))))) ((eq val 'keyword) (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE")) (org-open-link-from-string (format "[[%s]]" (expand-file-name (let ((value (org-element-property :value element))) (cond ((org-file-url-p value) (user-error "The file is specified as a URL, cannot be edited")) ((not (org-string-nw-p value)) (user-error "No file to edit")) ((string-match "\\`\"\\(.*?\\)\"" value) (match-string 1 value)) ((string-match "\\`[^ \011\"]\\S-*" value) (match-string 0 value)) (t (user-error "No valid file specified"))))))) (user-error "No special environment to edit here"))) ((eq val 'table) (if (eq (org-element-property :type element) 'table\.el) (org-edit-table\.el) (call-interactively 'org-table-edit-formulas))) ((eq val 'table-row) (call-interactively 'org-table-edit-formulas)) ((eq val 'example-block) (org-edit-src-code)) ((eq val 'export-block) (org-edit-export-block)) ((eq val 'fixed-width) (org-edit-fixed-width-region)) ((eq val 'latex-environment) (org-edit-latex-environment)) ((eq val 'planning) (let ((proplist (car (cdr element)))) (mapc (function call-interactively) (remq nil (list (if (plist-get proplist :deadline) (progn (function org-deadline))) (if (plist-get proplist :scheduled) (progn (function org-schedule)))))))) (t (let ((context (org-element-context element))) (let* ((val (org-element-type context))) (cond ((eq val 'footnote-reference) (org-edit-footnote-reference)) ((eq val 'inline-src-block) (org-edit-inline-src-code)) ((eq val 'timestamp) (if (eq 'inactive (org-element-property :type context)) (call-interactively (function org-time-stamp-inactive)) (call-interactively (function org-time-stamp)))) ((eq val 'link) (call-interactively (function ffap))) (t (user-error "No special environment to edit here")))))))))) nil)
  org-edit-special(nil)
  funcall-interactively(org-edit-special nil)
  call-interactively(org-edit-special nil nil)
  command-execute(org-edit-special)

I guess this is because timeout of lsp-java server.

And I see a warning message before open the source block buffer:
Initialization fails with: "Wrong type argument: stringp, nil"
Even I toggle-debug-on-error. It does not popup the track stack.

#+BEGIN_SRC java :file-name "~/Documents/learning/Java/test-project/src/main/java/temp/App.java"
package temp;

class App {
  public static void main(String[] args) {
    System.out.print(123);
    foo();
    bar();
  }

  static int foo() {
    new App();
    return 10;
  }

  static int bar() {
    new App();
    return 10;
  }
}

#+END_SRC
(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  ;; (lsp-javacomp-enable)
  (lsp-java-enable)
  (lsp-ui-mode t)
  ;; other lsp-java specific stuff that you usually run with the major mode, company mode and so on.
  (company-mode t))

(use-package lsp-java
  :ensure t
  :init (add-hook 'java-mode-hook #'lsp-java-enable)
  :config
  ;; set the projects that are going to be imported into the workspace.
  (setq lsp-java--workspace-folders (list "~/IdeaProjects/JavaTest/"
                                          "~/Documents/learning/Java/test-project/")))

Upper timeout issue seems is random. Later try times:
Here is the *messages* buffer logs:

Initialization fails with: "Wrong type argument: stringp, nil"
Type C-x 1 to delete the help window.
Mark set [2 times]
"org-babel-edit-prep:java"
executing Emacs-Lisp code block...
Code block evaluation complete.
Mark set [2 times]
Saving file /home/stardiviner/Org/Projects/Programming Projects/Code.org...
Wrote /home/stardiviner/Org/Projects/Programming Projects/Code.org
Initialization fails with: "Wrong type argument: stringp, nil"
using config for config_linux
Entering debugger...
2018-10-8 20:49:30 Main thread is waiting
2018-10-8 20:49:31 >> initialize
2018-10-8 20:49:31 Initializing Java Language Server 0.27.0.201810051359
Init...[Starting]
0% Starting Java Language Server [Starting]
20% Starting Java Language Server [Starting]
2018-10-8 20:49:32 Creating the default Java project
2018-10-8 20:49:32 Finished creating the default Java project
Refreshing Maven model
37% Starting Java Language Server [Starting]
100% Starting Java Language Server [Starting] [2 times]
2018-10-8 20:49:33 Workspace initialized in 2524ms
Ready[Started]
Building workspace - 0%
Building workspace - 100% (done) [2 times]
Building workspace - 0%
Building workspace - 100% (done) [2 times]
Refreshing Maven model (done) [2 times]
Building workspace - 0%
Updating indexes
Updating indexes (done) [2 times]
Building workspace - 100% (done) [4 times]
Repository registry initialization (done)
Updating indexes
Updating indexes (done) [2 times]
Mark set
Saved text from "Debugger entered--Lisp error: (lsp-timed"
Back to top level
Mark set [3 times]
using config for config_linux
Entering debugger...
Saving file ~/Documents/learning/Java/test-project/src/main/java/temp/App.java...
Saving file /home/stardiviner/Org/Projects/Programming Projects/Code.org...
Wrote /home/stardiviner/Org/Projects/Programming Projects/Code.org
Mark activated
Back to top level
Mark saved where search started [3 times]
Loading package lsp-java...
Configuring package lsp-java...done (0.111s)
Loading package lsp-java...done (0.330s)
t
C-x C-g is undefined
Quit
("~/IdeaProjects/JavaTest/" "~/Documents/learning/Java/test-project/")
Saving file /home/stardiviner/.emacs.d/init/programming/languages/Java/init-prog-lang-java.el...
Wrote /home/stardiviner/.emacs.d/init/programming/languages/Java/init-prog-lang-java.el
Initialization fails with: "Wrong type argument: stringp, nil"
using config for config_linux
Entering debugger...
2018-10-8 20:53:51 >> document/didOpen
2018-10-8 20:53:51 Classpath is incomplete. Only syntax errors will be reported for file:///home/stardiviner/Documents/learning/Java/test-project/src/main/java/temp/App.java
lsp-workspace-status: Wrong type argument: lsp--workspace, nil
Validate documents - 75%
Validate documents - 100% (done)
2018-10-8 20:53:52 begin problem for /App.java
2018-10-8 20:53:52 2 problems reported for /App.java
2018-10-8 20:53:52 Reconciled 0, validated: 1. Took 263 ms
Validate documents - 100% (done)
Building workspace - 0%
Building workspace - 100% (done) [4 times]
Back to top level
2018-10-8 20:53:58 >> document/didChange
Building workspace - 0%
Building workspace - 100% (done) [2 times]
2018-10-8 20:54:00 >> document/didChange
Building workspace - 0%
Building workspace - 0% (done)
2018-10-8 20:54:01 >> document/didChange
Building workspace - 0%
Building workspace - 0% (done)

Can you remove "~/IdeaProjects/JavaTest/" just to isolate the problem, set lsp-response-timeout to bigger value and retry?

I removed "~/IdeaProjects/JavaTest/". And (setq lsp-response-timeout 20). It works great now. Thanks a lot a lot a lot for your help me out on this.

I'm curious what caused this error: Initialization fails with: "Wrong type argument: stringp, nil"

@stardiviner You may now play with the Idea project. I suspect that for some reason(e. g. your PC is slow or was under load) JDT server was unable to parse the projects in 10 seconds time and the initialization has failed and after that LSP was mode is broken.

@twlz0ne did you had a chance to play with the solution that works for @stardiviner ?

@yyoncho Yes, my small notebook is slow on hardware performance. But I'm increasing Emacs performance on other places like disable some packages. Then I test now, it initialize lsp-java need about 8 seconds now.

@stardiviner yeah, so I have guessed it right. There is a bug to make that initialize function async which will solve that problem.

@yyoncho

org-src-block-with-lsp-mode

My configuration:

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (setq lsp-response-timeout 50)
  (my/enable-lsp-java))

(defun my/lsp-java-enable ()
  (message ">>>>>>>>>> (my/lsp-java-enable) <<<<<<<<<<")
  (set (make-local-variable 'company-backends)
       '(;; company-lsp
         company-capf))
  (lsp-java-enable))

(setq lsp-java-server-install-dir "~/.emacs.d/eclipse.jdt.ls/server/")
(setq lsp-java--workspace-folders
      (list ;; "~/IdeaProjects/JavaTest/"
       "~/Documents/learning/Java/test-project/"))

(add-hook 'java-mode-hook #'my/lsp-java-enable)

*Message*

>>>>>>>>>> (my/lsp-java-enable) <<<<<<<<<<
Initialization fails with: "Wrong type argument: stringp, nil"
>>>>>>>>>> (my/lsp-java-enable) <<<<<<<<<<
using config for config_mac
Oct 16, 2018, 5:54:35 PM Main thread is waiting
Oct 16, 2018, 5:54:36 PM >> initialize
Oct 16, 2018, 5:54:36 PM Initializing Java Language Server 0.27.0.201810051359
Init...[Starting]
0% Starting Java Language Server [Starting]
>>>[lsp-java-enable@after]
Oct 16, 2018, 5:54:36 PM >> initialized
Refreshing Maven model [2 times]
Repository registry initialization (done)
0% Starting Java Language Server [Starting]
Updating indexes
Updating indexes (done) [2 times]
20% Starting Java Language Server [Starting]
Oct 16, 2018, 5:54:38 PM Creating the default Java project
Oct 16, 2018, 5:54:38 PM Finished creating the default Java project
37% Starting Java Language Server [Starting]
100% Starting Java Language Server [Starting] [2 times]
Oct 16, 2018, 5:54:39 PM Workspace initialized in 2985ms
Ready[Started]
Oct 16, 2018, 5:54:39 PM >> workspace/didChangeConfiguration
Oct 16, 2018, 5:54:39 PM >> registerFeature 'workspace/didChangeWatchedFiles'
Oct 16, 2018, 5:54:39 PM >>New configuration: {prettier={eslintIntegration=null}, html={suggest={ionic=true, html5=true, angular1=true}}, vetur={format={scriptInitialIndent=null, styleInitialIndent=null, defaultFormatterOptions={js-beautify-html=null}, defaultFormatter={ts=prettier, js=prettier, stylus=stylus-supremacy, less=prettier, scss=prettier, postcss=prettier, css=prettier, html=none}}, validation={style=true, template=true}, grammar={customBlocks={i18n=json, doc=md}}, completion={autoImport=true}, colorDecorators={enable=true}}}
Oct 16, 2018, 5:54:39 PM >> document/didOpen
Refreshing Maven model (done) [2 times]
Building workspace - 0%
Oct 16, 2018, 5:54:39 PM >> workspace/didChangeConfiguration
Oct 16, 2018, 5:54:39 PM >> registerFeature 'workspace/didChangeWatchedFiles'
Oct 16, 2018, 5:54:39 PM >>New configuration: {java={jdt={ls={vmargs=-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication}}, errors={incompleteClasspath={severity=warning}}, configuration={updateBuildConfiguration=automatic, maven=null}, trace={server=off}, import={gradle={enabled=true}, maven={enabled=true}, exclusions=[**/node_modules/**, **/.metadata/**, **/archetype-resources/**, **/META-INF/maven/**]}, referencesCodeLens={enabled=true}, progressReports={enabled=true}, signatureHelp={enabled=true}, implementationsCodeLens={enabled=true}, format={enabled=true, settings={profile=null, url=null}, comments={enabled=false}}, saveActions={organizeImports=true}, contentProvider=null, autobuild={enabled=true}, completion={favoriteStaticMembers=[org.junit.Assert.*, org.junit.Assume.*, org.junit.jupiter.api.Assertions.*, org.junit.jupiter.api.Assumptions.*, org.junit.jupiter.api.DynamicContainer.*, org.junit.jupiter.api.DynamicTest.*], importOrder=[java, javax, com, org], guessMethodArguments=null}}}
Building workspace - 1% [2 times]
Building workspace - 100% (done) [4 times]
Oct 16, 2018, 5:54:47 PM >> document/didChange
Building workspace - 0%
Building workspace - 0% (done)
Oct 16, 2018, 5:54:47 PM >> document/documentHighlight
Oct 16, 2018, 5:54:47 PM >> document/codeAction
Oct 16, 2018, 5:54:49 PM >> document/completion
Oct 16, 2018, 5:54:49 PM Completion request completed
Oct 16, 2018, 5:54:49 PM >> document/completion
Oct 16, 2018, 5:54:49 PM Completion request completed
Oct 16, 2018, 5:54:49 PM >> document/completion
Oct 16, 2018, 5:54:49 PM Completion request completed
Quit
[No matches]
Oct 16, 2018, 5:54:51 PM >> document/completion
Oct 16, 2018, 5:54:51 PM Completion request completed
Oct 16, 2018, 5:54:51 PM >> document/completion
Oct 16, 2018, 5:54:51 PM Completion request completed
Oct 16, 2018, 5:54:51 PM >> document/completion
Oct 16, 2018, 5:54:51 PM Completion request completed
Quit
[No matches]
Oct 16, 2018, 5:54:52 PM >> document/completion
Oct 16, 2018, 5:54:52 PM Completion request completed
Oct 16, 2018, 5:54:52 PM >> document/completion
Oct 16, 2018, 5:54:52 PM Completion request completed
Oct 16, 2018, 5:54:52 PM >> document/completion
Oct 16, 2018, 5:54:52 PM Completion request completed
Quit
[No matches]

can you do toggle-debug-on-error, retry, and then paste the callstack? Also, make sure the lsp server status is Started before performing any operation(the status could be seen in the modeline).

Also, here it is the full function to enable autocompletion, I am not sure company-capf could handle lsp-java.

(defun org-babel-edit-prep:java (babel-info)
  (setq-local buffer-file-name (->> babel-info caddr (alist-get :file-name)))
  (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri))
  (lsp-java-enable)
  (push 'company-lsp company-backends)
  (lsp-ui-mode t)
  (flycheck-mode t)
  (company-mode t)
  (lsp-ui-flycheck-enable t))

No error and no callstack printed. Maybe there are other problems in my configuration, I'll check later.

Even so, it works in python block:

screenshot_2018-10-16_at_10 20 07_pm

Great! @twlz0ne @stardiviner you may consider contributing a wiki page so this info is not lost. I am making the bug as closed.

Ok, I will take time to contributing a wiki page.

After check out Wiki Pages https://github.com/emacs-lsp/lsp-mode/wiki, it can't online add wiki page using an online editor. Also I don't know how to fork the wiki page repo.

@stardiviner thanks, only the repo owner could change the wiki permissions:

@vibhavp can you make the wiki public so people could contribute: https://help.github.com/articles/changing-access-permissions-for-wikis/ ?

Seems this workaround doesn't work now. I got this error.
What was I missing?

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  file-truename(nil)
  (url-hexify-string (file-truename (alist-get :file-name (car (cdr (cdr babel-info))))) url-path-allowed-chars)
  (concat lsp--uri-file-prefix (url-hexify-string (file-truename (alist-get :file-name (car (cdr (cdr babel-info))))) url-path-allowed-chars))
  (set (make-local-variable 'lsp-buffer-uri) (concat lsp--uri-file-prefix (url-hexify-string (file-truename (alist-get :file-name (car (cdr (cdr babel-info))))) url-path-allowed-chars)))
  org-babel-edit-prep:python(("python" "import sys\nprint(sys.path)" ((:results . "output replace") (:exports . "code") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:cache . "no") (:session . "none")) "" nil 3848 "(ref:%s)"))
  org-edit-src-code()
  org-edit-special(nil)
  funcall-interactively(org-edit-special nil)
  call-interactively(org-edit-special nil nil)
  command-execute(org-edit-special)

@twlz0ne Would you please let me know how to get it work in Python block? Thanks.

I guess you are missing the configuration in org buffer.

+BEGIN_SRC java :file-name "~/Documents/learning/Java/test-project/src/main/java/temp/App.java"

@yyoncho Yes, you are right. I added :file-name xxxx and it's fine, but I don't think it's the ultimate solution, just a workaround, right? I noticed flycheck is working well with both temp and real buffers.

My workaround:

(defun org-babel-edit-prep:python (babel-info)
      (setq-local lsp-buffer-uri (lsp--path-to-uri
                                  (or (->> babel-info caddr (alist-get :file-name))
                                      (buffer-file-name))))
      (lsp-python-enable))

I wouldn't say it is a workaround but it is a normal org-mode adapter. Flycheck works fine with lsp-java. Note that when you open a file xxxx directly would be the same as when you are editing it in org-mode since the line (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :file-name) lsp--path-to-uri)) will change the file path and the lsp server will think that it is editing that particular file.

I tried this config:

(use-package lsp-python
  :ensure t
  :commands lsp-python-enable
  :init
  (add-hook 'python-mode-hook #'lsp-mode)
  (add-hook 'python-mode-hook #'lsp-python-enable)
  (defun org-babel-edit-prep:python (babel-info)
    "Prepare buffer local environment for Org source block Java."
    (if-let* ((lang (car babel-info))
              (ext (cdr (assoc lang org-babel-tangle-lang-exts)))
              ;; detect the header argument :lsp-file exist, if not, use default
              ;; "/tmp/tmp.EXT".
              (lsp-file (or (->> babel-info
                                 caddr
                                 (alist-get :file))
                            (buffer-file-name)
                            (format "/tmp/tmp.%s" ext)))
              (lsp-file-url (lsp--path-to-uri lsp-file)))
        (progn
          (setq-local buffer-file-name lsp-file)
          (setq-local lsp-buffer-uri lsp-file-url)
          (if lsp-mode (lsp-python-enable))
          (message "lsp-mode workspace file setup for source block done!")))))

Test:

import os
import sys

print("hello, world!")

print(sys.path)
pri

Upper python source block still report error when I open source block to try get code completion:

Wrong type argument: lsp--workspace, nil
Error during redisplay: (eval (lsp-mode-line)) signaled (wrong-type-argument lsp--workspace nil) [8 times]

Maybe my config is wrong, maybe somewhere is still wrong. Why lsp-workspace is still nil?

@stardiviner If you are using the latest lsp-python, lsp-mode is unable to be enabled automatically. Try this:

(lsp-define-stdio-client lsp-python "python"
                             (lsp-make-traverser #'(lambda (dir)
                                                     (if lsp-python-use-init-for-project-root
                                                         (not (directory-files dir nil "__init__.py"))
                                                       (directory-files
                                                        dir
                                                        nil
                                                        "setup.py\\|Pipfile\\|setup.cfg\\|tox.ini"))))
                             nil
                             :command-fn 'lsp-python--ls-command)

(defun org-babel-edit-prep:python (babel-info)
  "Prepare the local buffer environment for Org source block."
  (let ((lsp-file (or (->> babel-info caddr (alist-get :file))
                      buffer-file-name)))
    (setq-local buffer-file-name lsp-file)
    (setq-local lsp-buffer-uri (lsp--path-to-uri buffer-file-name))
    (lsp-python-enable)))

Refer to https://github.com/emacs-lsp/lsp-python/issues/28.

@stardiviner

(add-hook 'python-mode-hook #'lsp-mode)

This line is wrong. When you enable lsp-mode this will prevent lsp--cur-workspace initialization.

(if lsp-mode (lsp-python-enable))

The same - change it to (lsp-python-enable)

I removed those lines. still can't get code completion. This lsp is really hard to configure. I would prefer to stay on other code completion packages until this lsp-lang are enough great to use. Huuuuu...... :(

@stardiviner lsp-mode is easy to configure. Try my config.
Refer to https://github.com/seagle0128/.emacs.d/blob/master/lisp/init-lsp.el

(use-package lsp-python
    :ensure t
    :commands lsp-python-enable
    :hook (python-mode . lsp-python-enable)
    :config
    (defun org-babel-edit-prep:python (babel-info)
      "Prepare the local buffer environment for Org source block."
      (let ((lsp-file (or (->> babel-info caddr (alist-get :file))
                      buffer-file-name)))
        (setq-local buffer-file-name lsp-file)
        (setq-local lsp-buffer-uri (lsp--path-to-uri buffer-file-name))
        (lsp-python-enable)))

    ;; FIXME: https://github.com/emacs-lsp/lsp-python/issues/28
    (lsp-define-stdio-client lsp-python "python"
                             (lsp-make-traverser #'(lambda (dir)
                                                     (if lsp-python-use-init-for-project-root
                                                         (not (directory-files dir nil "__init__.py"))
                                                       (directory-files
                                                        dir
                                                        nil
                                                        "setup.py\\|Pipfile\\|setup.cfg\\|tox.ini"))))
                             nil
                             :command-fn 'lsp-python--ls-command))

@seagle0128 Thank you for sharing. Added into my init files.

@twlz0ne @stardiviner @seagle0128 https://github.com/emacs-lsp/lsp-mode/issues/655 might be interesting for you.

is this post merged ?

Was this page helpful?
0 / 5 - 0 ratings