|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import Dispatch |
| 14 | +import LanguageServerProtocol |
| 15 | +import SourceKitD |
| 16 | + |
| 17 | +/// A typed variable as returned by sourcekitd's CollectVariableType. |
| 18 | +struct VariableTypeInfo { |
| 19 | + /// Range of the variable identifier in the source file. |
| 20 | + var range: Range<Position> |
| 21 | + /// The printed type of the variable. |
| 22 | + var printedType: String |
| 23 | + |
| 24 | + init?(_ dict: SKDResponseDictionary, in snapshot: DocumentSnapshot) { |
| 25 | + let keys = dict.sourcekitd.keys |
| 26 | + |
| 27 | + guard let offset: Int = dict[keys.variable_offset], |
| 28 | + let length: Int = dict[keys.variable_length], |
| 29 | + let startIndex = snapshot.positionOf(utf8Offset: offset), |
| 30 | + let endIndex = snapshot.positionOf(utf8Offset: offset + length), |
| 31 | + let printedType: String = dict[keys.variable_type] else { |
| 32 | + return nil |
| 33 | + } |
| 34 | + |
| 35 | + self.range = startIndex..<endIndex |
| 36 | + self.printedType = printedType |
| 37 | + } |
| 38 | +} |
0 commit comments