Skip to content

Instead of returning an empty array in prepareTypeHierarchy, sourcekit-lsp should return nil #1178

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

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 16, 2024

Eg. when requesting type hierarchy of a class when the project hasn’t been built, sourcekit-lsp returns an empty array. That causes VS Code to fail with very ambiguous error messages

  • MISSING provider
  • Cannot read properties of null (reading 'kind')

To work around this, instead of returning an empty array, return nil instead.

rdar://126228814

…kit-lsp should return `nil`

Eg. when requesting type hierarchy of a class when the project hasn’t been built, sourcekit-lsp returns an empty array. That causes VS Code to fail with very ambiguous error messages
- MISSING provider
- Cannot read properties of null (reading 'kind')

To work around this, instead of returning an empty array, return `nil` instead.

rdar://126228814
@ahoppen ahoppen requested a review from bnbarham April 16, 2024 18:26
@ahoppen ahoppen requested a review from benlangmuir as a code owner April 16, 2024 18:26
@ahoppen ahoppen force-pushed the nil-for-empty-prepare-type-hierarchy branch from 5b0caf1 to f482982 Compare April 16, 2024 18:26
@ahoppen
Copy link
Member Author

ahoppen commented Apr 16, 2024

@swift-ci Please test

@@ -2291,6 +2291,13 @@ extension SourceKitLSPServer {
}
.sorted(by: { $0.name < $1.name })

if typeHierarchyItems.isEmpty {
// When returning an empty array, VS Code fails with the following two errors. Returning `nil` works around those
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is because it always expects at least the original element itself? Does call hierarchy have the same issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Call hierarchy doesn’t seem to have that issue.

@dschaefer2
Copy link
Member

You're ahead of me. :). Saw that today too. Thanks!

@ahoppen ahoppen merged commit 63171ab into swiftlang:main Apr 17, 2024
3 checks passed
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.

3 participants