@@ -50,7 +50,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
5050 type: type
5151 )
5252
53- let edits = try AddPackageTarget . manifestRefactor (
53+ let edits = try AddPackageTarget . textRefactor (
5454 syntax: scope. file,
5555 in: . init( target: target)
5656 )
@@ -98,7 +98,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
9898 dependencies: [ . byName( name: targetName) ] ,
9999 )
100100
101- let edits = try AddPackageTarget . manifestRefactor (
101+ let edits = try AddPackageTarget . textRefactor (
102102 syntax: scope. file,
103103 in: . init( target: target, testHarness: testingLibrary)
104104 )
@@ -151,7 +151,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
151151 targets: [ targetName]
152152 )
153153
154- let edits = try AddProduct . manifestRefactor (
154+ let edits = try AddProduct . textRefactor (
155155 syntax: scope. file,
156156 in: . init( product: product)
157157 )
@@ -175,81 +175,20 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
175175 ]
176176}
177177
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.
182180 /// `snapshot` is the latest snapshot of the `Package.swift` file.
183181 func asWorkspaceEdit( snapshot: DocumentSnapshot ) -> WorkspaceEdit {
184182 // The edits to perform on the manifest itself.
185- let manifestTextEdits = manifestEdits . map { edit in
183+ let manifestTextEdits = map { edit in
186184 TextEdit (
187185 range: snapshot. absolutePositionRange ( of: edit. range) ,
188186 newText: edit. replacement
189187 )
190188 }
191189
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-
250190 return WorkspaceEdit (
251- changes: [ snapshot. uri: manifestTextEdits] ,
252- documentChanges: documentChanges
191+ changes: [ snapshot. uri: manifestTextEdits]
253192 )
254193 }
255194}
0 commit comments