mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
A declaration request is similar to a definition request, except that it is expected to return (potentially) many results across the workspace for a given reference. For example, an inline function or macro may have many declarations in the workspace, but only one "good" or canonical definition. For now, this is only implemented by forwarding the request on to clangd since I'm unfamiliar with a SourceKit query for this. For languages like Swift that lack such a sharp declaration/definition split, we could potentially use this request to provide navigable metadata on linked definitions. For example, the declaration for a type reference would include all extensions of that type in the workspace.
42 lines
1.7 KiB
Swift
42 lines
1.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2022 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Request to find the declarations(s) of the symbol at the given location.
|
|
///
|
|
/// Looks up the symbol at the given position and returns a list of all
|
|
/// declarations involving that symbol in the workspace.
|
|
///
|
|
/// This request differs from `DefinitionRequest` because a symbol usually has
|
|
/// only one definition but potentially has many declarations involving that
|
|
/// symbol. E.g. the definition of a type versus the forward declarations of that type.
|
|
///
|
|
/// - Parameters:
|
|
/// - textDocument: The document in which to lookup the symbol location.
|
|
/// - position: The document location at which to lookup symbol information.
|
|
///
|
|
/// - Returns: The location of the declaration(s).
|
|
public struct DeclarationRequest: TextDocumentRequest, Hashable {
|
|
public static let method: String = "textDocument/declaration"
|
|
public typealias Response = LocationsOrLocationLinksResponse?
|
|
|
|
/// The document in which to lookup the symbol location.
|
|
public var textDocument: TextDocumentIdentifier
|
|
|
|
/// The document location at which to lookup symbol information.
|
|
public var position: Position
|
|
|
|
public init(textDocument: TextDocumentIdentifier, position: Position) {
|
|
self.textDocument = textDocument
|
|
self.position = position
|
|
}
|
|
}
|