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

Migrate to pygls v1.0 #484

Merged
merged 10 commits into from Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/lsp-pr.yml
Expand Up @@ -16,11 +16,6 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, windows-latest, macos-latest]

include:
- os: ubuntu-20.04
python-version: "3.6"


steps:
- uses: actions/checkout@v3

Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -24,3 +24,18 @@ repos:
- id: isort
name: isort (python)
args: [--settings-file=lib/esbonio/pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.991'
hooks:
- id: mypy
name: mypy (esbonio)
args: [--config,lib/esbonio/pyproject.toml]
additional_dependencies:
- pygls
- pytest_lsp
- sphinx
- types-appdirs
- types-docutils
- types-pygments
files: 'lib/esbonio/esbonio/.*\.py'
15 changes: 5 additions & 10 deletions docs/conf.py
Expand Up @@ -15,10 +15,10 @@
sys.path.insert(0, os.path.abspath("../lib/esbonio"))
sys.path.insert(0, os.path.abspath("./ext"))

import pygls.lsp.methods as M
from docutils.parsers.rst import nodes
from pygls.lsp.types import CompletionItem
from pygls.lsp.types import CompletionItemKind
from lsprotocol.types import METHOD_TO_TYPES
from lsprotocol.types import CompletionItem
from lsprotocol.types import CompletionItemKind
from sphinx.application import Sphinx

import esbonio.lsp
Expand Down Expand Up @@ -49,7 +49,6 @@
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinxcontrib.autodoc_pydantic",
"esbonio.relevant_to",
"esbonio.tutorial",
"cli_help",
Expand Down Expand Up @@ -107,12 +106,8 @@ def __init__(self) -> None:
def _index_methods(self):
self.items = []

for name, meth in M.__dict__.items():

if not isinstance(meth, str) or not name.isupper():
continue

item = CompletionItem(label=meth, kind=CompletionItemKind.Constant)
for method in METHOD_TO_TYPES.keys():
item = CompletionItem(label=method, kind=CompletionItemKind.Constant)
self.items.append(item)

def complete_targets(
Expand Down
10 changes: 5 additions & 5 deletions docs/lsp/extending/directives/directive-registry.rst
Expand Up @@ -44,7 +44,7 @@ This method should return a dictionary where the keys are the canonical name of
def __init__(self, app: Sphinx):
self.app = app # Sphinx application instance.

def index_directives(self) -> Dict[str, Directive]:
def index_directives(self) -> Dict[str, Type[Directive]]:
directives = {}
for prefix, domain in self.app.domains.items():
for name, directive in domain.directives.items():
Expand Down Expand Up @@ -74,12 +74,12 @@ The :meth:`~DirectiveLanguageFeature.suggest_directives` method is called each t
It can be used to tailor the list of directives that are offered to the user, depending on the current context.
Each ``DirectiveLanguageFeature`` has a default implementation, which may be sufficient depending on your use case::

def suggest_directives(self, context: CompletionContext) -> Iterable[Tuple[str, Directive]]:
def suggest_directives(self, context: CompletionContext) -> Iterable[Tuple[str, Type[Directive]]]:
return self.index_directives().items()

However, in the case of Sphinx domains, we need to modify this to also include the short form of the directives in the standard and primary domains::

def suggest_directives(self, context: CompletionContext) -> Iterable[Tuple[str, Directive]]:
def suggest_directives(self, context: CompletionContext) -> Iterable[Tuple[str, Type[Directive]]]:
directives = self.index_directives()
primary_domain = self.app.config.primary_domain

Expand All @@ -103,12 +103,12 @@ The :meth:`~DirectiveLanguageFeature.get_implementation` method is used by the l
This powers features such as documentation hovers and goto implementation.
As with ``suggest_directives``, each ``DirectiveLanguageFeature`` has a default implementation which may be sufficient for your use case::

def get_implementation(self, directive: str, domain: Optional[str]) -> Optional[Directive]:
def get_implementation(self, directive: str, domain: Optional[str]) -> Optional[Type[Directive]]:
return self.index_directives().get(directive, None)

In the case of Sphinx domains, if we see a directive without a domain prefix we need to see if it belongs to the standard or primary domains::

def get_implementation(self, directive: str, domain: Optional[str]) -> Optional[Directive]:
def get_implementation(self, directive: str, domain: Optional[str]) -> Optional[Type[Directive]]:
directives = self.index_directives()

if domain is not None:
Expand Down
5 changes: 0 additions & 5 deletions docs/lsp/how-to.rst
@@ -1,7 +1,2 @@
How To
======

.. toctree::
:glob:

how-to/*
38 changes: 0 additions & 38 deletions docs/lsp/how-to/get-debug-info.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/requirements.txt
@@ -1,7 +1,6 @@
# This assumes you are running the pip install command from the root of the repo e.g.
# $ pip install -r docs/requirements.txt
sphinx
autodoc-pydantic
furo
pytest_lsp
-e lib/esbonio
Expand Down
3 changes: 2 additions & 1 deletion lib/esbonio/MANIFEST.in
@@ -1,3 +1,4 @@
include esbonio/py.typed
include esbonio/cli/py.typed
include esbonio/lsp/py.typed
include esbonio/lsp/rst/*.json
include esbonio/lsp/sphinx/*.json
1 change: 1 addition & 0 deletions lib/esbonio/changes/400.misc.rst
@@ -0,0 +1 @@
Drop Python 3.6 support
1 change: 1 addition & 0 deletions lib/esbonio/changes/484.misc.rst
@@ -0,0 +1 @@
Migrate to pygls ``v1.0``
Expand Up @@ -2,6 +2,17 @@
import logging
import sys
import warnings
from typing import Union

from pygls.protocol import default_converter
from typing_extensions import Literal


def esbonio_converter():
converter = default_converter()
converter.register_structure_hook(Union[Literal["auto"], int], lambda obj, _: obj)

return converter


def setup_cli(progname: str, description: str) -> argparse.ArgumentParser:
Expand Down Expand Up @@ -88,7 +99,12 @@ def main(cli: argparse.ArgumentParser):
warnlog.addHandler(handler)

server = create_language_server(
args.server_cls, modules, name="esbonio", version=__version__
args.server_cls,
modules,
name="esbonio",
version=__version__,
# TODO: Figure out how to make this extensible
converter_factory=esbonio_converter,
)

if args.port:
Expand Down
File renamed without changes.