in Sources/SourceKitLSP/SourceKitServer.swift [1048:1093]
func implementation(
_ req: Request<ImplementationRequest>,
workspace: Workspace,
languageService: ToolchainLanguageServer
) {
let symbolInfo = SymbolInfoRequest(textDocument: req.params.textDocument, position: req.params.position)
let index = self.workspace?.index
let callback = callbackOnQueue(self.queue) { (result: Result<SymbolInfoRequest.Response, ResponseError>) in
guard let symbols: [SymbolDetails] = result.success ?? nil, let symbol = symbols.first else {
if let error = result.failure {
req.reply(.failure(error))
} else {
req.reply(.locations([]))
}
return
}
guard let usr = symbol.usr, let index = index else {
return req.reply(.locations([]))
}
var occurs = index.occurrences(ofUSR: usr, roles: .baseOf)
if occurs.isEmpty {
occurs = index.occurrences(relatedToUSR: usr, roles: .overrideOf)
}
let locations = occurs.compactMap { occur -> Location? in
if occur.location.path.isEmpty {
return nil
}
return Location(
uri: DocumentURI(URL(fileURLWithPath: occur.location.path)),
range: Range(Position(
line: occur.location.line - 1, // 1-based -> 0-based
// FIXME: we need to convert the utf8/utf16 column, which may require reading the file!
utf16index: occur.location.utf8Column - 1
))
)
}
req.reply(.locations(locations))
}
let request = Request(symbolInfo, id: req.id, clientID: ObjectIdentifier(self),
cancellation: req.cancellationToken, reply: callback)
languageService.symbolInfo(request)
}