Skip to content

Commit f899413

Browse files
committed
[SourceKit] Annotate default argument keywords #file/#line/...
rdar://problem/25128866
1 parent 0e8978a commit f899413

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,10 +2347,23 @@ void PrintAST::printOneParameter(const ParamDecl *param, bool Curried,
23472347
Printer << " = ";
23482348
auto defaultArgStr
23492349
= getDefaultArgumentSpelling(param->getDefaultArgumentKind());
2350-
if (defaultArgStr.empty())
2350+
if (defaultArgStr.empty()) {
23512351
Printer << tok::kw_default;
2352-
else
2353-
Printer << defaultArgStr;
2352+
} else {
2353+
switch (param->getDefaultArgumentKind()) {
2354+
case DefaultArgumentKind::File:
2355+
case DefaultArgumentKind::Line:
2356+
case DefaultArgumentKind::Column:
2357+
case DefaultArgumentKind::Function:
2358+
case DefaultArgumentKind::DSOHandle:
2359+
Printer.printKeyword(defaultArgStr);
2360+
break;
2361+
default:
2362+
Printer << defaultArgStr;
2363+
break;
2364+
}
2365+
2366+
}
23542367
}
23552368
}
23562369

test/SourceKit/SourceDocInfo/cursor_info.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ typealias MyAlias2<A, B> = MyAlias<A, B>
155155
func paramAutoclosureNoescape1(@noescape msg: ()->String) {}
156156
func paramAutoclosureNoescape2(@autoclosure msg: ()->String) {}
157157
func paramAutoclosureNoescape3(@autoclosure(escaping) msg: ()->String) {}
158+
159+
func paramDefaultPlaceholder(f: StaticString = #function, file: StaticString = #file, line: UInt = #line, col: UInt = #column, arr: [Int] = [], dict: [Int:Int] = [:], opt: Int? = nil, reg: Int = 1) {}
160+
158161
// RUN: rm -rf %t.tmp
159162
// RUN: mkdir %t.tmp
160163
// RUN: %swiftc_driver -emit-module -o %t.tmp/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift
@@ -564,3 +567,17 @@ func paramAutoclosureNoescape3(@autoclosure(escaping) msg: ()->String) {}
564567

565568
// RUN: %sourcekitd-test -req=cursor -pos=157:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK72
566569
// CHECK72: <decl.var.parameter><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@autoclosure</syntaxtype.attribute.name>(escaping)</syntaxtype.attribute.builtin> <decl.var.parameter.name>
570+
571+
// RUN: %sourcekitd-test -req=cursor -pos=159:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK73
572+
// CHECK73: <decl.function.free>
573+
// CHECK73-SAME: = <syntaxtype.keyword>#function</syntaxtype.keyword>
574+
// CHECK73-SAME: = <syntaxtype.keyword>#file</syntaxtype.keyword>
575+
// CHECK73-SAME: = <syntaxtype.keyword>#line</syntaxtype.keyword>
576+
// CHECK73-SAME: = <syntaxtype.keyword>#column</syntaxtype.keyword>
577+
// FIXME: []
578+
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword>
579+
// FIXME: [:]
580+
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword>
581+
// FIXME: keyword nil
582+
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword>
583+
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword>

0 commit comments

Comments
 (0)