WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Nov 19, 2025

fix #1418

image

Added metadata-backed hover names by threading a display_name through every FindDefinitionItemWithDocstring so hover headers can still show identifiers even when we land in stub files or empty ranges.

Updated the hover formatter to try definition snippets, the metadata name, a type-derived fallback, and finally a lexical identifier; this restored headers for third-party symbols and ensured both WASM and native LSP paths behave identically

Introduced rich function rendering: callable tooltips now show (function) name plus a syntactically valid def name(...): ..., improving syntax highlighting in VS Code for cases like np.array.

@meta-cla meta-cla bot added the cla signed label Nov 19, 2025
@asukaminato0721
Copy link
Contributor Author

asukaminato0721 commented Nov 19, 2025

improve #1416

image

@asukaminato0721
Copy link
Contributor Author

fix #1348

image

@asukaminato0721 asukaminato0721 marked this pull request as ready for review November 19, 2025 17:10
Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! A few questions

it's unclear why these names are missing from your summary. are all of these bugs the same situation?

do we need all of these fallbacks? which ones are necessary in which situations?

I would like to see all this logic localized to one section. can this entire PR be a change to pyrefly/crates/pyrefly_types/src/display.rs?

@asukaminato0721
Copy link
Contributor Author

Resolver didn’t keep a textual name when the definition expression was empty (e.g., stub attributes, keyword arguments, or type-only nodes). Fix: FindDefinitionItemWithDocstring now always carries a display_name, so when we do have definition metadata, we reuse that string.

Type-only lookup path – when we fail to find any definition (third-party binary stubs), we still need something readable. That’s why we fall back to metadata from Type::Function/Callable/BoundMethod/Forall.

Literal identifier under the cursor – in the degenerate case where neither of the above provides anything (e.g., a failing resolver on a local scratch buffer), we lex the identifier so we can at least echo the token.

@kinto0 kinto0 self-assigned this Nov 20, 2025
Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still a few unresolved comments about API changes: this diff adds a few layers of indirection. can we instead have as_hover_string take a fallback name and contain the logic there?

Copilot AI review requested due to automatic review settings December 3, 2025 05:52
Copilot finished reviewing on behalf of asukaminato0721 December 3, 2025 05:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #1418 where numpy function hovers were missing function names. The fix implements a comprehensive multi-layered fallback mechanism to ensure hover tooltips always display identifiable names, even for third-party symbols defined in stub files.

Key Changes:

  • Added display_name field to FindDefinitionItemWithDocstring to thread identifier names through definition lookups
  • Implemented multi-tier fallback for hover names: definition snippet → metadata name → type-derived name → lexical identifier
  • Enhanced callable type rendering with def name(...) syntax for improved readability and syntax highlighting

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pyrefly/lib/test/lsp/lsp_interaction/hover.rs Added integration test verifying third-party function names appear in hover tooltips
pyrefly/lib/test/lsp/hover.rs Updated test expectation to include def __matmul__( syntax in method hover display
pyrefly/lib/state/lsp.rs Added display_name field to FindDefinitionItemWithDocstring struct and populated it in all instantiation sites; updated destructuring patterns to handle new field
pyrefly/lib/lsp/wasm/hover.rs Implemented fallback mechanisms (fallback_hover_name_from_type, identifier_text_at) and integrated multi-layered name resolution into hover logic; added unit tests
pyrefly/lib/lsp/non_wasm/server.rs Updated destructuring patterns to ignore new display_name field with ..
crates/pyrefly_types/src/display.rs Added as_hover_string_with_fallback_name to format callable types with def name(...) syntax when name is provided

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numpy function hover missing name

2 participants