Lsp-mode: [Feature] org-mode lsp-mode integration

Created on 18 Feb 2019  路  22Comments  路  Source: emacs-lsp/lsp-mode

After spending some time reading org-mode code it seems like we may implement language support in the org-mode source block by using org-babel-tangle to save the file and translating the locations and buffer point/position using babel sources.

discussion enhancement epic

Most helpful comment

The initial version is in. Markdown integration is possible after copying lsp-org (and then extracting the common parts). It is still in experimental/beta phase and evolving of the code/feature set depends on feedback.

https://github.com/emacs-lsp/lsp-mode/blob/master/docs/page/lsp-org.md

All 22 comments

Thanks for diving into this.

Do you have a prototype? Using tangling might have some edge case, like multiple source block point to same one target file, and creating empty new source block might overwrite target file. But still I think its a great solution, I saw someone use this method before.

Do you have a prototype?

No, just came up with the idea and decided to file the issue if someone wants to work on it. dap-mode could support that too.

is this merged into the master branch?

is this merged into the master branch?

It is not implemented.

Is this purely for org-mode or also markdown support too?
FYI, https://github.com/polymode/poly-markdown can work to a certain degree with lsp-mode.
23a435f3-4cfb-4413-bf26-6147823b22f3

Is this purely for org-mode or also markdown support too?
FYI, https://github.com/polymode/poly-markdown can work to a certain degree with lsp-mode.
23a435f3-4cfb-4413-bf26-6147823b22f3

can you offer a configuration for the screenshot action? thanks.

@sxdxyxy There's no special configuration needed.
I just install poly-markdown

(use-package poly-markdown
  :ensure t
  :defer t
  :commands (poly-markdown-mode poly-gfm-mode)
  :mode (("\\.md$" . poly-gfm-mode)
         ("\\.markdown$" . poly-markdown-mode)))

And configure lsp-mode like normal. Since the part between ``python ... \``` will automatically changed major mode topython-mode(via indirect buffer), it will automatically triggerlsp-python` to work.

Not sure if it works by lucky or there's automatically point transformation somewhere

@kiennq I don't know why my python in org mode doesn't work , I just simply use a configurable layer called lsp , python and ipython-notebook, in a single file with extension .py will work properly, but in a org file under org-mode code blocks, use 'C-c, ' ', with a extremely long waiting open the code block, but no completion ,no tips, no docstring.

@sxdxyxy I suppose you are using spacemacs, right? You should see https://github.com/emacs-lsp/lsp-mode/issues/377#issuecomment-437565673

@seagle0128 yes, I figured this post from #377 , but I don't know if #377 merge into the master, I add that configuration to the spacemacs config file, still no work.

@sxdxyxy Sorry, I am not using spacemacs, but I do believe it should work.

Actually I make a new macro to support lsp in org-babel.

https://github.com/seagle0128/.emacs.d/blob/03a69b9b725a228a451ec27d7506a2d24f4d1a0f/lisp/init-lsp.el#L436

BTW, you should add :file xxx to the header of source block. That should work now.

For examle,

#+BEGIN_SRC python :results output :file test.py
  import sys
  import os

  print (sys.path)

#+END_SRC

Well, I will see poly-markdown later.

Updated: Did you check poly-org as well? The completion works but not well, since perhaps there are a several prog-modes in the same org file, and LSP server might not parse it correctly. That's why I don't use ploy-markdown or poly-org. IMO, it makes more sense to enable lsp-mode while editing the source blocks in the buffer, while not in the markdown/org files.

cc @vspinu

@seagle0128 unfortunately, I add some line in the init.el file and restart emacs, but it still doesn't work, I am not sure if my whole basic configuration of emacs is totally wrong.
image

this my config file.
image

this is my working file ,which is a independent py file.
image

by the way, another question, how to use your macro named 'lsp-org-babel-enable', I use M-x can not run this macro.

thanks!

@sxdxyxy Again, I am not using spacemacs. You can try vanilla Emacs or Centaur Emacs. lsp-org-babel-enable is a macro, not an interactive function.

Updated: I noticed you copied the codes without any changes. centuar-lsp is not set properly.
Put (setq centaur-lsp 'lsp-mode) before using the macro.

Screenshot in Centaur

screeshot

I am working on that right now.

Would be really great to see a generic non-org-mode-only solution here. Building multi-modes with polymode is easy, and there are many modes floating around already.

I can add a generic tangler to polymode so that, say, all spans of the mode at point up to current span are saved in a temporary buffer/file etc. Just need to converge on a tangling file format so that original file buffer location could be retrieved directly from the tangled file.

Actually such a tangler was in plan from the inception, but never found time for it.

@vspinu - make sense. Looking at what I currently have I think that it will end up generic either way.

Here it is a preview of what I currently have - https://www.youtube.com/watch?v=tnwvLyA2j4w . I started the integration with dap-mode as well.

There are a few more tricky things to handle but soon it will land in master.

I'm looking forward to taking a look at the code.

The initial version is in. Markdown integration is possible after copying lsp-org (and then extracting the common parts). It is still in experimental/beta phase and evolving of the code/feature set depends on feedback.

https://github.com/emacs-lsp/lsp-mode/blob/master/docs/page/lsp-org.md

I was able to run lsp-org normally but it doesn't work for org-babel-expand-src-block like shown by @seagle0128 comment

I was able to run lsp-org normally but it doesn't work for org-babel-expand-src-block like shown by @seagle0128 comment

You should refer to https://github.com/seagle0128/.emacs.d/blob/master/lisp/init-lsp.el#L444.

Was this page helpful?
0 / 5 - 0 ratings