[IDE][Refactoring] Handle 'callAsFunction' specially in syntactic rename.

This change makes us treat it exactly as we do 'init'. We don't allow renaming the base name,
and don't fail if the basename doesn't match for calls.

Also:
  - explicit init calls/references like `MyType.init(42)` are now reported with
    'init' as a keywordBase range, rather than nothing.
  - cursor info no longer reports rename as available on init/callAsFunction
    calls without arguments, as there's nothing to rename in that case.
  - Improved detection of when a referenced function is a call (rather than
    reference) across syntactic rename, cursor-info, and indexing.

Resolves rdar://problem/60340429
This commit is contained in:
Nathan Hawes
2020-04-08 17:45:51 -07:00
parent 4264b39b23
commit bce68fa4e5
24 changed files with 441 additions and 62 deletions

View File

@@ -78,6 +78,34 @@ func foo7() -> String {
foo6()
}
struct Test {
init(x: Int = 42) {}
func callAsFunction(x: Int = 42) {}
}
Test.init
Test.init()
Test.init(x:)
Test.init(x: 3)
let callable = Test();
callable(x: 89)
callable.callAsFunction
callable.callAsFunction()
callable.callAsFunction(x:)
callable.callAsFunction(x: 78)
(callable.callAsFunction)(x: 78)
(callable.callAsFunction)()
func foo(_ x: Int) -> Test { fatalError() }
foo(39)(x: 90)
struct TestDefaultedParen {
init(_: Int = 42) {}
}
TestDefaultedParen.init()
// RUN: %sourcekitd-test -req=cursor -pos=3:1 -end-pos=5:13 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK1
// CHECK1: ACTIONS BEGIN
@@ -92,6 +120,25 @@ func foo7() -> String {
// RUN: %sourcekitd-test -req=cursor -pos=26:20 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=27:11 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-LOCAL
// RUN: %sourcekitd-test -req=cursor -pos=83:8 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=86:6 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=87:6 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=88:6 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=89:6 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=89:11 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=92:10 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=93:10 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=94:10 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=95:10 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=96:10 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=96:25 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=97:11 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=97:27 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-GLOBAL
// RUN: %sourcekitd-test -req=cursor -pos=98:11 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=107:20 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-NORENAME
// RUN: %sourcekitd-test -req=cursor -pos=35:10 -end-pos=35:16 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-RENAME-EXTRACT
// RUN: %sourcekitd-test -req=cursor -pos=35:10 -end-pos=35:16 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-RENAME-EXTRACT
@@ -106,6 +153,9 @@ func foo7() -> String {
// RUN: %sourcekitd-test -req=cursor -pos=72:5 -end-pos=72:11 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-RENAME-EXTRACT
// RUN: %sourcekitd-test -req=cursor -pos=78:3 -end-pos=78:9 -cursor-action %s -- %s | %FileCheck %s -check-prefix=CHECK-RENAME-EXTRACT
// CHECK-NORENAME-NOT: Global Rename
// CHECK-NORENAME-NOT: Local Rename
// CHECK2: ACTIONS BEGIN
// CHECK2-NEXT: source.refactoring.kind.rename.global
// CHECK2-NEXT: Global Rename