swyddfa / esbonio

A language server for working with Sphinx projects.

Home Page:https://docs.esbon.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

configure lsp with helix

pzzxqj opened this issue Β· comments

I got into difficulties while configuring lsp with Helix. Could you give me a hand?

Sure! Are you able to elaborate on what some of these difficulties are? Any specific error messages? etc.

To start with you're going to need to make sure that the esbonio Python package is installed into the same environment as the one you use to build your documentation.

I've not used Helix before, so the following is a guess after a brief look at the Helix docs on lsp configuration

First you need to define an entry for the esbonio language server

[language-server.esbonio]
command = "/path/to/your/venv/bin/python"
args = ["-m", "esbonio"]
config = { sphinx = { confDir = "/path/to/docs/" } }

where config can contain anything that could be passed to init_options in the Neovim example

Then you need to tell helix to use the language server inside rst files

[[language]]
name = "restructuredtext"
language-servers = [ "esbonio" ] 

Unfortunately, this will have to change when 1.0 is released - but that won't be for a few months yet

Hope that helps!

Hi! Not the author of the issue, but maybe this helps someone out.

I managed to find a partial solution thanks to the Helix wiki.

[[language]]
name = "rst"
scope = "text.rst"
file-types = ["rst", "rest"]
indent = { tab-width = 3, unit = "   " }
language-servers = [ "rst" ]

[[grammar]]
name = "rst"
source = { git = "https://github.com/stsewd/tree-sitter-rst", rev = "25e6328872ac3a764ba8b926aea12719741103f1" }

[language-server.rst]
command = "nc"
args = ["127.0.0.1", "6666"]

This sets Helix up with both a treesitter grammar and a "proxy" LSP.

This is the "partial" part of my solution. Apparently Helix prefers stdio-type LSPs, and the wiki suggests to use netcat as a proxy for those who dont use stdio. The bothersome part of this solution is that I need to start esbonio manually and put it in the background before starting helix. Not only that, if I close helix (because maybe I want to do something in git) then esbonio also shuts down because it says that the client disconnected. I know it works because I can get suggestions for :ref: targets, so I could wrap it in an alias or something and move forward, but it's less than ideal...

Is there any plan/idea on supporting stdio besides a more "normal" setup?

The bothersome part of this solution is that I need to start esbonio manually and put it in the background before starting helix

How are you running esbonio? I assume something like python -m esbonio --port 6666?

Is there any plan/idea on supporting stdio besides a more "normal" setup?

If you drop the --port argument, esbonio will start in stdio mode instead. I'm a little surprised you found the TCP mode first... though that said I've just noticed the cli help text never mentions stdio at all! πŸ˜…

How are you running esbonio? I assume something like python -m esbonio --port 6666?

Yes, exactly, with a little & at the end to send it to the background.

I'm not at all used to setting up LSPs on my own, usually IDEs/editors do it for me, so I simply assumed that the word server always implied a TCP connection to some process. :D The --port argument made sense to me in this case. I never thought that the stdio mode was the default so yeah, maybe quickly mentioning it in the CLI text helps!

Dropping the --port argument and using the following as part of my ~/.config/helix/languages.toml file

[[language]]
name = "rst"
scope = "text.rst"
file-types = ["rst", "rest"]
indent = { tab-width = 3, unit = "   " }
language-servers = [ "esbonio" ]

[[grammar]]
name = "rst"
source = { git = "https://github.com/stsewd/tree-sitter-rst", rev = "25e6328872ac3a764ba8b926aea12719741103f1" }

[language-server.esbonio]
command = "esbonio"

works with my docs project (i.e. my references show up!), and helix even reports the LSP as properly configured

$ hx --health rst
Configured language servers:
  βœ“ esbonio: /path/to/project/.direnv/python-3.10.12/bin/esbonio
Configured debug adapter: None
Configured formatter: None
Highlight queries: βœ“
Textobject queries: ✘
Indent queries: ✘

So no changes needed :) Thanks for the hint!