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

Refactoring directives support #453

Merged
merged 12 commits into from
Oct 15, 2022
Merged

Refactoring directives support #453

merged 12 commits into from
Oct 15, 2022

Conversation

alcarney
Copy link
Member

@alcarney alcarney commented Sep 30, 2022

Building on the DirectiveLanguageFeatures introduced in #444, this PR introduces a number of new methods features can implement

  • index_directives: used to discover available directive implementations
  • suggest_directives: used to determine which directive names can be suggested in the current completion context (function vs py:function vs c:function etc.)
  • get_implementation: used to go from a directive name (function vs py:function) to its implementation
  • suggest_options: used to determine which directive options can be suggested in the current completion context

This should also enable implementing other features such as #105, #312 , #414 etc.

Finally, both <primary_domain>:function and function are offered as completion suggestions as they are both valid.
Working towards #416

Previously, the "core" language server class has been responsible for
indexing and generating completions for directives. This functionality
has now been moved out into the `Directives` language feature which
actually delegates this task to any of the `DirectiveLanguageFeatures`
that have been registered.

Additionally, up until now there has been no distinction made between
indexing directives, generating completion suggestions and "rendering"
these into `CompletionItem` instances. However, since the `function::`
directive in the Python domain can be referenced through both `function`
and `py:function` it's important recognise these as distinct steps.

Therefore generating completions for directives is now split into the
following steps.

- indexing: Discovery of available directive implementations
- suggesting: Suggesting the "names" that can be used for a given
  directive in a given context (e.g. `function` and `py:function`)
- rendering: Taking the list of suggested names and converting them into
  `CompletionItem` objects to send to the client.

`DirectiveLanguageFeatures` are responsible for the first two steps and
can implement the `index_directives` and `suggest_directives` methods
while the final rendering step is handled by the `Directives` language
feature itself.

The `RstLanguageServer.get_directives()` method has been deprecated in
favour of the new method with the same name on the `Directives` language
feature.
Since `DirectiveLanguageFeatures` are now responsible for discovering
the available directives, they are also the best suited to determine
which options a directive has.

Subclasses can now implement the `suggest_options` method to provide
this functionality.

Additionally, in order to correctly determine the correct implementation
given some name for a directive we need to be able to do the inverse of
the index -> suggest step of generating completions. So
`DirectiveLanguageFeatures` that provide directive implementations
should also implement the `get_implementation` method.
This aligns docutils support to the new `DirectiveLanguageFeature` API.
This aligns support for Sphinx's domains to the new
`DirectiveLanguageFeaure` API
This aligns support to the new `DirectiveLanguageFeature` API
The `DirectiveLanguageFeature` API introduces a few subtle changes, this
aligns the test suite to match
This adds a how to guide on providing support for new directive
registries using a `DirectiveLanguageFeature`

This also introduces some doctests for the directive regular
expressions.
@alcarney alcarney changed the title [WIP] Refactoring domain support Refactoring directive support Oct 15, 2022
@alcarney alcarney changed the title Refactoring directive support Refactoring directives support Oct 15, 2022
@alcarney alcarney marked this pull request as ready for review October 15, 2022 19:36
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.

1 participant