-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] add docstrings to completions based on type #20008
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
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
Screen.Recording.2025-08-20.at.1.52.03.PM.mov |
@@ -421,7 +421,7 @@ impl Workspace { | |||
.into_iter() | |||
.map(|completion| Completion { | |||
kind: completion.kind(&self.db).map(CompletionKind::from), | |||
name: completion.name.into(), | |||
name: completion.inner.name.into(), |
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.
It would be nice to also hook up documentation in the playground. You have to add a new documentation
field to Completion
, then propagate the field here
ruff/playground/ty/src/Editor/Editor.tsx
Line 321 in 8c0743d
insertText: completion.name, |
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 think done? Never tested the playground.
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.
Nice
|
||
pub struct DetailedCompletion<'db> { | ||
pub inner: Completion<'db>, | ||
pub documentation: Option<Docstring>, |
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.
Should we make this a field on Completion
instead that defaults to None
: Given that completion
is the only method constructing the completions
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.
Currently that doesn't work out because Docstring is defined in ty_ide and Completion is defined in ty_python_semantic. The crate boundaries have gotten quite wobbly 😅
* main: (29 commits) [ty] add docstrings to completions based on type (#20008) [`pyupgrade`] Avoid reporting `__future__` features as unnecessary when they are used (`UP010`) (#19769) [`flake8-use-pathlib`] Add fixes for `PTH102` and `PTH103` (#19514) [ty] correctly ignore field specifiers when not specified (#20002) `Option::unwrap` is now const (#20007) [ty] Re-arrange "list modules" implementation for Salsa caching [ty] Test "list modules" versus "resolve module" in every mdtest [ty] Wire up "list modules" API to make module completions work [ty] Tweak some completion tests [ty] Add "list modules" implementation [ty] Lightly expose `FileModule` and `NamespacePackage` fields [ty] Add some more helper routines to `ModulePath` [ty] Fix a bug when converting `ModulePath` to `ModuleName` [ty] Split out another constructor for `ModuleName` [ty] Add stub-file tests to existing module resolver [ty] Expose some routines in the module resolver [ty] Add more path helper functions [`flake8-annotations`] Remove unused import in example (`ANN401`) (#20000) [ty] distinguish base conda from child conda (#19990) [ty] Fix server hang (#19991) ...
This is a fairly simple but effective way to add docstrings to like 95% of completions from initial experimentation. Fixes astral-sh/ty#1036 Although ironically this approach *does not* work specifically for `print` and I haven't looked into why.
This is a fairly simple but effective way to add docstrings to like 95% of completions from initial experimentation.
Fixes astral-sh/ty#1036
Although ironically this approach does not work specifically for
print
and I haven't looked into why.