-
Notifications
You must be signed in to change notification settings - Fork 314
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
benlangmuir
merged 4 commits into
swiftlang:master
from
Trzyipolkostkicukru:implementation
Aug 9, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7667608
Implement "textDocument/implementation" request
Trzyipolkostkicukru 7b61973
Merge remote-tracking branch 'upstream/master' into implementation
Trzyipolkostkicukru ef7d8ab
Add tests
Trzyipolkostkicukru 719bed2
Response to code review
Trzyipolkostkicukru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Sources/LanguageServerProtocol/ImplementationRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// The go to implementation request is sent from the client to the server | ||
/// to resolve the implementation location of a symbol at a given | ||
/// text document position. | ||
/// | ||
/// Servers that provide Goto Implementation support should set | ||
/// the `implementationProvider` server capability. | ||
/// | ||
/// - Parameters: | ||
/// - textDocument: The document in which the given symbol is located. | ||
/// - position: The document location of a given symbol. | ||
/// | ||
/// - Returns: The location of the implementations of protocol requirements, | ||
/// protocol conforming types, subclasses, or overrides. | ||
public struct ImplementationRequest: TextDocumentRequest, Hashable { | ||
public static let method: String = "textDocument/implementation" | ||
public typealias Response = [Location] | ||
|
||
/// The document in which the given symbol is located. | ||
public var textDocument: TextDocumentIdentifier | ||
|
||
/// The document location of a given symbol. | ||
public var position: Position | ||
|
||
public init(textDocument: TextDocumentIdentifier, position: Position) { | ||
self.textDocument = textDocument | ||
self.position = position | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*a.swift*/ | ||
protocol /*Protocol*/Protocol { | ||
static var /*ProtocolStaticVar*/staticVar: Int { get } | ||
static func /*ProtocolStaticFunction*/staticFunction() | ||
var /*ProtocolVariable*/variable: Int { get } | ||
func /*ProtocolFunction*/function() | ||
} | ||
class /*Class*/Class { | ||
class var /*ClassClassVar*/classVar: Int { 123 } | ||
class func /*ClassClassFunction*/classFunction() {} | ||
var /*ClassVariable*/variable: Int { 123 } | ||
func /*ClassFunction*/function() {} | ||
} | ||
|
||
|
||
class /*Sepulcidae*/Sepulcidae {} | ||
class /*Parapamphiliinae*/Parapamphiliinae: /*ParapamphiliinaeConformance*/Sepulcidae {} | ||
class Micramphilius: /*MicramphiliusConformance*/Parapamphiliinae {} | ||
class Pamparaphilius: /*PamparaphiliusConformance*/Parapamphiliinae {} | ||
class /*Xyelulinae*/Xyelulinae: /*XyelulinaeConformance*/Sepulcidae {} | ||
class Xyelula: /*XyelulaConformance*/Xyelulinae {} | ||
class /*Trematothoracinae*/Trematothoracinae: /*TrematothoracinaeConformance*/Sepulcidae {} | ||
|
||
|
||
protocol /*Prozaiczne*/Prozaiczne {} | ||
protocol /*Sepulkowate*/Sepulkowate { | ||
func /*rozpocznijSepulenie*/rozpocznijSepulenie() | ||
} | ||
|
||
class Pćma {} | ||
class /*Murkwia*/Murkwia: /*MurkwiaConformance1*/Sepulkowate, /*MurkwiaConformance2*/Prozaiczne { | ||
func /*MurkwiaFunc*/rozpocznijSepulenie() {} | ||
} | ||
class /*Sepulka*/Sepulka: /*SepulkaConformance1*/Prozaiczne, /*SepulkaConformance2*/Sepulkowate { | ||
var size: Double { 10 } | ||
var /*SepulkaVar*/patroka: String { "puszysta" } | ||
func /*SepulkaFunc*/rozpocznijSepulenie() {} | ||
} | ||
class SepulkaDwuuszna: /*SepulkaDwuusznaConformance*/Sepulka { | ||
override var /*SepulkaDwuusznaVar*/patroka: String { "glazurowana" } | ||
} | ||
class SepulkaPrzechylna: /*SepulkaPrzechylnaConformance*/Sepulka { | ||
override var /*SepulkaPrzechylnaVar*/patroka: String { "piaskowana" } | ||
} | ||
class PćmaŁagodna: Pćma { | ||
func /*PćmaŁagodnaFunc*/rozpocznijSepulenie() { } | ||
} | ||
extension PćmaŁagodna: /*PćmaŁagodnaConformance*/Sepulkowate {} | ||
|
||
class PćmaZwyczajna: Pćma {} | ||
extension PćmaZwyczajna: /*PćmaZwyczajnaConformance*/Sepulkowate { | ||
func /*PćmaZwyczajnaFunc*/rozpocznijSepulenie() { } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*b.swift*/ | ||
struct Struct: /*StructConformance*/Protocol { | ||
static var /*StructStaticVar*/staticVar: Int { 123 } | ||
static func /*StructStaticFunction*/staticFunction() {} | ||
var /*StructVariable*/variable: Int { 123 } | ||
func /*StructFunction*/function() {} | ||
} | ||
class Subclass: /*SubclassConformance*/Class { | ||
override class var /*SubclassClassVar*/classVar: Int { 123 } | ||
override class func /*SubclassClassFunction*/classFunction() {} | ||
override var /*SubclassVariable*/variable: Int { 123 } | ||
override func /*SubclassFunction*/function() {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"sources": ["a.swift", "b.swift"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
@testable import SourceKit | ||
import LanguageServerProtocol | ||
import XCTest | ||
import SKTestSupport | ||
import ISDBTestSupport | ||
|
||
final class ImplementationTests: XCTestCase { | ||
func testImplementation() throws { | ||
let ws = try staticSourceKitTibsWorkspace(name: "Implementation")! | ||
try ws.buildAndIndex() | ||
|
||
try ws.openDocument(ws.testLoc("a.swift").url, language: .swift) | ||
try ws.openDocument(ws.testLoc("b.swift").url, language: .swift) | ||
|
||
func impls(at testLoc: TestLocation) throws -> Set<Location> { | ||
let textDocument = testLoc.docIdentifier | ||
let request = ImplementationRequest(textDocument: textDocument, position: Position(testLoc)) | ||
let implementations = try ws.sk.sendSync(request) | ||
return Set(implementations) | ||
} | ||
func testLoc(_ name: String) -> TestLocation { | ||
ws.testLoc(name) | ||
} | ||
func loc(_ name: String) -> Location { | ||
Location(ws.testLoc(name)) | ||
} | ||
|
||
try XCTAssertEqual(impls(at: testLoc("Protocol")), [loc("StructConformance")]) | ||
try XCTAssertEqual(impls(at: testLoc("ProtocolStaticVar")), [loc("StructStaticVar")]) | ||
try XCTAssertEqual(impls(at: testLoc("ProtocolStaticFunction")), [loc("StructStaticFunction")]) | ||
try XCTAssertEqual(impls(at: testLoc("ProtocolVariable")), [loc("StructVariable")]) | ||
try XCTAssertEqual(impls(at: testLoc("ProtocolFunction")), [loc("StructFunction")]) | ||
try XCTAssertEqual(impls(at: testLoc("Class")), [loc("SubclassConformance")]) | ||
try XCTAssertEqual(impls(at: testLoc("ClassClassVar")), [loc("SubclassClassVar")]) | ||
try XCTAssertEqual(impls(at: testLoc("ClassClassFunction")), [loc("SubclassClassFunction")]) | ||
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")]) | ||
try XCTAssertEqual(impls(at: testLoc("Parapamphiliinae")), [loc("MicramphiliusConformance"), loc("PamparaphiliusConformance")]) | ||
try XCTAssertEqual(impls(at: testLoc("Xyelulinae")), [loc("XyelulaConformance")]) | ||
try XCTAssertEqual(impls(at: testLoc("Trematothoracinae")), []) | ||
|
||
try XCTAssertEqual(impls(at: testLoc("Prozaiczne")), [loc("MurkwiaConformance2"), loc("SepulkaConformance1")]) | ||
// FIXME: For some reason we get a location in the middle of a symbol for PćmaŁagodnaConformance | ||
// 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// try XCTAssertEqual(impls(at: testLoc("rozpocznijSepulenie")), [loc("MurkwiaFunc"), loc("SepulkaFunc"), loc("PćmaŁagodnaFunc"), loc("PćmaZwyczajnaFunc")]) | ||
try XCTAssertEqual(impls(at: testLoc("Murkwia")), []) | ||
try XCTAssertEqual(impls(at: testLoc("MurkwiaFunc")), []) | ||
try XCTAssertEqual(impls(at: testLoc("Sepulka")), [loc("SepulkaDwuusznaConformance"), loc("SepulkaPrzechylnaConformance")]) | ||
try XCTAssertEqual(impls(at: testLoc("SepulkaVar")), [loc("SepulkaDwuusznaVar"), loc("SepulkaPrzechylnaVar")]) | ||
try XCTAssertEqual(impls(at: testLoc("SepulkaFunc")), []) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The order of these is not guaranteed in the index. Maybe we should change
impls
to return aSet
for testing purposes?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.
changed