-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lsp: Return completion suggestions from Sphinx
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lib/esbonio/esbonio/server/features/sphinx_support/directives.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import List | ||
from typing import Optional | ||
|
||
from esbonio import server | ||
from esbonio.server.features import directives | ||
from esbonio.server.features.sphinx_manager import SphinxManager | ||
|
||
|
||
class SphinxDirectives(directives.DirectiveProvider): | ||
"""Support for directives in a sphinx project.""" | ||
|
||
def __init__(self, manager: SphinxManager): | ||
self.manager = manager | ||
|
||
async def suggest_directives( | ||
self, context: server.CompletionContext | ||
) -> Optional[List[directives.Directive]]: | ||
"""Given a completion context, suggest directives that may be used.""" | ||
|
||
if (client := await self.manager.get_client(context.uri)) is None: | ||
return None | ||
|
||
result: List[directives.Directive] = [] | ||
for name, implementation in await client.get_directives(): | ||
result.append( | ||
directives.Directive(name=name, implementation=implementation) | ||
) | ||
|
||
return result | ||
|
||
|
||
def esbonio_setup( | ||
sphinx_manager: SphinxManager, | ||
directive_feature: directives.DirectiveFeature, | ||
): | ||
provider = SphinxDirectives(sphinx_manager) | ||
directive_feature.add_provider(provider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Directives | ||
========== | ||
|
||
The language server has extensive support for directives. | ||
|
||
Completion | ||
---------- | ||
|
||
The most obvious feature is the completion suggestions, try inserting a ``.. note::`` directive on the next line | ||
|
||
.. Add your note here... | ||
Notice how VSCode automatically presented you with a list of all the directives you can use in this Sphinx project? | ||
|
||
Goto ... | ||
-------- | ||
|
||
The language server also provides a number of "Goto" navigation commands. | ||
On the ``.. note::`` directive you inserted above, try each of the following commands | ||
|
||
- ``Implementation`` goto the source code that implements the selected directive |