Hi folks, I've added limited support for LSP via Eglot in org-src-mode buffers. I was intending to publish it as a package but it was suggested to me that it could live as part of Org instead, especially now that Eglot is intended to be part of the upcoming Emacs release. Here are some details: I. What it does. II. How to use it. III. How it works. IV. Limitations and concerns. I. What it does =============== It allows you to run Eglot in org-src buffers opened with org-edit-special (C-c '), giving you context-aware completion, linting, code actions etc. II. How to use it ================ (i) Turn on org-src-context-mode. (ii) Add :tangle header args to code blocks that you intend the Language Server (LS) to parse sequentially, as one file. To parse all code blocks in the Org document using the LS as one file, you can set a global ":tangle yes" header argument. (You don't have to tangle anything -- this is to identify which code blocks constitute a "file".) (iii) Use org-edit-special on a code block. (iv) Run eglot or eglot-connect in the org-src-mode buffer. From this point on, you can use org-edit-special and org-edit-src-exit (both bound by default to C-c ') as usual, and you should have LSP support via Eglot. This LSP connection is persistent across this Emacs session, you can exit the org-src buffer or kill the Org buffer, and come back to it at will. (v) You can shutdown the LSP connection with eglot-shutdown, as usual. III. How it works ================ The main problem with reconciling org-src-mode and Language Server (LS) support is that the LSP requires and expects files, not buffers. By default, org-src buffers are not associated with files. Even if one were to associate an org-src-mode buffer with a file, set the correct default-directory for a project and start Eglot, it would only contain the small chunk of code from the current code block. The LS cannot access enough code to form a useful picture of the project. org-src-context-mode reuses the tangling machinery to populate an org-src buffer with code from all blocks associated with the current tangle file, and associates it with a temporary file. This way, the LS has a better picture -- if still limited to a single file -- of the project. org-src-context-mode then checks if there's an appropriate Eglot LSP connection active, and reconnects to it. Only the contents of the current code block are editable. The other blocks are marked read-only and (by default) only visible by widening the buffer. No actual tangling is done -- the default-directory of the org file is not touched at all. If there's no :tangle header arg, org-src-context-mode does nothing. IV. Limitations and concerns ============================= (i) This creates temporary files with (ostensibly) the contents of code blocks in the Org file. (ii) org-src-context-mode is implemented by advising org-edit-src-code and org-edit-src-exit. This is because it was originally intended to be a third-party package. These functions will need to be modified a bit otherwise. (iii) I'm assuming this design will go through revisions, so I haven't updated the Org manual yet. (I did update the changelog.) (iv) It is quite straightforward to add lsp-mode support with a user-option. (The LSP-specific part of this package is tiny.) Since lsp-mode is not part of Emacs and Eglot will be soon, I decided to focus on Eglot support. (v) org-src-context-mode does some pseudo-tangling -- this is required to specify what constitutes a "file" for the LS to parse. This adds a performance penalty to org-edit-src-code that can be noticeable if you have many (100+?) code blocks with the same tangle file as the current block. (vi) Consider this scenario: The code for your entire project resides in one or more Org files, and is intended to be tangled to several files under a project root directory. Then the nature of LSP support depends on the state of tangling. - Before tangling anything: LSP support with org-src-context-mode remains limited since it can only "see" one file, the one being edited. - Post-tangling the entire project: You have full and veracious LSP support in all org-src buffers. - Post-tangling and after edits to multiple code blocks: LSP support is now *incorrect* since it "sees" a combination of the current state of the "file" being edited in the org-src buffer, and the past state of tangled versions of other code blocks. Still, I've found this to be a big improvement over having no LSP support for Org code blocks. Please let me know if you have any feedback. Karthik