Skip to content

Commit

Permalink
Merge pull request #533 from yukinarit/fix-completion-for-lsp
Browse files Browse the repository at this point in the history
Fix broken code completion for LSP and jedi
  • Loading branch information
yukinarit authored May 31, 2024
2 parents 858d658 + 912feda commit ad0aa3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pytest-xdist = "^3.5.0"
types-PyYAML = "^6.0.9"
msgpack-types = "^0.3"
envclasses = "^0.3.1"
jedi = "*"

[tool.poetry.extras]
msgpack = ["msgpack"]
Expand Down
6 changes: 3 additions & 3 deletions serde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from dataclasses import dataclass
from collections.abc import Callable
from typing import Optional, overload, Any
from typing import Optional, overload, Any, Type

from typing_extensions import dataclass_transform

Expand Down Expand Up @@ -113,7 +113,7 @@

@overload
def serde(
_cls: type[T],
_cls: Type[T],
rename_all: Optional[str] = None,
reuse_instances_default: bool = True,
convert_sets_default: bool = False,
Expand All @@ -124,7 +124,7 @@ def serde(
serialize_class_var: bool = False,
class_serializer: Optional[ClassSerializer] = None,
class_deserializer: Optional[ClassDeserializer] = None,
) -> type[T]: ...
) -> Type[T]: ...


@overload
Expand Down
23 changes: 23 additions & 0 deletions tests/test_code_completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import jedi


def test_jedi() -> None:
source = """
from serde import serde
@serde
class Foo:
a: int
b: float
c: str
baz: bool
foo = Foo(10, 100.0, "foo", True)
"""
source_completion = source + "\n" + "foo."
jedi_script = jedi.Script(source_completion, path="foo.py")
completions = jedi_script.complete(9, len("foo."))
completions = [comp.name for comp in completions]
assert "a" in completions
assert "b" in completions
assert "c" in completions

0 comments on commit ad0aa3e

Please sign in to comment.