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