1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public struct InlineValueContext: Codable, Hashable, Sendable {
/// The stack frame (as a DAP Id) where the execution has stopped.
public var frameId: Int
/// The document range where execution has stopped.
/// Typically the end position of the range denotes the line where the
/// inline values are shown.
@CustomCodable<PositionRange>
public var stoppedLocation: Range<Position>
public init(frameId: Int, stoppedLocation: Range<Position>) {
self.frameId = frameId
self.stoppedLocation = stoppedLocation
}
}
/// The inline value request is sent from the client to the server to compute inline values for a given text document that may be rendered in the editor at the end of lines.
public struct InlineValueRequest: TextDocumentRequest {
public static let method: String = "textDocument/inlineValue"
public typealias Response = [InlineValue]?
/// The text document.
public var textDocument: TextDocumentIdentifier
/// The document range for which inline values should be computed.
@CustomCodable<PositionRange>
public var range: Range<Position>
/// Additional information about the context in which inline values were
/// requested.
public var context: InlineValueContext
public init(textDocument: TextDocumentIdentifier, range: Range<Position>, context: InlineValueContext) {
self.textDocument = textDocument
self.range = range
self.context = context
}
}
/// Provide inline value as text.
public struct InlineValueText: Codable, Hashable, Sendable {
/// The document range for which the inline value applies.
@CustomCodable<PositionRange>
public var range: Range<Position>
/// The text of the inline value.
public var text: String
public init(range: Range<Position>, text: String) {
self.range = range
self.text = text
}
}
/// Provide inline value through a variable lookup.
///
/// If only a range is specified, the variable name will be extracted from
/// the underlying document.
///
/// An optional variable name can be used to override the extracted name.
public struct InlineValueVariableLookup: Codable, Hashable, Sendable {
/// The document range for which the inline value applies.
/// The range is used to extract the variable name from the underlying
/// document.
@CustomCodable<PositionRange>
public var range: Range<Position>
/// If specified the name of the variable to look up.
public var variableName: String?
/// How to perform the lookup.
public var caseSensitiveLookup: Bool
public init(range: Range<Position>, variableName: String? = nil, caseSensitiveLookup: Bool) {
self.range = range
self.variableName = variableName
self.caseSensitiveLookup = caseSensitiveLookup
}
}
/// Provide an inline value through an expression evaluation.
///
/// If only a range is specified, the expression will be extracted from the
/// underlying document.
///
/// An optional expression can be used to override the extracted expression.
public struct InlineValueEvaluatableExpression: Codable, Hashable, Sendable {
/// The document range for which the inline value applies.
/// The range is used to extract the evaluatable expression from the
/// underlying document.
@CustomCodable<PositionRange>
public var range: Range<Position>
/// If specified the expression overrides the extracted expression.
public var expression: String?
public init(range: Range<Position>, expression: String? = nil) {
self.range = range
self.expression = expression
}
}
/// Inline value information can be provided by different means:
/// - directly as a text value (class InlineValueText).
/// - as a name to use for a variable lookup (class InlineValueVariableLookup)
/// - as an evaluatable expression (class InlineValueEvaluatableExpression)
/// The InlineValue types combines all inline value types into one type.
public enum InlineValue: ResponseType, Hashable, Sendable {
case text(InlineValueText)
case variableLookup(InlineValueVariableLookup)
case evaluatableExpression(InlineValueEvaluatableExpression)
public init(from decoder: Decoder) throws {
if let text = try? InlineValueText(from: decoder) {
self = .text(text)
} else if let variableLookup = try? InlineValueVariableLookup(from: decoder) {
self = .variableLookup(variableLookup)
} else if let evaluatableExpression = try? InlineValueEvaluatableExpression(from: decoder) {
self = .evaluatableExpression(evaluatableExpression)
} else {
let context = DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription:
"Expected InlineValueText, InlineValueEvaluatableExpression or InlineValueEvaluatableExpression"
)
throw DecodingError.dataCorrupted(context)
}
}
public func encode(to encoder: Encoder) throws {
switch self {
case .text(let text):
try text.encode(to: encoder)
case .variableLookup(let variableLookup):
try variableLookup.encode(to: encoder)
case .evaluatableExpression(let evaluatableExpression):
try evaluatableExpression.encode(to: encoder)
}
}
}
|