10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- #if !NO_SWIFTPM_DEPENDENCY
14
-
15
13
import Foundation
16
14
import LanguageServerProtocol
17
- import PackageModel
18
- import PackageModelSyntax
19
15
import SwiftParser
20
- import SwiftRefactor
16
+ @ _spi ( PackageRefactor ) import SwiftRefactor
21
17
import SwiftSyntax
22
18
23
19
import struct Basics. RelativePath
@@ -41,21 +37,21 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
41
37
) -> [ CodeAction ] {
42
38
do {
43
39
var actions : [ CodeAction ] = [ ]
44
- let variants : [ ( TargetDescription . TargetKind , String ) ] = [
45
- ( . regular , " library " ) ,
40
+ let variants : [ ( PackageTarget . TargetKind , String ) ] = [
41
+ ( . library , " library " ) ,
46
42
( . executable, " executable " ) ,
47
43
( . macro, " macro " ) ,
48
44
]
49
45
50
46
for (type, name) in variants {
51
- let target = try TargetDescription (
47
+ let target = PackageTarget (
52
48
name: " NewTarget " ,
53
49
type: type
54
50
)
55
51
56
- let edits = try AddTarget . addTarget (
57
- target ,
58
- to : scope . file
52
+ let edits = try AddPackageTarget . manifestRefactor (
53
+ syntax : scope . file ,
54
+ in : . init ( target : target )
59
55
)
60
56
61
57
actions. append (
@@ -89,22 +85,21 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
89
85
do {
90
86
var actions : [ CodeAction ] = [ ]
91
87
92
- let variants : [ ( AddTarget . TestHarness , String ) ] = [
88
+ let variants : [ ( AddPackageTarget . TestHarness , String ) ] = [
93
89
( . swiftTesting, " Swift Testing " ) ,
94
90
( . xctest, " XCTest " ) ,
95
91
]
96
92
for (testingLibrary, libraryName) in variants {
97
93
// Describe the target we are going to create.
98
- let target = try TargetDescription (
94
+ let target = PackageTarget (
99
95
name: " \( targetName) Tests " ,
100
- dependencies : [ . byName ( name : targetName , condition : nil ) ] ,
101
- type : . test
96
+ type : . test ,
97
+ dependencies : [ . byName ( name : targetName ) ] ,
102
98
)
103
99
104
- let edits = try AddTarget . addTarget (
105
- target,
106
- to: scope. file,
107
- configuration: . init( testHarness: testingLibrary)
100
+ let edits = try AddPackageTarget . manifestRefactor (
101
+ syntax: scope. file,
102
+ in: . init( target: target, testHarness: testingLibrary)
108
103
)
109
104
110
105
actions. append (
@@ -143,19 +138,23 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
143
138
}
144
139
145
140
do {
146
- let type : ProductType =
141
+ let type : ProductDescription . ProductType =
147
142
calledMember == " executableTarget "
148
143
? . executable
149
144
: . library( . automatic)
150
145
151
146
// Describe the target we are going to create.
152
- let product = try ProductDescription (
147
+ let product = ProductDescription (
153
148
name: targetName,
154
149
type: type,
155
150
targets: [ targetName]
156
151
)
157
152
158
- let edits = try AddProduct . addProduct ( product, to: scope. file)
153
+ let edits = try AddProduct . manifestRefactor (
154
+ syntax: scope. file,
155
+ in: . init( product: product)
156
+ )
157
+
159
158
return [
160
159
CodeAction (
161
160
title: " Add product to export this target " ,
@@ -175,7 +174,7 @@ struct PackageManifestEdits: SyntaxCodeActionProvider {
175
174
]
176
175
}
177
176
178
- fileprivate extension PackageEditResult {
177
+ fileprivate extension PackageEdit {
179
178
/// Translate package manifest edits into a workspace edit. This can
180
179
/// involve both modifications to the manifest file as well as the creation
181
180
/// of new files.
@@ -218,7 +217,7 @@ fileprivate extension PackageEditResult {
218
217
for (relativePath, contents) in auxiliaryFiles {
219
218
guard
220
219
let url = URL (
221
- string: relativePath. pathString ,
220
+ string: relativePath,
222
221
relativeTo: manifestDirectoryURL
223
222
)
224
223
else {
@@ -300,5 +299,3 @@ fileprivate extension FunctionCallExprSyntax {
300
299
return memberAccess. declName. baseName. text
301
300
}
302
301
}
303
-
304
- #endif
0 commit comments