-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Use markdown for completions documentation #21752
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
base: main
Are you sure you want to change the base?
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
crates/ty_ide/src/symbols.rs
Outdated
| kind: SymbolKind::Class, | ||
| name_range: class_def.name.range(), | ||
| full_range: stmt.range(), | ||
| documentation: class_def.definition(&self.model).docstring(self.model.db()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty worried about doing this eagerly for every single symbol in an environment. I did some very ad hoc testing to compare perf here. On main with this pyproject.toml:
[project]
name = "ex003-reexport-simple"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"matplotlib>=3.10.7",
"numpy>=2.3.4",
"pandas>=2.3.3",
"scikit-learn>=1.7.2",
"scipy>=1.16.3",
"whenever>=0.9.3",
]And this Python source file:
arrayWith my cursor right after array.
I get this in the trace logs after requesting completions at my cursor position a few times:
2025-12-02 09:59:31.888839440 DEBUG request{id=13 method="textDocument/completion"}: Completions request returned 1582 suggestions in 177.106611ms
2025-12-02 09:59:34.297544175 DEBUG request{id=15 method="textDocument/completion"}: Completions request returned 1582 suggestions in 56.358747ms
2025-12-02 09:59:36.489098862 DEBUG request{id=17 method="textDocument/completion"}: Completions request returned 1582 suggestions in 57.155421ms
2025-12-02 09:59:38.932666244 DEBUG request{id=20 method="textDocument/completion"}: Completions request returned 1582 suggestions in 57.014757ms
2025-12-02 09:59:42.342361845 DEBUG request{id=22 method="textDocument/completion"}: Completions request returned 1582 suggestions in 58.887699ms
2025-12-02 09:59:45.683431792 DEBUG request{id=24 method="textDocument/completion"}: Completions request returned 1582 suggestions in 57.7364ms
Now with this PR, I do the same test and I get:
2025-12-02 10:02:13.280166325 DEBUG request{id=13 method="textDocument/completion"}: Completions request returned 1582 suggestions in 139.561616ms
2025-12-02 10:02:16.136079062 DEBUG request{id=15 method="textDocument/completion"}: Completions request returned 1582 suggestions in 73.513749ms
2025-12-02 10:02:18.525222384 DEBUG request{id=17 method="textDocument/completion"}: Completions request returned 1582 suggestions in 71.187676ms
2025-12-02 10:02:20.888572941 DEBUG request{id=19 method="textDocument/completion"}: Completions request returned 1582 suggestions in 71.481457ms
2025-12-02 10:02:23.408312653 DEBUG request{id=21 method="textDocument/completion"}: Completions request returned 1582 suggestions in 70.057387ms
2025-12-02 10:02:26.422923788 DEBUG request{id=23 method="textDocument/completion"}: Completions request returned 1582 suggestions in 72.955201ms
Which seems like a noticeable dip to me. And this probably isn't that big of a Python project either.
So I think I'd prefer to hold off on doing this eagerly with auto-import specifically. I think it looks like that should be done via a resolve request.
An alternative that still involves eagerly getting the docstring is to:
- Only do it for symbols that match the query given.
- Perhaps only do it for the first N such symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah okay, resolve request sounds a lot better.
I can revert these changes and add them to another PR adding resolve completion. Do you think we should defer the auto import too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! What do you mean by defer the auto import too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean defer generating the edit for unimported symbols.
I'm not sure how expensive this is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave that for now personally. It isn't obviously slow to me, and I wrote it to amortize most work so that the unit of work done per completion is pretty small (but still not fully optimal from a quick glance).
Summary
Make documentation markdown for completions, which, in zed, moves the documentation to the right of the completions panel, rather than inside it.
Also add documentation for class and function definitions
Test Plan
e2e test.