Skip to content

Commit 4bd724e

Browse files
Refactors
1 parent d92d6c6 commit 4bd724e

15 files changed

Lines changed: 147 additions & 116 deletions

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@
424424
6C4E37FA2C73E00700AEE7B5 /* XCRemoteSwiftPackageReference "SwiftTerm" */,
425425
6CB94D012CA1205100E8651C /* XCRemoteSwiftPackageReference "swift-async-algorithms" */,
426426
6CF368562DBBD274006A77FD /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
427+
30ED7B722DD299E600ACC922 /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
427428
);
428429
preferredProjectObjectVersion = 55;
429430
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
@@ -1661,14 +1662,6 @@
16611662
minimumVersion = 0.9.19;
16621663
};
16631664
};
1664-
30C549D82D77BDF8008DDEF8 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
1665-
isa = XCRemoteSwiftPackageReference;
1666-
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor.git";
1667-
requirement = {
1668-
kind = upToNextMajorVersion;
1669-
minimumVersion = 0.11.0;
1670-
};
1671-
};
16721665
30CB648F2C16CA8100CC8A9E /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */ = {
16731666
isa = XCRemoteSwiftPackageReference;
16741667
repositoryURL = "https://github.com/ChimeHQ/LanguageServerProtocol";
@@ -1685,6 +1678,14 @@
16851678
minimumVersion = 0.8.0;
16861679
};
16871680
};
1681+
30ED7B722DD299E600ACC922 /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
1682+
isa = XCRemoteSwiftPackageReference;
1683+
repositoryURL = "https://github.com/weichsel/ZIPFoundation";
1684+
requirement = {
1685+
kind = upToNextMajorVersion;
1686+
minimumVersion = 0.9.19;
1687+
};
1688+
};
16881689
583E529A29361BAB001AB554 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {
16891690
isa = XCRemoteSwiftPackageReference;
16901691
repositoryURL = "https://github.com/pointfreeco/swift-snapshot-testing.git";
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// InstallationMethod.swift
3+
// CodeEdit
4+
//
5+
// Created by Abe Malla on 5/12/25.
6+
//
7+
8+
import Foundation
9+
10+
/// Installation method enum with all supported types
11+
enum InstallationMethod: Equatable {
12+
/// For standard package manager installations
13+
case standardPackage(source: PackageSource)
14+
/// For packages that need to be built from source with custom build steps
15+
case sourceBuild(source: PackageSource, command: String)
16+
/// For direct binary downloads
17+
case binaryDownload(source: PackageSource, url: URL)
18+
/// For installations that aren't recognized
19+
case unknown
20+
21+
var packageName: String? {
22+
switch self {
23+
case .standardPackage(let source),
24+
.sourceBuild(let source, _),
25+
.binaryDownload(let source, _):
26+
return source.pkgName
27+
case .unknown:
28+
return nil
29+
}
30+
}
31+
32+
var version: String? {
33+
switch self {
34+
case .standardPackage(let source),
35+
.sourceBuild(let source, _),
36+
.binaryDownload(let source, _):
37+
return source.version
38+
case .unknown:
39+
return nil
40+
}
41+
}
42+
43+
var packageManagerType: PackageManagerType? {
44+
switch self {
45+
case .standardPackage(let source),
46+
.sourceBuild(let source, _),
47+
.binaryDownload(let source, _):
48+
return source.type
49+
case .unknown:
50+
return nil
51+
}
52+
}
53+
}
54+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// PackageManagerError.swift
3+
// CodeEdit
4+
//
5+
// Created by Abe Malla on 5/12/25.
6+
//
7+
8+
enum PackageManagerError: Error {
9+
case packageManagerNotInstalled
10+
case initializationFailed(String)
11+
case installationFailed(String)
12+
case invalidConfiguration
13+
}

CodeEdit/Features/LSP/Registry/PackageManagerProtocol.swift

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protocol PackageManagerProtocol {
2323

2424
extension PackageManagerProtocol {
2525
/// Creates the directory for the language server to be installed in
26-
internal func createDirectoryStructure(for packagePath: URL) throws {
26+
func createDirectoryStructure(for packagePath: URL) throws {
2727
let decodedPath = packagePath.path.removingPercentEncoding ?? packagePath.path
2828
if !FileManager.default.fileExists(atPath: decodedPath) {
2929
try FileManager.default.createDirectory(
@@ -35,12 +35,12 @@ extension PackageManagerProtocol {
3535
}
3636

3737
/// Executes commands in the specified directory
38-
internal func executeInDirectory(in packagePath: String, _ args: [String]) async throws -> [String] {
38+
func executeInDirectory(in packagePath: String, _ args: [String]) async throws -> [String] {
3939
return try await runCommand("cd \"\(packagePath)\" && \(args.joined(separator: " "))")
4040
}
4141

4242
/// Runs a shell command and returns output
43-
internal func runCommand(_ command: String) async throws -> [String] {
43+
func runCommand(_ command: String) async throws -> [String] {
4444
var output: [String] = []
4545
for try await line in shellClient.runAsync(command) {
4646
output.append(line)
@@ -49,44 +49,6 @@ extension PackageManagerProtocol {
4949
}
5050
}
5151

52-
enum PackageManagerError: Error {
53-
case packageManagerNotInstalled
54-
case initializationFailed(String)
55-
case installationFailed(String)
56-
case invalidConfiguration
57-
}
58-
59-
enum RegistryManagerError: Error {
60-
case invalidResponse(statusCode: Int)
61-
case downloadFailed(url: URL, error: Error)
62-
case maxRetriesExceeded(url: URL, lastError: Error)
63-
case writeFailed(error: Error)
64-
}
65-
66-
/// Package manager types supported by the system
67-
enum PackageManagerType: String, Codable {
68-
/// JavaScript
69-
case npm
70-
/// Rust
71-
case cargo
72-
/// Go
73-
case golang
74-
/// Python
75-
case pip
76-
/// Ruby
77-
case gem
78-
/// C#
79-
case nuget
80-
/// OCaml
81-
case opam
82-
/// PHP
83-
case composer
84-
/// Building from source
85-
case sourceBuild
86-
/// Binary download
87-
case github
88-
}
89-
9052
/// Generic package source information that applies to all installation methods.
9153
/// Takes all the necessary information from `RegistryItem`.
9254
struct PackageSource: Equatable, Codable {
@@ -132,48 +94,3 @@ struct PackageSource: Equatable, Codable {
13294
case revision(String)
13395
}
13496
}
135-
136-
/// Installation method enum with all supported types
137-
enum InstallationMethod: Equatable {
138-
/// For standard package manager installations
139-
case standardPackage(source: PackageSource)
140-
/// For packages that need to be built from source with custom build steps
141-
case sourceBuild(source: PackageSource, command: String)
142-
/// For direct binary downloads
143-
case binaryDownload(source: PackageSource, url: URL)
144-
/// For installations that aren't recognized
145-
case unknown
146-
147-
var packageName: String? {
148-
switch self {
149-
case .standardPackage(let source),
150-
.sourceBuild(let source, _),
151-
.binaryDownload(let source, _):
152-
return source.pkgName
153-
case .unknown:
154-
return nil
155-
}
156-
}
157-
158-
var version: String? {
159-
switch self {
160-
case .standardPackage(let source),
161-
.sourceBuild(let source, _),
162-
.binaryDownload(let source, _):
163-
return source.version
164-
case .unknown:
165-
return nil
166-
}
167-
}
168-
169-
var packageManagerType: PackageManagerType? {
170-
switch self {
171-
case .standardPackage(let source),
172-
.sourceBuild(let source, _),
173-
.binaryDownload(let source, _):
174-
return source.type
175-
case .unknown:
176-
return nil
177-
}
178-
}
179-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// PackageManagerType.swift
3+
// CodeEdit
4+
//
5+
// Created by Abe Malla on 5/12/25.
6+
//
7+
8+
/// Package manager types supported by the system
9+
enum PackageManagerType: String, Codable {
10+
/// JavaScript
11+
case npm
12+
/// Rust
13+
case cargo
14+
/// Go
15+
case golang
16+
/// Python
17+
case pip
18+
/// Ruby
19+
case gem
20+
/// C#
21+
case nuget
22+
/// OCaml
23+
case opam
24+
/// PHP
25+
case composer
26+
/// Building from source
27+
case sourceBuild
28+
/// Binary download
29+
case github
30+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
final class CargoPackageManager: PackageManagerProtocol {
1111
private let installationDirectory: URL
1212

13-
internal let shellClient: ShellClient
13+
let shellClient: ShellClient
1414

1515
init(installationDirectory: URL) {
1616
self.installationDirectory = installationDirectory

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
final class GithubPackageManager: PackageManagerProtocol {
1111
private let installationDirectory: URL
1212

13-
internal let shellClient: ShellClient
13+
let shellClient: ShellClient
1414

1515
init(installationDirectory: URL) {
1616
self.installationDirectory = installationDirectory

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Foundation
99

1010
final class GolangPackageManager: PackageManagerProtocol {
1111
private let installationDirectory: URL
12-
internal let shellClient: ShellClient
12+
13+
let shellClient: ShellClient
1314

1415
init(installationDirectory: URL) {
1516
self.installationDirectory = installationDirectory

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
final class NPMPackageManager: PackageManagerProtocol {
1111
private let installationDirectory: URL
1212

13-
internal let shellClient: ShellClient
13+
let shellClient: ShellClient
1414

1515
init(installationDirectory: URL) {
1616
self.installationDirectory = installationDirectory

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
final class PipPackageManager: PackageManagerProtocol {
1111
private let installationDirectory: URL
1212

13-
internal let shellClient: ShellClient
13+
let shellClient: ShellClient
1414

1515
init(installationDirectory: URL) {
1616
self.installationDirectory = installationDirectory
@@ -81,7 +81,7 @@ final class PipPackageManager: PackageManagerProtocol {
8181
}
8282

8383
func isInstalled() async -> Bool {
84-
let pipCommands = ["pip --version", "pip3 --version", "python -m pip --version"]
84+
let pipCommands = ["pip3 --version", "python3 -m pip --version"]
8585
for command in pipCommands {
8686
do {
8787
let versionOutput = try await runCommand(command)

0 commit comments

Comments
 (0)