@@ -24,7 +24,47 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
24
24
return [ ]
25
25
}
26
26
27
- return addTestTargetActions ( call: call, in: scope) + addProductActions( call: call, in: scope)
27
+ return addTargetActions ( call: call, in: scope) + addTestTargetActions( call: call, in: scope)
28
+ + addProductActions( call: call, in: scope)
29
+ }
30
+
31
+ /// Produce code actions to add new targets of various kinds.
32
+ static func addTargetActions(
33
+ call: FunctionCallExprSyntax ,
34
+ in scope: SyntaxCodeActionScope
35
+ ) -> [ CodeAction ] {
36
+ do {
37
+ var actions : [ CodeAction ] = [ ]
38
+ let variants : [ ( TargetDescription . TargetType , String ) ] = [
39
+ ( . regular, " library " ) ,
40
+ ( . executable, " executable " ) ,
41
+ ( . macro, " macro " ) ,
42
+ ]
43
+
44
+ for (type, name) in variants {
45
+ let target = try TargetDescription (
46
+ name: " NewTarget " ,
47
+ type: type
48
+ )
49
+
50
+ let edits = try AddTarget . addTarget (
51
+ target,
52
+ to: scope. file
53
+ )
54
+
55
+ actions. append (
56
+ CodeAction (
57
+ title: " Add \( name) target " ,
58
+ kind: . refactor,
59
+ edit: edits. asWorkspaceEdit ( snapshot: scope. snapshot)
60
+ )
61
+ )
62
+ }
63
+
64
+ return actions
65
+ } catch {
66
+ return [ ]
67
+ }
28
68
}
29
69
30
70
/// Produce code actions to add test target(s) if we are currently on
@@ -77,7 +117,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
77
117
}
78
118
79
119
/// A list of target kinds that allow the creation of tests.
80
- static let targetsThatAllowTests : Set < String > = [
120
+ static let targetsThatAllowTests : [ String ] = [
81
121
" executableTarget " ,
82
122
" macro " ,
83
123
" target " ,
@@ -123,7 +163,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
123
163
}
124
164
125
165
/// A list of target kinds that allow the creation of tests.
126
- static let targetsThatAllowProducts : Set < String > = [
166
+ static let targetsThatAllowProducts : [ String ] = [
127
167
" executableTarget " ,
128
168
" target " ,
129
169
]
0 commit comments