@@ -1667,7 +1667,7 @@ extension SourceKitServer {
1667
1667
symbols: [ SymbolDetails ] ,
1668
1668
index: IndexStoreDB ? ,
1669
1669
useLocalFallback: Bool = false ,
1670
- extractOccurrences: ( String , IndexStoreDB ) -> [ SymbolOccurrence ]
1670
+ extractOccurrences: ( SymbolDetails , IndexStoreDB ) -> [ SymbolOccurrence ]
1671
1671
) -> [ ( occurrence: SymbolOccurrence ? , location: Location ) ] {
1672
1672
guard let symbol = symbols. first else {
1673
1673
return [ ]
@@ -1680,11 +1680,11 @@ extension SourceKitServer {
1680
1680
fallback = [ ]
1681
1681
}
1682
1682
1683
- guard let usr = symbol . usr , let index = index else {
1683
+ guard let index = index else {
1684
1684
return fallback
1685
1685
}
1686
1686
1687
- let occurs = extractOccurrences ( usr , index)
1687
+ let occurs = extractOccurrences ( symbol , index)
1688
1688
let resolved = occurs. compactMap { occur in
1689
1689
indexToLSPLocation ( occur. location) . map {
1690
1690
( occurrence: occur, location: $0)
@@ -1725,12 +1725,24 @@ extension SourceKitServer {
1725
1725
}
1726
1726
1727
1727
let resolved = self . extractIndexedOccurrences ( symbols: symbols, index: index, useLocalFallback: true ) {
1728
- ( usr, index) in
1728
+ ( symbolDetails, index) in
1729
+ guard symbolDetails. isDynamic ?? false else {
1730
+ // If the symbol isn't dynamic, we won't get more information from the index compared to what we already have
1731
+ // in the symbolDetails response. Return an empty array so that `extractIndexedOccurrences` falls back to the
1732
+ // location in the symbol details response.
1733
+ return [ ]
1734
+ }
1735
+ guard let usr = symbolDetails. usr else { return [ ] }
1729
1736
logger. info ( " performing indexed jump-to-def with usr \( usr) " )
1730
1737
var occurs = index. occurrences ( ofUSR: usr, roles: [ . definition] )
1731
1738
if occurs. isEmpty {
1732
1739
occurs = index. occurrences ( ofUSR: usr, roles: [ . declaration] )
1733
1740
}
1741
+ if symbolDetails. isDynamic ?? false {
1742
+ occurs += occurs. flatMap {
1743
+ index. occurrences ( relatedToUSR: $0. symbol. usr, roles: . overrideOf)
1744
+ }
1745
+ }
1734
1746
return occurs
1735
1747
}
1736
1748
@@ -1783,7 +1795,8 @@ extension SourceKitServer {
1783
1795
)
1784
1796
)
1785
1797
let index = await self . workspaceForDocument ( uri: req. textDocument. uri) ? . index
1786
- let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( usr, index) in
1798
+ let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( symbolDetails, index) in
1799
+ guard let usr = symbolDetails. usr else { return [ ] }
1787
1800
var occurs = index. occurrences ( ofUSR: usr, roles: . baseOf)
1788
1801
if occurs. isEmpty {
1789
1802
occurs = index. occurrences ( relatedToUSR: usr, roles: . overrideOf)
@@ -1806,7 +1819,8 @@ extension SourceKitServer {
1806
1819
)
1807
1820
)
1808
1821
let index = await self . workspaceForDocument ( uri: req. textDocument. uri) ? . index
1809
- let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( usr, index) in
1822
+ let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( symbolDetails, index) in
1823
+ guard let usr = symbolDetails. usr else { return [ ] }
1810
1824
logger. info ( " performing indexed jump-to-def with usr \( usr) " )
1811
1825
var roles : SymbolRole = [ . reference]
1812
1826
if req. context. includeDeclaration {
@@ -1852,8 +1866,9 @@ extension SourceKitServer {
1852
1866
)
1853
1867
let index = await self . workspaceForDocument ( uri: req. textDocument. uri) ? . index
1854
1868
// For call hierarchy preparation we only locate the definition
1855
- let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( usr, index) in
1856
- index. occurrences ( ofUSR: usr, roles: [ . definition, . declaration] )
1869
+ let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( symbolDetails, index) in
1870
+ guard let usr = symbolDetails. usr else { return [ ] }
1871
+ return index. occurrences ( ofUSR: usr, roles: [ . definition, . declaration] )
1857
1872
}
1858
1873
return extractedResult. compactMap { info -> CallHierarchyItem ? in
1859
1874
guard let occurrence = info. occurrence else {
@@ -2009,8 +2024,9 @@ extension SourceKitServer {
2009
2024
guard let index = await self . workspaceForDocument ( uri: req. textDocument. uri) ? . index else {
2010
2025
return [ ]
2011
2026
}
2012
- let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( usr, index) in
2013
- index. occurrences ( ofUSR: usr, roles: [ . definition, . declaration] )
2027
+ let extractedResult = self . extractIndexedOccurrences ( symbols: symbols, index: index) { ( symbolDetails, index) in
2028
+ guard let usr = symbolDetails. usr else { return [ ] }
2029
+ return index. occurrences ( ofUSR: usr, roles: [ . definition, . declaration] )
2014
2030
}
2015
2031
return extractedResult. compactMap { info -> TypeHierarchyItem ? in
2016
2032
guard let occurrence = info. occurrence else {
0 commit comments