Skip to content

Commit 80d16d9

Browse files
Small update
1 parent ca48313 commit 80d16d9

File tree

3 files changed

+125
-85
lines changed

3 files changed

+125
-85
lines changed

CodeEdit/Features/LSP/Registry/PackageManagerFactory.swift

Lines changed: 82 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
/// Factory for creating the appropriate package manager based on installation method
1111
final class PackageManagerFactory {
12-
let installationDirectory: URL
12+
private let installationDirectory: URL
1313

1414
init(installationDirectory: URL) {
1515
self.installationDirectory = installationDirectory
@@ -37,94 +37,91 @@ final class PackageManagerFactory {
3737
}
3838

3939
/// Parse a registry entry and create the appropriate installation method
40-
static func parseRegistryEntry(_ entry: [String: Any]) -> InstallationMethod? {
41-
guard let source = entry["source"] as? [String: Any],
42-
let sourceId = source["id"] as? String else {
43-
return nil
44-
}
45-
46-
let buildInstructions = source["build"] as? [[String: Any]]
47-
48-
// Detect the build tool from the registry entry
49-
var buildTool: String?
50-
if let bin = entry["bin"] as? [String: String] {
51-
let binValues = Array(bin.values)
52-
if !binValues.isEmpty {
53-
let value = binValues[0]
54-
if value.hasPrefix("cargo:") {
55-
buildTool = "cargo"
56-
} else if value.hasPrefix("npm:") {
57-
buildTool = "npm"
58-
} else if value.hasPrefix("pypi:") {
59-
buildTool = "pip"
60-
} else if value.hasPrefix("gem:") {
61-
buildTool = "gem"
62-
} else if value.hasPrefix("golang:") {
63-
buildTool = "golang"
64-
}
65-
}
66-
}
67-
68-
var method = PackageSourceParser.parse(sourceId, buildInstructions: buildInstructions)
69-
70-
if let buildTool = buildTool {
71-
switch method {
72-
case .standardPackage(var source):
73-
var options = source.options
74-
options["buildTool"] = buildTool
75-
source = PackageSource(
76-
sourceId: source.sourceId,
77-
type: source.type,
78-
name: source.name,
79-
version: source.version,
80-
subpath: source.subpath,
81-
repositoryUrl: source.repositoryUrl,
82-
gitReference: source.gitReference,
83-
options: options
84-
)
85-
method = .standardPackage(source: source)
86-
case .sourceBuild(var source, let instructions):
87-
var options = source.options
88-
options["buildTool"] = buildTool
89-
source = PackageSource(
90-
sourceId: source.sourceId,
91-
type: source.type,
92-
name: source.name,
93-
version: source.version,
94-
subpath: source.subpath,
95-
repositoryUrl: source.repositoryUrl,
96-
gitReference: source.gitReference,
97-
options: options
98-
)
99-
method = .sourceBuild(source: source, buildInstructions: instructions)
100-
case .binaryDownload(var source, let url):
101-
var options = source.options
102-
options["buildTool"] = buildTool
103-
source = PackageSource(
104-
sourceId: source.sourceId,
105-
type: source.type,
106-
name: source.name,
107-
version: source.version,
108-
subpath: source.subpath,
109-
repositoryUrl: source.repositoryUrl,
110-
gitReference: source.gitReference,
111-
options: options
112-
)
113-
method = .binaryDownload(source: source, url: url)
114-
case .unknown:
115-
break
116-
}
117-
}
118-
return method
40+
static func parseRegistryEntry(_ entry: RegistryItem) -> InstallationMethod? {
41+
// let buildInstructions = source["build"] as? [[String: Any]]
42+
// entry.source.build
43+
//
44+
// // Detect the build tool from the registry entry
45+
// var buildTool: String?
46+
// if let bin = entry.bin {
47+
// let binValues = Array(bin.values)
48+
// if !binValues.isEmpty {
49+
// let value = binValues[0]
50+
// if value.hasPrefix("cargo:") {
51+
// buildTool = "cargo"
52+
// } else if value.hasPrefix("npm:") {
53+
// buildTool = "npm"
54+
// } else if value.hasPrefix("pypi:") {
55+
// buildTool = "pip"
56+
// } else if value.hasPrefix("gem:") {
57+
// buildTool = "gem"
58+
// } else if value.hasPrefix("golang:") {
59+
// buildTool = "golang"
60+
// }
61+
// }
62+
// }
63+
//
64+
// var method = PackageSourceParser.parse(entry.source.id, buildInstructions: buildInstructions)
65+
//
66+
// if let buildTool = buildTool {
67+
// switch method {
68+
// case .standardPackage(var source):
69+
// var options = source.options
70+
// options["buildTool"] = buildTool
71+
// source = PackageSource(
72+
// sourceId: source.sourceId,
73+
// type: source.type,
74+
// name: source.name,
75+
// version: source.version,
76+
// subpath: source.subpath,
77+
// repositoryUrl: source.repositoryUrl,
78+
// gitReference: source.gitReference,
79+
// options: options
80+
// )
81+
// method = .standardPackage(source: source)
82+
// case .sourceBuild(var source, let instructions):
83+
// var options = source.options
84+
// options["buildTool"] = buildTool
85+
// source = PackageSource(
86+
// sourceId: source.sourceId,
87+
// type: source.type,
88+
// name: source.name,
89+
// version: source.version,
90+
// subpath: source.subpath,
91+
// repositoryUrl: source.repositoryUrl,
92+
// gitReference: source.gitReference,
93+
// options: options
94+
// )
95+
// method = .sourceBuild(source: source, buildInstructions: instructions)
96+
// case .binaryDownload(var source, let url):
97+
// var options = source.options
98+
// options["buildTool"] = buildTool
99+
// source = PackageSource(
100+
// sourceId: source.sourceId,
101+
// type: source.type,
102+
// name: source.name,
103+
// version: source.version,
104+
// subpath: source.subpath,
105+
// repositoryUrl: source.repositoryUrl,
106+
// gitReference: source.gitReference,
107+
// options: options
108+
// )
109+
// method = .binaryDownload(source: source, url: url)
110+
// case .unknown:
111+
// break
112+
// }
113+
// }
114+
// return method
115+
return nil
119116
}
120117

121118
/// Install a package from a registry entry
122119
func installFromRegistryEntry(_ entry: [String: Any]) async throws {
123-
guard let method = PackageManagerFactory.parseRegistryEntry(entry),
124-
let manager = createPackageManager(for: method) else {
125-
throw PackageManagerError.invalidConfiguration
126-
}
127-
try await manager.install(method: method)
120+
// guard let method = PackageManagerFactory.parseRegistryEntry(entry),
121+
// let manager = createPackageManager(for: method) else {
122+
// throw PackageManagerError.invalidConfiguration
123+
// }
124+
// try await manager.install(method: method)
128125
}
129126

130127
/// Install a package from a source ID string

CodeEdit/Features/LSP/Registry/RegistryManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ final class RegistryManager {
107107
}
108108
}
109109

110+
// func installPackage(package entry: RegistryItem) {
111+
// PackageManagerFactory.init(installationDirectory: saveLocation).installFromRegistryEntry(entry)
112+
// }
113+
110114
/// Attempts downloading from `url`, with error handling and a retry policy
111115
private func download(from url: URL, attempt: Int = 1) async throws -> Data {
112116
do {

CodeEdit/Features/LSP/Registry/RegistryPackage.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct RegistryItem: Codable {
2121
struct Source: Codable {
2222
let id: String
2323
let asset: AssetContainer?
24+
let build: BuildContainer?
2425
let versionOverrides: [VersionOverride]?
2526

2627
enum AssetContainer: Codable {
@@ -63,6 +64,44 @@ struct RegistryItem: Codable {
6364
}
6465
}
6566

67+
enum BuildContainer: Codable {
68+
case single(Build)
69+
case multiple([Build])
70+
case none
71+
72+
init(from decoder: Decoder) throws {
73+
if let container = try? decoder.singleValueContainer() {
74+
if let singleValue = try? container.decode(Build.self) {
75+
self = .single(singleValue)
76+
return
77+
} else if let multipleValues = try? container.decode([Build].self) {
78+
self = .multiple(multipleValues)
79+
return
80+
}
81+
}
82+
self = .none
83+
}
84+
85+
func encode(to encoder: Encoder) throws {
86+
var container = encoder.singleValueContainer()
87+
switch self {
88+
case .single(let value):
89+
try container.encode(value)
90+
case .multiple(let values):
91+
try container.encode(values)
92+
case .none:
93+
try container.encodeNil()
94+
}
95+
}
96+
}
97+
98+
struct Build: Codable {
99+
let target: String?
100+
let run: String
101+
let env: [String: String]?
102+
let bin: String?
103+
}
104+
66105
struct Asset: Codable {
67106
let target: Target
68107
let file: String?

0 commit comments

Comments
 (0)