Skip to content

Implement "textDocument/implementation" request #126

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
merged 4 commits into from
Aug 9, 2019

Conversation

Trzyipolkostkicukru
Copy link
Contributor

https://bugs.swift.org/browse/SR-10808

Won't build right now, because it relies on occurrences(relatedToUSR:roles:) that will be introduced in swiftlang/indexstore-db#32

There's a bug where if you satisfy a protocol requirement in the main body of a type, but conform to the protocol in an extension, indexstore-db will give you the location when looking for the protocol requirement implementation.

@benlangmuir
Copy link
Contributor

It looks like this needs an update now that workspace/symbols has landed.

I also recently added the missing test support code that will allow you to write tests for this, so let's do that. I'd love any feedback you have about using the new APIs. You can find an example test in testIndexSwiftModules, which includes a textDocument/definition request. I also wrote a bunch of information about the new infrastructure in #131 and swiftlang/indexstore-db#35.

# Conflicts:
#	Sources/LanguageServerProtocol/ServerCapabilities.swift
#	Sources/SourceKit/SourceKitServer.swift
#	Tests/LanguageServerProtocolJSONRPCTests/CodingTests.swift
Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

A few minor things, but overall looks great!

occurs = index.occurrences(relatedToUSR: usr, roles: .overrideOf)
}

// FIXME: overrided method logic
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this FIXME about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just got copy-pasted with the rest of definition(_:workspace:)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's relevant here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted

try ws.openDocument(ws.testLoc("b.swift").url, language: .swift)

func impls(at testLoc: TestLocation) throws -> [Location] {
let textDocument = TextDocumentIdentifier(testLoc.url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I added a shortcut testLoc.docIdentifier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

try XCTAssertEqual(impls(at: testLoc("ClassVariable")), [loc("SubclassVariable")])
try XCTAssertEqual(impls(at: testLoc("ClassFunction")), [loc("SubclassFunction")])

try XCTAssertEqual(impls(at: testLoc("Sepulcidae")), [loc("ParapamphiliinaeConformance"), loc("XyelulinaeConformance"), loc("TrematothoracinaeConformance")])
Copy link
Contributor

Choose a reason for hiding this comment

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

The order of these is not guaranteed in the index. Maybe we should change impls to return a Set for testing purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

try XCTAssertEqual(impls(at: testLoc("Trematothoracinae")), [])

try XCTAssertEqual(impls(at: testLoc("Prozaiczne")), [loc("MurkwiaConformance2"), loc("SepulkaConformance1")])
// FIXME: non-ascii characters break Tibs `TestLocation`s
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got confused by late night debugging. There is a tibs bug, but I accidentally dodged it here, because "ć" and "Ł" fit into a single utf-16 code unit, even though they aren't ascii. The bug that the test caught is real though and needs investigating.

About the tibs bug - if I put this in a test file

class 😃 {}/*a*/
class B {}/*b*/
class Ć {}/*c*/
class 👩‍👩‍👧‍👧 {}/*d*/

and then print(loc("a").range.lowerBound.utf16index), I get 15 for all of them, which suggests that tibs counts Characters instead of utf-16 code units. I think I should get 16, 15, 15, 25 for the column numbers

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks! I'll fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I think I fixed this in
swiftlang/indexstore-db#38
#136

Unfortunately, this will probably expose the latent problem that we are using a utf8 index from the SymbolOccurrence, so your comparisons may start failing. If that's the case, I suggest adding new initializers to Position(badUTF16: TestLocation) and similarly for Location that do the same incorrect behaviour as we do in the implementation. It also makes it easier to find the places that should change when we someday fix the underlying utf8 vs. utf16 issue from our index data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, assuming the tests pass we could just land your changes first, and I can fix up any discrepancies in my PR.

try XCTAssertEqual(impls(at: testLoc("Prozaiczne")), [loc("MurkwiaConformance2"), loc("SepulkaConformance1")])
// FIXME: non-ascii characters break Tibs `TestLocation`s
// try XCTAssertEqual(impls(at: testLoc("Sepulkowate")), [loc("MurkwiaConformance1"), loc("SepulkaConformance2"), loc("PćmaŁagodnaConformance"), loc("PćmaZwyczajnaConformance")])
// FIXME: sourcekit returns wrong locations for the function (subclasses that don't override it, and extensions that don't implement it)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you file a bug for this one? It seems worth understanding and fixing either in the index or in sourcekit-lsp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

@swift-ci please test

@benlangmuir
Copy link
Contributor

@swift-ci please test macOS

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.

2 participants