Skip to content

Commit 0fe73ef

Browse files
Refactors, fix and update removals
1 parent 6b40bb3 commit 0fe73ef

17 files changed

+288
-198
lines changed

CodeEdit/Features/LSP/Registry/PackageManagerProtocol.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ struct PackageSource: Equatable, Codable {
9595
/// The type of the package manager
9696
let type: PackageManagerType
9797
/// Package name
98-
let name: String
98+
let pkgName: String
99+
/// The name in the registry.json file. Used for the folder name when saved.
100+
let entryName: String
99101
/// Package version
100102
let version: String
101103
/// URL for repository or download link
@@ -108,15 +110,17 @@ struct PackageSource: Equatable, Codable {
108110
init(
109111
sourceId: String,
110112
type: PackageManagerType,
111-
name: String,
113+
pkgName: String,
114+
entryName: String,
112115
version: String,
113116
repositoryUrl: String? = nil,
114117
gitReference: GitReference? = nil,
115118
options: [String: String] = [:]
116119
) {
117120
self.sourceId = sourceId
118121
self.type = type
119-
self.name = name
122+
self.pkgName = pkgName
123+
self.entryName = entryName
120124
self.version = version
121125
self.repositoryUrl = repositoryUrl
122126
self.gitReference = gitReference
@@ -140,7 +144,7 @@ enum InstallationMethod: Equatable {
140144
case .standardPackage(let source),
141145
.sourceBuild(let source, _),
142146
.binaryDownload(let source, _):
143-
return source.name
147+
return source.pkgName
144148
case .unknown:
145149
return nil
146150
}

CodeEdit/Features/LSP/Registry/PackageManagers/CargoPackageManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class CargoPackageManager: PackageManagerProtocol {
3434
throw PackageManagerError.invalidConfiguration
3535
}
3636

37-
let packagePath = installationDirectory.appending(path: source.name)
38-
print("Installing \(source.name)@\(source.version) in \(packagePath.path)")
37+
let packagePath = installationDirectory.appending(path: source.entryName)
38+
print("Installing \(source.entryName)@\(source.version) in \(packagePath.path)")
3939

4040
try await initialize(in: packagePath)
4141

@@ -52,7 +52,7 @@ class CargoPackageManager: PackageManagerProtocol {
5252
cargoArgs.append(contentsOf: ["--rev", rev])
5353
}
5454
} else {
55-
cargoArgs.append("\(source.name)@\(source.version)")
55+
cargoArgs.append("\(source.pkgName)@\(source.version)")
5656
}
5757

5858
if let features = source.options["features"] {
@@ -63,7 +63,7 @@ class CargoPackageManager: PackageManagerProtocol {
6363
}
6464

6565
_ = try await executeInDirectory(in: packagePath.path, cargoArgs)
66-
print("Successfully installed \(source.name)@\(source.version)")
66+
print("Successfully installed \(source.entryName)@\(source.version)")
6767
} catch {
6868
print("Installation failed: \(error)")
6969
throw error

CodeEdit/Features/LSP/Registry/PackageManagers/GithubPackageManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GithubPackageManager: PackageManagerProtocol {
3434
throw PackageManagerError.invalidConfiguration
3535
}
3636

37-
let packagePath = installationDirectory.appending(path: source.name)
37+
let packagePath = installationDirectory.appending(path: source.entryName)
3838
try await initialize(in: packagePath)
3939

4040
switch method {
@@ -67,7 +67,7 @@ class GithubPackageManager: PackageManagerProtocol {
6767
private func downloadBinary(_ source: PackageSource, _ url: URL) async throws {
6868
_ = try await URLSession.shared.data(from: url)
6969
let fileName = url.lastPathComponent
70-
let downloadPath = installationDirectory.appending(path: source.name)
70+
let downloadPath = installationDirectory.appending(path: source.entryName)
7171
let packagePath = downloadPath.appending(path: fileName)
7272

7373
if !FileManager.default.fileExists(atPath: packagePath.path) {
@@ -83,10 +83,10 @@ class GithubPackageManager: PackageManagerProtocol {
8383
}
8484

8585
private func installFromSource(_ source: PackageSource, _ command: String) async throws {
86-
let installPath = installationDirectory.appending(path: source.name, directoryHint: .isDirectory)
86+
let installPath = installationDirectory.appending(path: source.entryName, directoryHint: .isDirectory)
8787
do {
8888
_ = try await executeInDirectory(in: installPath.path, ["git", "clone", source.repositoryUrl!])
89-
let repoPath = installPath.appending(path: source.name, directoryHint: .isDirectory)
89+
let repoPath = installPath.appending(path: source.pkgName, directoryHint: .isDirectory)
9090
_ = try await executeInDirectory(in: repoPath.path, [command])
9191
} catch {
9292
print("Failed to build from source: \(error)")

CodeEdit/Features/LSP/Registry/PackageManagers/GolangPackageManager.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class GolangPackageManager: PackageManagerProtocol {
4242
throw PackageManagerError.invalidConfiguration
4343
}
4444

45-
let packagePath = installationDirectory.appending(path: source.name)
46-
print("Installing Go package \(source.name)@\(source.version) in \(packagePath.path)")
45+
let packagePath = installationDirectory.appending(path: source.entryName)
46+
print("Installing Go package \(source.entryName)@\(source.version) in \(packagePath.path)")
4747

4848
try await initialize(in: packagePath)
4949

@@ -62,13 +62,13 @@ class GolangPackageManager: PackageManagerProtocol {
6262
}
6363

6464
let binaryName = subpath.components(separatedBy: "/").last ??
65-
source.name.components(separatedBy: "/").last ?? source.name
65+
source.pkgName.components(separatedBy: "/").last ?? source.pkgName
6666
let buildArgs = ["go", "build", "-o", "bin/\(binaryName)"]
6767

68-
// If source.name includes the full import path (like github.com/owner/repo)
69-
if source.name.contains("/") {
68+
// If source.pkgName includes the full import path (like github.com/owner/repo)
69+
if source.pkgName.contains("/") {
7070
_ = try await executeInDirectory(
71-
in: packagePath.path, buildArgs + ["\(source.name)/\(subpath)"]
71+
in: packagePath.path, buildArgs + ["\(source.pkgName)/\(subpath)"]
7272
)
7373
} else {
7474
_ = try await executeInDirectory(
@@ -79,7 +79,7 @@ class GolangPackageManager: PackageManagerProtocol {
7979
_ = try await runCommand("chmod +x \"\(execPath)\"")
8080
}
8181

82-
print("Successfully installed \(source.name)@\(source.version)")
82+
print("Successfully installed \(source.entryName)@\(source.version)")
8383
} catch {
8484
print("Installation failed: \(error)")
8585
try? cleanupFailedInstallation(packagePath: packagePath)
@@ -138,7 +138,7 @@ class GolangPackageManager: PackageManagerProtocol {
138138
private func getGoInstallCommand(_ source: PackageSource) -> String {
139139
if let gitRef = source.gitReference, let repoUrl = source.repositoryUrl {
140140
// Check if this is a Git-based package
141-
var packageName = source.name
141+
var packageName = source.pkgName
142142
if !packageName.contains("github.com") && !packageName.contains("golang.org") {
143143
packageName = repoUrl.replacingOccurrences(of: "https://", with: "")
144144
}
@@ -153,7 +153,7 @@ class GolangPackageManager: PackageManagerProtocol {
153153

154154
return "\(packageName)@\(gitVersion)"
155155
} else {
156-
return "\(source.name)@\(source.version)"
156+
return "\(source.pkgName)@\(source.version)"
157157
}
158158
}
159159
}

CodeEdit/Features/LSP/Registry/PackageManagers/NPMPackageManager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class NPMPackageManager: PackageManagerProtocol {
5555
throw PackageManagerError.invalidConfiguration
5656
}
5757

58-
let packagePath = installationDirectory.appending(path: source.name)
59-
print("Installing \(source.name)@\(source.version) in \(packagePath.path)")
58+
let packagePath = installationDirectory.appending(path: source.entryName)
59+
print("Installing \(source.entryName)@\(source.version) in \(packagePath.path)")
6060

6161
try await initialize(in: packagePath)
6262

6363
do {
64-
var installArgs = ["npm", "install", "\(source.name)@\(source.version)"]
64+
var installArgs = ["npm", "install", "\(source.pkgName)@\(source.version)"]
6565
if let dev = source.options["dev"], dev.lowercased() == "true" {
6666
installArgs.append("--save-dev")
6767
}
@@ -72,9 +72,9 @@ class NPMPackageManager: PackageManagerProtocol {
7272
}
7373

7474
_ = try await executeInDirectory(in: packagePath.path, installArgs)
75-
try verifyInstallation(package: source.name, version: source.version)
75+
try verifyInstallation(folderName: source.entryName, package: source.pkgName, version: source.version)
7676

77-
print("Successfully installed \(source.name)@\(source.version)")
77+
print("Successfully installed \(source.entryName)@\(source.version)")
7878
} catch {
7979
print("Installation failed: \(error)")
8080
let nodeModulesPath = packagePath.appending(path: "node_modules").path
@@ -107,8 +107,8 @@ class NPMPackageManager: PackageManagerProtocol {
107107
}
108108

109109
/// Verify the installation was successful
110-
private func verifyInstallation(package: String, version: String) throws {
111-
let packagePath = installationDirectory.appending(path: package)
110+
private func verifyInstallation(folderName: String, package: String, version: String) throws {
111+
let packagePath = installationDirectory.appending(path: folderName)
112112
let packageJsonPath = packagePath.appending(path: "package.json").path
113113

114114
// Verify package.json contains the installed package

CodeEdit/Features/LSP/Registry/PackageManagers/PipPackageManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class PipPackageManager: PackageManagerProtocol {
4242
throw PackageManagerError.invalidConfiguration
4343
}
4444

45-
let packagePath = installationDirectory.appending(path: source.name)
46-
print("Installing \(source.name)@\(source.version) in \(packagePath.path)")
45+
let packagePath = installationDirectory.appending(path: source.entryName)
46+
print("Installing \(source.entryName)@\(source.version) in \(packagePath.path)")
4747

4848
try await initialize(in: packagePath)
4949

@@ -52,9 +52,9 @@ class PipPackageManager: PackageManagerProtocol {
5252
var installArgs = [pipCommand, "install"]
5353

5454
if source.version.lowercased() != "latest" {
55-
installArgs.append("\(source.name)==\(source.version)")
55+
installArgs.append("\(source.pkgName)==\(source.version)")
5656
} else {
57-
installArgs.append(source.name)
57+
installArgs.append(source.pkgName)
5858
}
5959

6060
let extras = source.options["extra"]
@@ -66,9 +66,9 @@ class PipPackageManager: PackageManagerProtocol {
6666

6767
_ = try await executeInDirectory(in: packagePath.path, installArgs)
6868
try await updateRequirements(packagePath: packagePath)
69-
try await verifyInstallation(packagePath: packagePath, package: source.name)
69+
try await verifyInstallation(packagePath: packagePath, package: source.pkgName)
7070

71-
print("Successfully installed \(source.name)@\(source.version)")
71+
print("Successfully installed \(source.entryName)@\(source.version)")
7272
} catch {
7373
print("Installation failed: \(error)")
7474
throw error

CodeEdit/Features/LSP/Registry/PackageSourceParser/PackageSourceParser+Cargo.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ extension PackageSourceParser {
6161
let source = PackageSource(
6262
sourceId: sourceId,
6363
type: .cargo,
64-
name: packageName,
64+
pkgName: packageName,
65+
entryName: entry.name,
6566
version: version,
6667
repositoryUrl: repositoryUrl,
6768
gitReference: gitReference,

CodeEdit/Features/LSP/Registry/PackageSourceParser/PackageSourceParser+Gem.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ extension PackageSourceParser {
5151
let source = PackageSource(
5252
sourceId: sourceId,
5353
type: .gem,
54-
name: packageName,
54+
pkgName: packageName,
55+
entryName: entry.name,
5556
version: version,
5657
repositoryUrl: repositoryUrl,
5758
gitReference: gitReference,

CodeEdit/Features/LSP/Registry/PackageSourceParser/PackageSourceParser+Golang.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ extension PackageSourceParser {
6363
let source = PackageSource(
6464
sourceId: sourceId,
6565
type: .golang,
66-
name: packageName,
66+
pkgName: packageName,
67+
entryName: entry.name,
6768
version: version,
6869
repositoryUrl: repositoryUrl,
6970
gitReference: gitReference,

CodeEdit/Features/LSP/Registry/PackageSourceParser/PackageSourceParser+NPM.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension PackageSourceParser {
1919
let packageVersion = String(components[0])
2020
let parameters = components.count > 1 ? String(components[1]) : ""
2121

22-
let (packageName, version) = parseNPMPackageVersion(packageVersion)
22+
let (packageName, version) = parseNPMPackageNameAndVersion(packageVersion)
2323

2424
// Parse parameters as options
2525
var options: [String: String] = ["buildTool": "npm"]
@@ -48,7 +48,8 @@ extension PackageSourceParser {
4848
let source = PackageSource(
4949
sourceId: sourceId,
5050
type: .npm,
51-
name: packageName,
51+
pkgName: packageName,
52+
entryName: entry.name,
5253
version: version,
5354
repositoryUrl: repositoryUrl,
5455
gitReference: gitReference,
@@ -57,7 +58,7 @@ extension PackageSourceParser {
5758
return .standardPackage(source: source)
5859
}
5960

60-
private static func parseNPMPackageVersion(_ packageVersion: String) -> (String, String) {
61+
private static func parseNPMPackageNameAndVersion(_ packageVersion: String) -> (String, String) {
6162
var packageName: String
6263
var version: String = "latest"
6364

0 commit comments

Comments
 (0)