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

Fix type-based code completion for some LSPs #62

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

ikalnytskyi
Copy link
Owner

It turns out that picobox.Stack() is missing few key type annotations that breaks autocompletion for some LSP servers. For instance, in the following code example:

@dataclasses.dataclass
class Struct:
    value: int

@picobox.pass_("value")
def pack(value: int) -> Struct:
    return Struct(value=value)

with picobox.push(picobox.Box()) as box:
    box.put("value", 42)
    value = pack(42).value

there are two broken autocompletion points:

  • .put() is not completed for the box variable
  • .value is not completed for the struct type returned by pack()

This patch fixes these scenarios by (1) annotating that picobox.push() returns a context manager, and (2) avoiding using too-much-dynamic expressions in picobox.pass_() which return type cannot be easily inferred.

It turns out that `picobox.Stack()` is missing few key type annotations
that breaks autocompletion for some LSP servers. For instance, in the
following code example:

    @dataclasses.dataclass
    class Struct:
        value: int

    @picobox.pass_("value")
    def pack(value: int) -> Struct:
        return Struct(value=value)

    with picobox.push(picobox.Box()) as box:
        box.put("value", 42)
        value = pack(42).value

there are two broken autocompletion points:

 * `.put()` is not completed for the `box` variable
 * `.value` is not completed for the struct type returned by `pack()`

This patch fixes these scenarios by (1) annotating that `picobox.push()`
returns a context manager, and (2) avoiding using too-much-dynamic
expressions in `picobox.pass_()` which return type cannot be easily
inferred.
@ikalnytskyi ikalnytskyi merged commit 12c4b7d into master Oct 5, 2023
@ikalnytskyi ikalnytskyi deleted the bug/type-annotate-stack branch October 5, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant