diff --git a/CHANGELOG.md b/CHANGELOG.md index 813aca015354d..25a29b7ed561d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ ## Swift (next) +* Syntactic SourceKit queries no longer attempt to provide information + within the inactive `#if` regions. For example, given: + + ```swift + #if DEBUG + extension MyType: CustomDebugStringConvertible { + var debugDescription: String { ... } + } + #endif + ``` + + If `DEBUG` is not set, SourceKit results will not involve the + inactive code. Clients should use either SourceKit-LSP or + swift-syntax for syntactic queries that are independent of the + specific build configuration. + * [SE-0442][]: TaskGroups can now be created without explicitly specifying their child task's result types: diff --git a/lib/IDE/Formatting.cpp b/lib/IDE/Formatting.cpp index 482719401fd8b..5489904984e89 100644 --- a/lib/IDE/Formatting.cpp +++ b/lib/IDE/Formatting.cpp @@ -487,15 +487,6 @@ class RangeWalker: protected ASTWalker { if (D->isImplicit()) return Action::Continue(); - // Walk into inactive config regions. - if (auto *ICD = dyn_cast(D)) { - for (auto Clause : ICD->getClauses()) { - for (auto Member : Clause.Elements) - Member.walk(*this); - } - return Action::SkipNode(); - } - SourceLoc ContextLoc = D->getStartLoc(); if (auto *GC = D->getAsGenericContext()) { @@ -1396,17 +1387,6 @@ class FormatWalker : public ASTWalker { } } - // Walk into inactive config regions. - if (auto *ICD = dyn_cast(D)) { - if (Action.shouldVisitChildren()) { - for (auto Clause : ICD->getClauses()) { - for (auto Member : Clause.Elements) - Member.walk(*this); - } - } - return Action::SkipNode(); - } - // FIXME: We ought to be able to use Action::VisitChildrenIf here, but we'd // need to ensure the AST is walked in source order (currently not the case // for things like postfix operators). @@ -1933,19 +1913,6 @@ class FormatWalker : public ASTWalker { return IndentContext {ContextLoc, !OutdentChecker::hasOutdent(SM, D)}; } - if (auto *ICD = dyn_cast(D)) { - for (auto &Clause: ICD->getClauses()) { - if (Clause.Loc == TargetLocation) - break; - if (auto *Cond = Clause.Cond) { - SourceRange CondRange = Cond->getSourceRange(); - if (CondRange.isValid() && overlapsTarget(CondRange)) - return IndentContext {Clause.Loc, true}; - } - } - return IndentContext { ICD->getStartLoc(), false }; - } - switch (D->getKind()) { case DeclKind::InfixOperator: case DeclKind::PostfixOperator: diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp index 12e2c9d4c8ff9..64e67a6e322ce 100644 --- a/lib/IDE/SyntaxModel.cpp +++ b/lib/IDE/SyntaxModel.cpp @@ -416,7 +416,6 @@ class ModelASTWalker : public ASTWalker { private: static bool findUrlStartingLoc(StringRef Text, unsigned &Start, std::regex& Regex); - bool annotateIfConfigConditionIdentifiers(Expr *Cond); bool handleAttrs(const ParsedDeclAttributes &Attrs); bool handleAttrs(ArrayRef Attrs); @@ -1003,24 +1002,8 @@ ASTWalker::PreWalkAction ModelASTWalker::walkToDeclPre(Decl *D) { } pushStructureNode(SN, VD); - } else if (auto *ConfigD = dyn_cast(D)) { - for (auto &Clause : ConfigD->getClauses()) { - if (Clause.Cond && !annotateIfConfigConditionIdentifiers(Clause.Cond)) - return Action::SkipNode(); - - InactiveClauseRAII inactiveClauseRAII(inInactiveClause, !Clause.isActive); - for (auto &Element : Clause.Elements) { - if (auto *E = Element.dyn_cast()) { - E->walk(*this); - } else if (auto *S = Element.dyn_cast()) { - S->walk(*this); - } else { - Element.get()->walk(*this); - } - NodesVisitedBefore.insert(Element); - } - } - + } else if (isa(D)) { + // Note: nothing to do. } else if (auto *EnumCaseD = dyn_cast(D)) { SyntaxStructureNode SN; setDecl(SN, D); @@ -1172,17 +1155,6 @@ class IdRefWalker : public ASTWalker { }; } // end anonymous namespace -bool ModelASTWalker::annotateIfConfigConditionIdentifiers(Expr *Cond) { - if (!Cond) - return true; - auto passNode = [&](CharSourceRange R) { - return passNonTokenNode({ SyntaxNodeKind::BuildConfigId, R }); - }; - - IdRefWalker Walker(passNode); - return Cond->walk(Walker); -} - bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D, ArrayRef Toks) { if (!D) diff --git a/test/IDE/coloring_configs.swift b/test/IDE/coloring_configs.swift index 9273f8d6e2e04..58977387bcb89 100644 --- a/test/IDE/coloring_configs.swift +++ b/test/IDE/coloring_configs.swift @@ -1,326 +1,5 @@ // RUN: %target-swift-ide-test -syntax-coloring -source-filename %s -D CONF | %FileCheck %s -// CHECK: var f : Int -var f : Int - -// CHECK: <#kw>#if <#id>os(<#id>macOS) -#if os(macOS) -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x : Int - var x : Int -// CHECK: <#kw>#else -#else - // CHECK: var x : Float - var x : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x2 : Int - var x2 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x3 : Int - var x3 : Int -// CHECK: <#kw>#else -#else - // CHECK: var x3 : Float - var x3 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x4 : Int - var x4 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var y1 : Int - var y1 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y1 : String - var y1 : String -// CHECK: <#kw>#else -#else - // CHECK: var y1 : Float - var y1 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y2 : Int - var y2 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y2 : String - var y2 : String -// CHECK: <#kw>#else -#else - // CHECK: var y2 : Float - var y2 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y3 : Int - var y3 : Int -// CHECK: <#kw>#elseif <#id>CONF -#elseif CONF - // CHECK: var y3 : String - var y3 : String -// CHECK: <#kw>#else -#else - // CHECK: var y3 : Float - var y3 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: var l : Int -var l : Int - -// CHECK: class C1 { -class C1 { - // CHECK: var f : Int - var f : Int - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x : Int - var x : Int -// CHECK: <#kw>#else -#else - // CHECK: var x : Float - var x : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x2 : Int - var x2 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x3 : Int - var x3 : Int -// CHECK: <#kw>#else -#else - // CHECK: var x3 : Float - var x3 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x4 : Int - var x4 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var y1 : Int - var y1 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y1 : String - var y1 : String -// CHECK: <#kw>#else -#else - // CHECK: var y1 : Float - var y1 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y2 : Int - var y2 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y2 : String - var y2 : String -// CHECK: <#kw>#else -#else - // CHECK: var y2 : Float - var y2 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y3 : Int - var y3 : Int -// CHECK: <#kw>#elseif <#id>CONF -#elseif CONF - // CHECK: var y3 : String - var y3 : String -// CHECK: <#kw>#else -#else - // CHECK: var y3 : Float - var y3 : Float -// CHECK: <#kw>#endif -#endif - - // CHECK: var l : Int - var l : Int -} - -// CHECK: func test1() { -func test1() { - // CHECK: var f : Int - var f : Int - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x : Int - var x : Int -// CHECK: <#kw>#else -#else - // CHECK: var x : Float - var x : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var x2 : Int - var x2 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x3 : Int - var x3 : Int -// CHECK: <#kw>#else -#else - // CHECK: var x3 : Float - var x3 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var x4 : Int - var x4 : Int -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if <#id>CONF -#if CONF - // CHECK: var y1 : Int - var y1 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y1 : String - var y1 : String -// CHECK: <#kw>#else -#else - // CHECK: var y1 : Float - var y1 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y2 : Int - var y2 : Int -// CHECK: <#kw>#elseif <#id>BAZ -#elseif BAZ - // CHECK: var y2 : String - var y2 : String -// CHECK: <#kw>#else -#else - // CHECK: var y2 : Float - var y2 : Float -// CHECK: <#kw>#endif -#endif - -// CHECK: <#kw>#if !<#id>CONF -#if !CONF - // CHECK: var y3 : Int - var y3 : Int -// CHECK: <#kw>#elseif <#id>CONF -#elseif CONF - // CHECK: var y3 : String - var y3 : String -// CHECK: <#kw>#else -#else - // CHECK: var y3 : Float - var y3 : Float -// CHECK: <#kw>#endif -#endif - - // CHECK: var l : Int - var l : Int -} - -// CHECK: class C2 { -class C2 { - // CHECK: <#kw>#if <#id>os(<#id>iOS) - #if os(iOS) - // CHECK: func foo() {} - func foo() {} - #endif -} - -class NestedPoundIf { -// CHECK: class NestedPoundIf { - func foo1() { -// CHECK: func foo1() { - #if os(macOS) -// CHECK: <#kw>#if <#id>os(<#id>macOS) - var a = 1 -// CHECK: var a = 1 - #if USE_METAL -// CHECK: <#kw>#if <#id>USE_METAL - var b = 2 -// CHECK: var b = 2 - #if os(iOS) -// CHECK: <#kw>#if <#id>os(<#id>iOS) - var c = 3 -// CHECK: var c = 3 - #else -// CHECK: <#kw>#else - var c = 3 -// CHECK: var c = 3 - #endif -// CHECK: <#kw>#endif - #else -// CHECK: <#kw>#else - var b = 2 -// CHECK: var b = 2 - #endif -// CHECK: <#kw>#endif - #else -// CHECK: <#kw>#else - var a = 1 -// CHECK: var a = 1 - #endif -// CHECK: <#kw>#endif - } - func foo2() {} -// CHECK: func foo2() {} - func foo3() {} -// CHECK: func foo3() {} -} - // CHECK: <#kw>#error("Error") #error("Error") // CHECK: <#kw>#warning("Warning") diff --git a/test/IDE/coloring_unclosed_hash_if.swift b/test/IDE/coloring_unclosed_hash_if.swift deleted file mode 100644 index a680085fb6949..0000000000000 --- a/test/IDE/coloring_unclosed_hash_if.swift +++ /dev/null @@ -1,14 +0,0 @@ -// RUN: %target-swift-ide-test -syntax-coloring -source-filename %s | %FileCheck %s -// RUN: %target-swift-ide-test -syntax-coloring -typecheck -source-filename %s | %FileCheck %s - -// CHECK: <#kw>#if <#id>d -// CHECK-NEXT: func bar() { -// CHECK-NEXT: <#kw>#if <#id>d -// CHECK-NEXT: } -// CHECK-NEXT: func foo() {} - -#if d -func bar() { - #if d -} -func foo() {} diff --git a/test/SourceKit/CodeExpand/code-expand.swift b/test/SourceKit/CodeExpand/code-expand.swift index 3936ac140c044..8144e40fbe902 100644 --- a/test/SourceKit/CodeExpand/code-expand.swift +++ b/test/SourceKit/CodeExpand/code-expand.swift @@ -147,17 +147,11 @@ braced2(x: {<#T##() -> Void#>}, y: Int) // CHECK-NEXT: }, y: Int) braced3({ - #if true <#T##() -> Int#> - #endif }) -// CHECK: braced3({ -// CHECK-NEXT: #if true -// CHECK-NEXT: { +// CHECK: braced3 { // CHECK-NEXT: <#code#> -// CHECK-NEXT: } -// CHECK-NEXT: #endif -// CHECK-NEXT: }) +// CHECK-NEXT: } func returnTrailing() -> Int { return withtrail(<#T##() -> ()#>) @@ -260,17 +254,6 @@ func activeWithTrailing() { // CHECK: forEach { // CHECK-NEXT: <#code#> } -#if false -func inactive() { - foo(<#T##value: Foo##Foo#>) - // CHECK: foo(Foo) -} -func inactiveWithTrailing() { - forEach(<#T##() -> ()#>) - // CHECK: forEach { - // CHECK-NEXT: <#code#> -} -#endif expandClosureWithInternalParameterNames { withtrail(<#T##callback: (Int, Int) -> Bool##(_ a: Int, _ b: Int) -> Bool#>) diff --git a/test/SourceKit/CodeFormat/indent-pound-if.swift b/test/SourceKit/CodeFormat/indent-pound-if.swift index 8416f7b7a8507..50024b11dbc5a 100644 --- a/test/SourceKit/CodeFormat/indent-pound-if.swift +++ b/test/SourceKit/CodeFormat/indent-pound-if.swift @@ -35,7 +35,7 @@ print(false) // RUN: %FileCheck --strict-whitespace %s <%t.response // CHECK: key.sourcetext: "#else" -// CHECK: key.sourcetext: " let i = 3" -// CHECK: key.sourcetext: " func b () {" +// CHECK: key.sourcetext: "let i = 3" +// CHECK: key.sourcetext: "func b () {" // CHECK: key.sourcetext: "#elseif os(OSX)" -// CHECK: key.sourcetext: " func b () {" +// CHECK: key.sourcetext: "func b () {" diff --git a/test/SourceKit/DocumentStructure/structure.swift.empty.response b/test/SourceKit/DocumentStructure/structure.swift.empty.response index aa146ae8ce7df..f3df09e5a056f 100644 --- a/test/SourceKit/DocumentStructure/structure.swift.empty.response +++ b/test/SourceKit/DocumentStructure/structure.swift.empty.response @@ -1428,106 +1428,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Result", - key.offset: 2496, - key.length: 36, - key.nameoffset: 2506, - key.namelength: 6, - key.bodyoffset: 2514, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "foo()", - key.offset: 2517, - key.length: 13, - key.nameoffset: 2522, - key.namelength: 5, - key.bodyoffset: 2529, - key.bodylength: 0 - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Outer", - key.offset: 2534, - key.length: 53, - key.nameoffset: 2544, - key.namelength: 5, - key.bodyoffset: 2551, - key.bodylength: 35, - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.name: "Inner", - key.offset: 2554, - key.length: 31, - key.nameoffset: 2560, - key.namelength: 5, - key.bodyoffset: 2567, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "deinit", - key.offset: 2572, - key.length: 9, - key.nameoffset: 2572, - key.namelength: 6, - key.bodyoffset: 2580, - key.bodylength: 0 - } - ] - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Outer2", - key.offset: 2596, - key.length: 55, - key.nameoffset: 2606, - key.namelength: 6, - key.bodyoffset: 2614, - key.bodylength: 36, - key.attributes: [ - { - key.offset: 2589, - key.length: 6, - key.attribute: source.decl.attribute.public - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Inner2", - key.offset: 2617, - key.length: 32, - key.nameoffset: 2623, - key.namelength: 6, - key.bodyoffset: 2631, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "deinit", - key.offset: 2636, - key.length: 9, - key.nameoffset: 2636, - key.namelength: 6, - key.bodyoffset: 2644, - key.bodylength: 0 - } - ] - } - ] - }, { key.kind: source.lang.swift.decl.protocol, key.accessibility: source.lang.swift.accessibility.internal, @@ -1578,50 +1478,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.protocol, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "MyProtocol", - key.offset: 2780, - key.length: 71, - key.nameoffset: 2789, - key.namelength: 10, - key.bodyoffset: 2819, - key.bodylength: 31, - key.inheritedtypes: [ - { - key.name: "NSObjectProtocol" - } - ], - key.attributes: [ - { - key.offset: 2774, - key.length: 5, - key.attribute: source.decl.attribute.objc - } - ], - key.elements: [ - { - key.kind: source.lang.swift.structure.elem.typeref, - key.offset: 2801, - key.length: 16 - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "thing", - key.offset: 2824, - key.length: 25, - key.typename: "NSObject", - key.nameoffset: 2828, - key.namelength: 5, - key.bodyoffset: 2845, - key.bodylength: 3 - } - ] - }, { key.kind: source.lang.swift.decl.class, key.accessibility: source.lang.swift.accessibility.internal, @@ -1631,44 +1487,7 @@ key.nameoffset: 2866, key.namelength: 1, key.bodyoffset: 2869, - key.bodylength: 59, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "foo(a:)", - key.offset: 2899, - key.length: 19, - key.selector_name: "fooWithA:", - key.nameoffset: 2904, - key.namelength: 11, - key.bodyoffset: 2917, - key.bodylength: 0, - key.attributes: [ - { - key.offset: 2893, - key.length: 5, - key.attribute: source.decl.attribute.objc.name - }, - { - key.offset: 2883, - key.length: 9, - key.attribute: source.decl.attribute.ibaction - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.parameter, - key.name: "a", - key.offset: 2908, - key.length: 6, - key.typename: "Int", - key.nameoffset: 2908, - key.namelength: 1 - } - ] - } - ] + key.bodylength: 59 } ], key.diagnostics: [ diff --git a/test/SourceKit/DocumentStructure/structure.swift.foobar.response b/test/SourceKit/DocumentStructure/structure.swift.foobar.response index a49feac856040..9c3daaa5bf0ab 100644 --- a/test/SourceKit/DocumentStructure/structure.swift.foobar.response +++ b/test/SourceKit/DocumentStructure/structure.swift.foobar.response @@ -1428,106 +1428,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Result", - key.offset: 2496, - key.length: 36, - key.nameoffset: 2506, - key.namelength: 6, - key.bodyoffset: 2514, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "foo()", - key.offset: 2517, - key.length: 13, - key.nameoffset: 2522, - key.namelength: 5, - key.bodyoffset: 2529, - key.bodylength: 0 - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Outer", - key.offset: 2534, - key.length: 53, - key.nameoffset: 2544, - key.namelength: 5, - key.bodyoffset: 2551, - key.bodylength: 35, - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.name: "Inner", - key.offset: 2554, - key.length: 31, - key.nameoffset: 2560, - key.namelength: 5, - key.bodyoffset: 2567, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "deinit", - key.offset: 2572, - key.length: 9, - key.nameoffset: 2572, - key.namelength: 6, - key.bodyoffset: 2580, - key.bodylength: 0 - } - ] - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Outer2", - key.offset: 2596, - key.length: 55, - key.nameoffset: 2606, - key.namelength: 6, - key.bodyoffset: 2614, - key.bodylength: 36, - key.attributes: [ - { - key.offset: 2589, - key.length: 6, - key.attribute: source.decl.attribute.public - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Inner2", - key.offset: 2617, - key.length: 32, - key.nameoffset: 2623, - key.namelength: 6, - key.bodyoffset: 2631, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "deinit", - key.offset: 2636, - key.length: 9, - key.nameoffset: 2636, - key.namelength: 6, - key.bodyoffset: 2644, - key.bodylength: 0 - } - ] - } - ] - }, { key.kind: source.lang.swift.decl.protocol, key.accessibility: source.lang.swift.accessibility.internal, @@ -1578,50 +1478,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.protocol, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "MyProtocol", - key.offset: 2780, - key.length: 71, - key.nameoffset: 2789, - key.namelength: 10, - key.bodyoffset: 2819, - key.bodylength: 31, - key.inheritedtypes: [ - { - key.name: "NSObjectProtocol" - } - ], - key.attributes: [ - { - key.offset: 2774, - key.length: 5, - key.attribute: source.decl.attribute.objc - } - ], - key.elements: [ - { - key.kind: source.lang.swift.structure.elem.typeref, - key.offset: 2801, - key.length: 16 - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "thing", - key.offset: 2824, - key.length: 25, - key.typename: "NSObject", - key.nameoffset: 2828, - key.namelength: 5, - key.bodyoffset: 2845, - key.bodylength: 3 - } - ] - }, { key.kind: source.lang.swift.decl.class, key.accessibility: source.lang.swift.accessibility.internal, @@ -1631,44 +1487,7 @@ key.nameoffset: 2866, key.namelength: 1, key.bodyoffset: 2869, - key.bodylength: 59, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "foo(a:)", - key.offset: 2899, - key.length: 19, - key.selector_name: "fooWithA:", - key.nameoffset: 2904, - key.namelength: 11, - key.bodyoffset: 2917, - key.bodylength: 0, - key.attributes: [ - { - key.offset: 2893, - key.length: 5, - key.attribute: source.decl.attribute.objc.name - }, - { - key.offset: 2883, - key.length: 9, - key.attribute: source.decl.attribute.ibaction - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.parameter, - key.name: "a", - key.offset: 2908, - key.length: 6, - key.typename: "Int", - key.nameoffset: 2908, - key.namelength: 1 - } - ] - } - ] + key.bodylength: 59 } ], key.diagnostics: [ diff --git a/test/SourceKit/DocumentStructure/structure.swift.response b/test/SourceKit/DocumentStructure/structure.swift.response index 28ec4000fa6cb..8f7b82ff0b1c9 100644 --- a/test/SourceKit/DocumentStructure/structure.swift.response +++ b/test/SourceKit/DocumentStructure/structure.swift.response @@ -1428,106 +1428,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Result", - key.offset: 2496, - key.length: 36, - key.nameoffset: 2506, - key.namelength: 6, - key.bodyoffset: 2514, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "foo()", - key.offset: 2517, - key.length: 13, - key.nameoffset: 2522, - key.namelength: 5, - key.bodyoffset: 2529, - key.bodylength: 0 - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.name: "Outer", - key.offset: 2534, - key.length: 53, - key.nameoffset: 2544, - key.namelength: 5, - key.bodyoffset: 2551, - key.bodylength: 35, - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.name: "Inner", - key.offset: 2554, - key.length: 31, - key.nameoffset: 2560, - key.namelength: 5, - key.bodyoffset: 2567, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.name: "deinit", - key.offset: 2572, - key.length: 9, - key.nameoffset: 2572, - key.namelength: 6, - key.bodyoffset: 2580, - key.bodylength: 0 - } - ] - } - ] - }, - { - key.kind: source.lang.swift.decl.extension, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Outer2", - key.offset: 2596, - key.length: 55, - key.nameoffset: 2606, - key.namelength: 6, - key.bodyoffset: 2614, - key.bodylength: 36, - key.attributes: [ - { - key.offset: 2589, - key.length: 6, - key.attribute: source.decl.attribute.public - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.class, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "Inner2", - key.offset: 2617, - key.length: 32, - key.nameoffset: 2623, - key.namelength: 6, - key.bodyoffset: 2631, - key.bodylength: 17, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.public, - key.name: "deinit", - key.offset: 2636, - key.length: 9, - key.nameoffset: 2636, - key.namelength: 6, - key.bodyoffset: 2644, - key.bodylength: 0 - } - ] - } - ] - }, { key.kind: source.lang.swift.decl.protocol, key.accessibility: source.lang.swift.accessibility.internal, @@ -1578,50 +1478,6 @@ } ] }, - { - key.kind: source.lang.swift.decl.protocol, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "MyProtocol", - key.offset: 2780, - key.length: 71, - key.nameoffset: 2789, - key.namelength: 10, - key.bodyoffset: 2819, - key.bodylength: 31, - key.inheritedtypes: [ - { - key.name: "NSObjectProtocol" - } - ], - key.attributes: [ - { - key.offset: 2774, - key.length: 5, - key.attribute: source.decl.attribute.objc - } - ], - key.elements: [ - { - key.kind: source.lang.swift.structure.elem.typeref, - key.offset: 2801, - key.length: 16 - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "thing", - key.offset: 2824, - key.length: 25, - key.typename: "NSObject", - key.nameoffset: 2828, - key.namelength: 5, - key.bodyoffset: 2845, - key.bodylength: 3 - } - ] - }, { key.kind: source.lang.swift.decl.class, key.accessibility: source.lang.swift.accessibility.internal, @@ -1631,44 +1487,7 @@ key.nameoffset: 2866, key.namelength: 1, key.bodyoffset: 2869, - key.bodylength: 59, - key.substructure: [ - { - key.kind: source.lang.swift.decl.function.method.instance, - key.accessibility: source.lang.swift.accessibility.internal, - key.name: "foo(a:)", - key.offset: 2899, - key.length: 19, - key.selector_name: "fooWithA:", - key.nameoffset: 2904, - key.namelength: 11, - key.bodyoffset: 2917, - key.bodylength: 0, - key.attributes: [ - { - key.offset: 2893, - key.length: 5, - key.attribute: source.decl.attribute.objc.name - }, - { - key.offset: 2883, - key.length: 9, - key.attribute: source.decl.attribute.ibaction - } - ], - key.substructure: [ - { - key.kind: source.lang.swift.decl.var.parameter, - key.name: "a", - key.offset: 2908, - key.length: 6, - key.typename: "Int", - key.nameoffset: 2908, - key.namelength: 1 - } - ] - } - ] + key.bodylength: 59 } ], key.diagnostics: [ diff --git a/test/SourceKit/SyntaxMapData/syntaxmap.swift.response b/test/SourceKit/SyntaxMapData/syntaxmap.swift.response index 157901d925f04..34ed36e100af9 100644 --- a/test/SourceKit/SyntaxMapData/syntaxmap.swift.response +++ b/test/SourceKit/SyntaxMapData/syntaxmap.swift.response @@ -64,7 +64,7 @@ key.length: 3 }, { - key.kind: source.lang.swift.syntaxtype.buildconfig.id, + key.kind: source.lang.swift.syntaxtype.identifier, key.offset: 140, key.length: 4 }, @@ -79,7 +79,7 @@ key.length: 1 }, { - key.kind: source.lang.swift.syntaxtype.typeidentifier, + key.kind: source.lang.swift.syntaxtype.identifier, key.offset: 153, key.length: 3 }, @@ -99,7 +99,7 @@ key.length: 1 }, { - key.kind: source.lang.swift.syntaxtype.typeidentifier, + key.kind: source.lang.swift.syntaxtype.identifier, key.offset: 171, key.length: 5 }, diff --git a/test/swift-indent/basic.swift b/test/swift-indent/basic.swift index 29434054fcbd2..e17e5ad5d9fed 100644 --- a/test/swift-indent/basic.swift +++ b/test/swift-indent/basic.swift @@ -357,17 +357,17 @@ let x = [ var array: [String] = [] #else var array: [String] = { - return ["one", - "two"] +return ["one", +"two"] }() #endif #if os(iOS) var source: String? { - if true { - if otherCondition { - return "true" - } - } +if true { +if otherCondition { +return "true" +} +} } #endif diff --git a/test/swift-indent/main.swift.indent2.response b/test/swift-indent/main.swift.indent2.response index 81fa06f36f1f7..55a873e560324 100644 --- a/test/swift-indent/main.swift.indent2.response +++ b/test/swift-indent/main.swift.indent2.response @@ -37,7 +37,7 @@ func collatz(n: Int, m: String?) { #if true func foo() -> Int { - 0 +0 } #else 1 diff --git a/test/swift-indent/main.swift.indentswitch.response b/test/swift-indent/main.swift.indentswitch.response index a1e22470b1acb..a3fb50af74414 100644 --- a/test/swift-indent/main.swift.indentswitch.response +++ b/test/swift-indent/main.swift.indentswitch.response @@ -37,7 +37,7 @@ func collatz(n: Int, m: String?) { #if true func foo() -> Int { - 0 +0 } #else 1 diff --git a/test/swift-indent/main.swift.response b/test/swift-indent/main.swift.response index 16e9521b66d9f..6797e122f5382 100644 --- a/test/swift-indent/main.swift.response +++ b/test/swift-indent/main.swift.response @@ -37,7 +37,7 @@ func collatz(n: Int, m: String?) { #if true func foo() -> Int { - 0 +0 } #else 1 diff --git a/test/swift-indent/main.swift.tabs.response b/test/swift-indent/main.swift.tabs.response index e77879783a5fa..68e1b519e508a 100644 --- a/test/swift-indent/main.swift.tabs.response +++ b/test/swift-indent/main.swift.tabs.response @@ -37,7 +37,7 @@ func collatz(n: Int, m: String?) { #if true func foo() -> Int { - 0 +0 } #else 1 diff --git a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp index eafa3a756e737..c123c155e795c 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp @@ -1608,9 +1608,11 @@ class PlaceholderExpansionScanner { if (auto *ICD = dyn_cast(D)) { // The base walker assumes the content of active IfConfigDecl clauses // has been injected into the parent context and will be walked there. - // This doesn't hold for pre-typechecked ASTs and we need to find - // placeholders in inactive clauses anyway, so walk them here. + // This doesn't hold for pre-typechecked ASTs, so walk them here. for (auto Clause: ICD->getClauses()) { + if (!Clause.isActive) + continue; + for (auto Elem: Clause.Elements) { Elem.walk(*this); } @@ -1798,20 +1800,6 @@ class PlaceholderExpansionScanner { return Action::Continue(S); } - PreWalkAction walkToDeclPre(Decl *D) override { - if (auto *ICD = dyn_cast(D)) { - for (auto Clause : ICD->getClauses()) { - // Active clase elements are visited normally. - if (Clause.isActive) - continue; - for (auto Member : Clause.Elements) - Member.walk(*this); - } - return Action::SkipNode(); - } - return Action::Continue(); - } - ArgumentList *findEnclosingCallArg(SourceFile &SF, SourceLoc SL) { EnclosingCallAndArg = {nullptr, nullptr}; OuterExpr = nullptr;