Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial completionItem/resolve support #284

Merged
merged 14 commits into from Feb 12, 2022

Conversation

alcarney
Copy link
Member

@alcarney alcarney commented Feb 5, 2022

  • Adds completionItem/resolve support to the language server, and for role, directive and directive options.
    Closes Investigate completionItem/resolve requests #274
  • Adds the ability to register documentation for roles as well as directives and their options which will get added to relevant CompletionItems during a completionItem/resolve request.
  • Adds a script to scrape the docutils documentation site for role and directive documentation while converting it into a format that's useful to the language server.
  • Adds a script to scrape the Sphinx documentation site for role and directive documentation while converting it into a format that's useful to the language server.
    Closes Better directive completions #36

This PR supersedes #251.

The way to reference language features is now `full.module.path.Class`
so for example the `roles` feature is now referred to as
`esbonio.lsp.roles.Roles`.

This removes allows us to be much more precise about referencing
features going forward.
@alcarney alcarney force-pushed the completion-resolve branch 3 times, most recently from de01f89 to 6ecd97d Compare February 12, 2022 12:07
This is to cope with directives like `.. rst:directive:option::`
The language server now advertises `completionItem/resolve` support.
There is also a new `completion_resolve` method on
`LanguageFeatures` that is called whenever a client asks for more
details on a `CompletionItem` produced by that feature.
Since directive implementations can be overriden, the name of a
directive is not a reliable way to identify them. So we now use
the `detail` field on a `CompletionItem` to carry the fully
qualified name of the class that implements them.

With some additional metadata in the `data` field on a
`CompletionItem`, the directives language feature now uses the
`completionItem/resolve` request to provide documentation for
a directive and its options.

This relies on the langauge feature being loaded up with the
documentation for the relevant items as it typically not available
as docstrings on the implementation. This is done through the
`add_documentation` method and by default the language server will
look for the following files.

- `esbonio/lsp/rst/directives.json`
- `esbonio/lsp/sphinx/directives.json`

Which should contain the documentation for `docutils` and `sphinx`
directives respectively.
This adds the `scripts/generate_docutils_documentation.py` script which
pulls the latest rst source files for the reference directive and roles
documentation pages from the docutils docs site.

Example usage:

   python scripts/generate_docutils_documentation.py -o lib/esbonio/esbonio/lsp/rst/

The script produces a file `directives.json` with the following
structure

```
{
  "name(module.path.ClassName)": {
    "is_markdown": true,
    "description": [
      "# Some title",
      "This is useful when...",
      ...
    ]
    "options": {
      "opt1": "...",
      ...
    }
  }
}
```

As well as a file `roles.json` with a similar structure

This corresponds with the dictionary structure expected by the
`Directives` and `Roles` language features.

This commit also adds the result of running the script.
This script uses the `objects.inv` file published by the Sphinx
documentation site to discover and scrape the documentation for roles
and directives added by Sphinx. The resulting documentation is then
saved as a JSON file that can be loaded by the language server.

It is far from perfect but its probably good enough for now and we can
continue to refine it over time.

This commit also adds the result of running the script.
@alcarney alcarney marked this pull request as ready for review February 12, 2022 12:58
@alcarney alcarney merged commit 281a795 into swyddfa:develop Feb 12, 2022
@alcarney alcarney deleted the completion-resolve branch February 12, 2022 19:09
@alcarney alcarney mentioned this pull request Feb 12, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate completionItem/resolve requests Better directive completions
1 participant