Skip to content

Commit

Permalink
lsp: Implement support for the .. default-domain:: directive
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Jan 13, 2024
1 parent 4a5f1d1 commit eb0c4e0
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/esbonio/esbonio/server/features/sphinx_support/directives.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from typing import List
from typing import Optional
from __future__ import annotations

import typing

from lsprotocol import types

from esbonio import server
from esbonio.server.features import directives
from esbonio.server.features.sphinx_manager import SphinxManager

if typing.TYPE_CHECKING:
from typing import List
from typing import Optional


class SphinxDirectives(directives.DirectiveProvider):
"""Support for directives in a sphinx project."""
Expand All @@ -20,14 +27,25 @@ async def suggest_directives(
if (client := await self.manager.get_client(context.uri)) is None:
return None

# TODO .. default-domain:: support
# Does the document have a default domain set?
results = await client.find_symbols(
uri=str(context.uri.resolve()),
kind=types.SymbolKind.Class.value,
detail="default-domain",
)
if len(results) > 0:
default_domain = results[0][1]
else:
default_domain = None

primary_domain = await client.get_config_value("primary_domain")
active_domain = default_domain or primary_domain or "py"

result: List[directives.Directive] = []
for name, implementation in await client.get_directives():
# Also suggest unqualified versions of directives from the primary_domain.
if name.startswith(f"{primary_domain}:"):
short_name = name.replace(f"{primary_domain}:", "")
# Also suggest unqualified versions of directives from the currently active domain.
if name.startswith(f"{active_domain}:"):
short_name = name.replace(f"{active_domain}:", "")
result.append(
directives.Directive(name=short_name, implementation=implementation)
)
Expand Down

0 comments on commit eb0c4e0

Please sign in to comment.