Skip to content

Commit

Permalink
docs: Add support for multiple versions of a client
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Oct 21, 2023
1 parent fcceee7 commit 6386b6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 26 additions & 3 deletions docs/ext/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import pathlib
import re
import typing
from typing import Dict
from typing import List
from typing import Optional

import attrs
from docutils import nodes
from docutils.parsers.rst import directives
from lsprotocol import types
from lsprotocol.converters import get_converter
from packaging.version import parse as parse_version
from pygls.capabilities import get_capability
from sphinx.application import Sphinx
from sphinx.domains import Domain
Expand Down Expand Up @@ -37,19 +40,39 @@ def build_header(self):

return header, colspecs

def build_body(self, capability: str):
rows = []
def get_client_support_for(self, capability: str) -> Dict[str, Optional[str]]:
"""Build a dictionary containing the clients that support the given capability
as well as the version that support was introduced in."""
domain = self.env.domains["capabilities"]

clients: Dict[str, Optional[str]] = {}
for (name, version), capabilities in domain.clients.items():
supported = get_capability(capabilities, capability, False)

if not supported:
if name not in clients:
clients[name] = None
continue

if (existing := clients.get(name, None)) is None:
clients[name] = version
else:
clients[name] = min(existing, version, key=parse_version)

return clients

def build_body(self, capability: str):
rows = []
clients = self.get_client_support_for(capability)

for name, version in clients.items():
rows.append(
nodes.row(
"",
nodes.entry("", nodes.Text(name)),
nodes.entry(
"",
nodes.Text(version if supported else " - "),
nodes.Text(version or " - "),
classes=["centered"],
),
)
Expand Down
4 changes: 3 additions & 1 deletion docs/ext/supported_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from docutils import nodes
from docutils.parsers.rst import Directive
from packaging.version import parse as parse_version
from sphinx.application import Sphinx


Expand All @@ -26,6 +27,7 @@ def run(self):
clients = self.load_clients()

for client, versions in clients.items():
version_string = ", ".join(sorted(versions, key=parse_version))
rows.append(
nodes.row(
"",
Expand All @@ -35,7 +37,7 @@ def run(self):
),
nodes.entry(
"",
nodes.paragraph("", ", ".join(versions)),
nodes.paragraph("", version_string),
),
),
)
Expand Down

0 comments on commit 6386b6e

Please sign in to comment.