判斷變數是否是 struct 的方式
基本上離不開 USR
我們一樣還是透過 CursorInfo
查詢 a
的資訊
let a = 1
print(a)
這邊我們可以取得兩個我們想關注的屬性
▿ 0 : 2 elements
- key : "key.typeusr"
- value : "$sSiD"
▿ 5 : 2 elements
- key : "key.typename"
- value : "Int"
我們透過 demangle
將 usr
還原成 Int
A Unified Symbol Resolution (USR) is a string that identifies a particular
entity (function, class, variable, etc.) within a program. USRs can be
compared across translation units to determine, e.g., when references in
one translation refer to an entity defined in another translation unit.
透過解析 USR
來判斷是否是 struct
將 USR
當作搜尋條件查詢
public enum IndexSymbolKind: Hashable {
case unknown
case module
case namespace
case namespaceAlias
case macro
case `enum`
case `struct`
case `class`
case `protocol`
case `extension`
case union
case `typealias`
case function
case variable
case field
case enumConstant
case instanceMethod
case classMethod
case staticMethod
case instanceProperty
case classProperty
case staticProperty
case constructor
case destructor
case conversionFunction
case parameter
case using
case concept
case commentTag
}