@@ -26,24 +26,12 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
26
26
return [ ]
27
27
}
28
28
29
- var actions = [ CodeAction] ( )
30
-
31
- // Add test target(s)
32
- actions. append (
33
- contentsOf: maybeAddTestTargetActions ( call: call, in: scope)
34
- )
35
-
36
- // Add product(s).
37
- actions. append (
38
- contentsOf: maybeAddProductActions ( call: call, in: scope)
39
- )
40
-
41
- return actions
29
+ return addTestTargetActions ( call: call, in: scope) + addProductActions( call: call, in: scope)
42
30
}
43
31
44
32
/// Produce code actions to add test target(s) if we are currently on
45
33
/// a target for which we know how to create a test.
46
- static func maybeAddTestTargetActions (
34
+ static func addTestTargetActions (
47
35
call: FunctionCallExprSyntax ,
48
36
in scope: SyntaxCodeActionScope
49
37
) -> [ CodeAction ] {
@@ -84,7 +72,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
84
72
85
73
/// Produce code actions to add a product if we are currently on
86
74
/// a target for which we can create a product.
87
- static func maybeAddProductActions (
75
+ static func addProductActions (
88
76
call: FunctionCallExprSyntax ,
89
77
in scope: SyntaxCodeActionScope
90
78
) -> [ CodeAction ] {
@@ -103,7 +91,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
103
91
104
92
// Describe the target we are going to create.
105
93
let product = try ProductDescription (
106
- name: " \( targetName) " ,
94
+ name: targetName,
107
95
type: type,
108
96
targets: [ targetName]
109
97
)
@@ -132,6 +120,7 @@ fileprivate extension PackageEditResult {
132
120
/// Translate package manifest edits into a workspace edit. This can
133
121
/// involve both modifications to the manifest file as well as the creation
134
122
/// of new files.
123
+ /// `snapshot` is the latest snapshot of the `Package.swift` file.
135
124
func asWorkspaceEdit( snapshot: DocumentSnapshot ) -> WorkspaceEdit {
136
125
// The edits to perform on the manifest itself.
137
126
let manifestTextEdits = manifestEdits. map { edit in
@@ -144,9 +133,9 @@ fileprivate extension PackageEditResult {
144
133
// If we couldn't figure out the manifest directory, or there are no
145
134
// files to add, the only changes are the manifest edits. We're done
146
135
// here.
147
- let manifestDirectoryURI = snapshot. uri. fileURL?
136
+ let manifestDirectoryURL = snapshot. uri. fileURL?
148
137
. deletingLastPathComponent ( )
149
- guard let manifestDirectoryURI , !auxiliaryFiles. isEmpty else {
138
+ guard let manifestDirectoryURL , !auxiliaryFiles. isEmpty else {
150
139
return WorkspaceEdit (
151
140
changes: [ snapshot. uri: manifestTextEdits]
152
141
)
@@ -159,8 +148,8 @@ fileprivate extension PackageEditResult {
159
148
// Put the manifest changes into the array.
160
149
documentChanges. append (
161
150
. textDocumentEdit(
162
- . init (
163
- textDocument: . init( snapshot. uri, version: nil ) ,
151
+ TextDocumentEdit (
152
+ textDocument: . init( snapshot. uri, version: snapshot . version ) ,
164
153
edits: manifestTextEdits. map { . textEdit( $0) }
165
154
)
166
155
)
@@ -169,15 +158,15 @@ fileprivate extension PackageEditResult {
169
158
// Create an populate all of the auxiliary files.
170
159
for (relativePath, contents) in auxiliaryFiles {
171
160
guard
172
- let uri = URL (
161
+ let url = URL (
173
162
string: relativePath. pathString,
174
- relativeTo: manifestDirectoryURI
163
+ relativeTo: manifestDirectoryURL
175
164
)
176
165
else {
177
166
continue
178
167
}
179
168
180
- let documentURI = DocumentURI ( uri )
169
+ let documentURI = DocumentURI ( url )
181
170
let createFile = CreateFile (
182
171
uri: documentURI
183
172
)
@@ -191,8 +180,8 @@ fileprivate extension PackageEditResult {
191
180
documentChanges. append ( . createFile( createFile) )
192
181
documentChanges. append (
193
182
. textDocumentEdit(
194
- . init (
195
- textDocument: . init( documentURI, version: nil ) ,
183
+ TextDocumentEdit (
184
+ textDocument: . init( documentURI, version: snapshot . version ) ,
196
185
edits: [ . textEdit( edit) ]
197
186
)
198
187
)
0 commit comments