@@ -50,7 +50,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
50
50
type: type
51
51
)
52
52
53
- let edits = try AddPackageTarget . manifestRefactor (
53
+ let edits = try AddPackageTarget . textRefactor (
54
54
syntax: scope. file,
55
55
in: . init( target: target)
56
56
)
@@ -98,7 +98,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
98
98
dependencies: [ . byName( name: targetName) ] ,
99
99
)
100
100
101
- let edits = try AddPackageTarget . manifestRefactor (
101
+ let edits = try AddPackageTarget . textRefactor (
102
102
syntax: scope. file,
103
103
in: . init( target: target, testHarness: testingLibrary)
104
104
)
@@ -151,7 +151,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
151
151
targets: [ targetName]
152
152
)
153
153
154
- let edits = try AddProduct . manifestRefactor (
154
+ let edits = try AddProduct . textRefactor (
155
155
syntax: scope. file,
156
156
in: . init( product: product)
157
157
)
@@ -175,81 +175,20 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
175
175
]
176
176
}
177
177
178
- fileprivate extension PackageEdit {
179
- /// Translate package manifest edits into a workspace edit. This can
180
- /// involve both modifications to the manifest file as well as the creation
181
- /// of new files.
178
+ fileprivate extension [ SourceEdit ] {
179
+ /// Translate package manifest edits into a workspace edit.
182
180
/// `snapshot` is the latest snapshot of the `Package.swift` file.
183
181
func asWorkspaceEdit( snapshot: DocumentSnapshot ) -> WorkspaceEdit {
184
182
// The edits to perform on the manifest itself.
185
- let manifestTextEdits = manifestEdits . map { edit in
183
+ let manifestTextEdits = map { edit in
186
184
TextEdit (
187
185
range: snapshot. absolutePositionRange ( of: edit. range) ,
188
186
newText: edit. replacement
189
187
)
190
188
}
191
189
192
- // If we couldn't figure out the manifest directory, or there are no
193
- // files to add, the only changes are the manifest edits. We're done
194
- // here.
195
- let manifestDirectoryURL = snapshot. uri. fileURL?
196
- . deletingLastPathComponent ( )
197
- guard let manifestDirectoryURL, !auxiliaryFiles. isEmpty else {
198
- return WorkspaceEdit (
199
- changes: [ snapshot. uri: manifestTextEdits]
200
- )
201
- }
202
-
203
- // Use the more full-featured documentChanges, which takes precedence
204
- // over the individual changes to documents.
205
- var documentChanges : [ WorkspaceEditDocumentChange ] = [ ]
206
-
207
- // Put the manifest changes into the array.
208
- documentChanges. append (
209
- . textDocumentEdit(
210
- TextDocumentEdit (
211
- textDocument: . init( snapshot. uri, version: snapshot. version) ,
212
- edits: manifestTextEdits. map { . textEdit( $0) }
213
- )
214
- )
215
- )
216
-
217
- // Create an populate all of the auxiliary files.
218
- for (relativePath, contents) in auxiliaryFiles {
219
- guard
220
- let url = URL (
221
- string: relativePath,
222
- relativeTo: manifestDirectoryURL
223
- )
224
- else {
225
- continue
226
- }
227
-
228
- let documentURI = DocumentURI ( url)
229
- let createFile = CreateFile (
230
- uri: documentURI
231
- )
232
-
233
- let zeroPosition = Position ( line: 0 , utf16index: 0 )
234
- let edit = TextEdit (
235
- range: zeroPosition..< zeroPosition,
236
- newText: contents. description
237
- )
238
-
239
- documentChanges. append ( . createFile( createFile) )
240
- documentChanges. append (
241
- . textDocumentEdit(
242
- TextDocumentEdit (
243
- textDocument: . init( documentURI, version: snapshot. version) ,
244
- edits: [ . textEdit( edit) ]
245
- )
246
- )
247
- )
248
- }
249
-
250
190
return WorkspaceEdit (
251
- changes: [ snapshot. uri: manifestTextEdits] ,
252
- documentChanges: documentChanges
191
+ changes: [ snapshot. uri: manifestTextEdits]
253
192
)
254
193
}
255
194
}
0 commit comments