Skip to content

Commit aa7be46

Browse files
Fix the scope building for type declarations
1 parent d3ad334 commit aa7be46

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/TypeDeclResolver.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import SwiftSyntax
1515
/// Resolves type declarations from Swift syntax nodes
1616
class TypeDeclResolver {
1717
typealias TypeDecl = NamedDeclSyntax & DeclGroupSyntax & DeclSyntaxProtocol
18+
/// A representation of a qualified name of a type declaration
19+
///
20+
/// `Outer.Inner` type declaration is represented as ["Outer", "Inner"]
1821
typealias QualifiedName = [String]
1922
private var typeDeclByQualifiedName: [QualifiedName: TypeDecl] = [:]
2023

@@ -69,15 +72,15 @@ class TypeDeclResolver {
6972

7073
/// Builds the type name scope for a given type usage
7174
private func buildScope(type: IdentifierTypeSyntax) -> QualifiedName {
72-
var contextScope: [String] = []
75+
var innerToOuter: [String] = []
7376
var context: SyntaxProtocol = type
7477
while let parent = context.parent {
7578
if let parent = parent.asProtocol(NamedDeclSyntax.self), parent.isProtocol(DeclGroupSyntax.self) {
76-
contextScope.append(parent.name.text)
79+
innerToOuter.append(parent.name.text)
7780
}
7881
context = parent
7982
}
80-
return contextScope
83+
return innerToOuter.reversed()
8184
}
8285

8386
/// Looks up a qualified name of a type declaration by its unqualified type usage

0 commit comments

Comments
 (0)