swyddfa / esbonio

A language server for working with Sphinx projects.
https://docs.esbon.io/
131 stars 21 forks source link

Search conf.py from bottom to top #415

Closed stsewd closed 11 months ago

stsewd commented 2 years ago

Hi, thanks for creating this!

When searching the conf.py file, currently esbonio starts looking from the root of the project, but often big projects may have separate set of docs on the same project, or a project could have several sphinx projects as test data, or even a file named conf.py somewhere in their code, this leads to esbonio using the wrong conf.py file for a given rst file.

Another approach to look for the conf.py file given a rst file would be from bottom to top, which I think will give more accurate results, as the conf.py file usually is the root of the source directory (also true for sphinx projects that user the docs/source structure).

I'm not that familiar with the internals of LSP, so not sure if this is possible or if it goes against the "rules".

alcarney commented 2 years ago

I'm sure it is possible, just not something that has been implemented yet :smile:

Currently the language server only supports a single Sphinx project, mostly due to Sphinx/docutils relying on a certain amount of global state. I have a few ideas for how support for multiple projects may be added, but right now I'm focusing on making it work well for a single project.

this leads to esbonio using the wrong conf.py file for a given rst file.

The server does provide options (like esbonio.sphinx.confDir) that allow you to override the default discovery mechanism if it's finding the wrong conf.py. However, it's probably not that useful if you're trying to work on multiple projects at once.

Another approach to look for the conf.py file given a rst file would be from bottom to top,

If I'm understanding what you mean by "bottom to top" correctly then I really like this idea! I can imagine that when support for multiple projects comes along, Sphinx applications could be lazily created on demand using the conf.py that's found by traversing up the directory tree from the current rst file.

thanks for creating this!

Thanks for taking an interest in this! :smile:

lextm commented 1 year ago

vscode-restructuredtext extension scans the working directory to locate all conf.py files, and allows users to choose which one should be used for live preview/LSP,

https://docs.restructuredtext.net/articles/preview#preview-mode-selection

alcarney commented 11 months ago

This is now implemented as part of the upcoming v1 of the server