Implement textDocument/typeDefinition request#2445
Conversation
|
i might have missed something because i was going back and forth , lets see |
|
I’ll start reviewing this after #2436 is merged and you can rebase this on top of |
486f903 to
df6ce2c
Compare
b5ed7e9 to
d8b8d71
Compare
c6ad839 to
94ad50d
Compare
ahoppen
left a comment
There was a problem hiding this comment.
Very nice. I think the biggest thing will be to reconcile the resolving of the definition’s USR with indexBasedDefinition now.
| return nil | ||
| } | ||
|
|
||
| // Try cursorInfo with USR lookup first - it knows the current in-memory state |
There was a problem hiding this comment.
There’s no second here, so I think the comment no longer applies
| let location = typeInfo.symbolInfo.bestLocalDeclaration | ||
| { | ||
| return .locations([location]) | ||
| } |
There was a problem hiding this comment.
Similar to my comments in the inlay type hints PR, this doesn’t handle jumping to generated interfaces. Instead of doing another ad-hoc fix like you did in the inlay hints PR, I’d really like to see this unified with the logic in indexBasedJumpToDefinition. Could you look into how we can best re-use code between both that function, inlay hints resolve and the type definition request?
| func testTypeDefinitionClassType() async throws { | ||
| let testClient = try await TestSourceKitLSPClient() | ||
| let uri = DocumentURI(for: .swift) | ||
|
|
||
| let positions = testClient.openDocument( | ||
| """ | ||
| class 1️⃣MyClass {} | ||
| let 2️⃣instance = MyClass() | ||
| """, | ||
| uri: uri | ||
| ) | ||
|
|
||
| let response = try await testClient.send( | ||
| TypeDefinitionRequest( | ||
| textDocument: TextDocumentIdentifier(uri), | ||
| position: positions["2️⃣"] | ||
| ) | ||
| ) | ||
|
|
||
| guard case .locations(let locations) = response, let location = locations.first else { | ||
| XCTFail("Expected location response") | ||
| return | ||
| } | ||
|
|
||
| XCTAssertEqual(location.uri, uri) | ||
| XCTAssertEqual(location.range, Range(positions["1️⃣"])) | ||
| } | ||
|
|
||
| func testTypeDefinitionEnumType() async throws { |
There was a problem hiding this comment.
Classes and enums are just the same as a struct in the type system, so these two tests don’t really provide much value and I think we can delete them.
| completionProvider: completionOptions, | ||
| signatureHelpProvider: signatureHelpOptions, | ||
| definitionProvider: .bool(true), | ||
| typeDefinitionProvider: .bool(true), |
There was a problem hiding this comment.
Can you also advertise the typeDefinitionProvider here?
| func typeDefinition(_ request: TypeDefinitionRequest) async throws -> LocationsOrLocationLinksResponse? { | ||
| throw ResponseError.requestNotImplemented(TypeDefinitionRequest.self) | ||
| } | ||
|
|
There was a problem hiding this comment.
Should we also forward the request to clangd in the ClangLanguageService? Not sure if clangd supports the request right now but if it does in the future, we’ll pick it up that way.
| case let request as RequestAndReply<TypeDefinitionRequest>: | ||
| await self.handleRequest(for: request, requestHandler: self.typeDefinition) |
There was a problem hiding this comment.
This list is ordered alphabetically? Could insert this at t?
|
Instead of adding a new requirement to |
- Add DefinitionLocations.swift to CMakeLists.txt - Add proper documentation comments to functions in DefinitionLocations.swift - Make indexToLSPLocation private since it's only used within the file - Revert unrelated comment changes in InlayHintResolve.swift - Use .only instead of .first in InlayHintResolve to avoid ambiguous types - Refactor TypeDefinition.swift to use cleaner control flow with guard/else - Add test for jumping to generated interface (String)
ahoppen
left a comment
There was a problem hiding this comment.
Sorry for the delayed review.
I left a few comments inline but there are also quite a few comments from my previous review outstanding. Please address those and then I can take another look at this.
e4bc7d7 to
5ee63b7
Compare
|
Regarding the isDynamic check - your comment said that "indexBasedDefinition mostly deals with logic to jump to definitions instead of declarations (only really applicable to the C family of languages)", so I left tout the isDynamic handling out of the shared definitionLocations function since: What i thought was to do is this |
|
Oh, sorry, you‘re right about |
|
okie got it |
ahoppen
left a comment
There was a problem hiding this comment.
Nice, I only have a few small things left, otherwise this looks good to me. Looking forward to using this request 😄
|
@swift-ci Please test |
|
@swift-ci please test windows |
|
@swift-ci please test |
|
@swift-ci please test windows |
|
@swift-ci Please test Windows |
|
yaay 🎊 |
follow up pr referenced from - comment
to be merged after #2436