Using directory local environment for language servers and other functionality
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- swift
- Lĩnh vực
- developer-experience, tooling
Hướng nghiên cứu
Bắt đầu với thiết kế EnvironmentProvider protocol và EnvironmentProviderStore được đề xuất; issue không nêu tên tệp CodeEdit hoặc các bài kiểm thử nào. Sử dụng các tham chiếu Zed shell_env.rs và environment.rs được liên kết để làm ngữ cảnh, sau đó phân chia công việc thành hai giai đoạn đã nêu. Hoàn tất có nghĩa là các môi trường cục bộ theo thư mục hỗ trợ direnv, venv, asdf và dotenv, được truyền cho các tiến trình liên quan và sau này có thể được mở rộng thông qua một extension API.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Environment providers.
I propose a new struct: EnvironmentProviderStore, for the environment providers, which would be used to get the environment for the current directory. This should be implemented in two stages:
a) Implement the API inside of CodeEdit to iron out rough edges, implement support for direnv, venv, asdf and dotenv using it.
b) Create an extension API allowing users to extend CodeEdit with their own environment providers, move existing ones to the extensions
The protocol is as follows:
protocol EnvironmentProvider {
var displayName { get }
func update_env(_ env: [String : String], for directory: FilePath) async throws -> [String: String]
}
Then, based on this protocol, projects should use functions reliant on it to find binaries in path, as well as passing the environment to executed processes
Alternatives Considered
Install everything globally
Additional Context
An example implementation for direnv
import Foundation
struct DirenvProvider: EnvironmentProvider {
let displayName = "direnv"
func update_env(_ env: [String: String], for directory: FilePath) async throws -> [String: String] {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
process.arguments = ["direnv", "export", "json"]
process.currentDirectoryURL = URL(fileURLWithPath: directory.string)
process.environment = env
let pipe = Pipe()
process.standardOutput = pipe
process.standardError = Pipe()
try process.run()
process.waitUntilExit()
guard process.terminationStatus == 0 else {
throw DirenvError.commandFailed(exitCode: process.terminationStatus)
}
let data = pipe.fileHandleForReading.readDataToEndOfFile()
guard let jsonString = String(data: data, encoding: .utf8) else {
throw DirenvError.invalidOutput
}
guard let jsonData = jsonString.data(using: .utf8),
let exportedEnv = try JSONSerialization.jsonObject(with: jsonData) as? [String: String] else {
throw DirenvError.jsonParsingFailed
}
var updatedEnv = env
for (key, value) in exportedEnv {
updatedEnv[key] = value
}
return updatedEnv
}
}
enum DirenvError: Error, LocalizedError {
case commandFailed(exitCode: Int32)
case invalidOutput
case jsonParsingFailed
var errorDescription: String? {
switch self {
case .commandFailed(let exitCode):
return "direnv command failed with exit code \(exitCode)"
case .invalidOutput:
return "direnv produced invalid output"
case .jsonParsingFailed:
return "Failed to parse direnv JSON output"
}
}
}
This should of course be made to asynchronously execute the direnv process but that's mostly details
Zed implementation for reference (it hardcodes direnv and relies on a shell hook for everything else which is explicitly not what I want to do here:
https://github.com/zed-industries/zed/blob/main/crates/util/src/shell_env.rs
https://github.com/zed-industries/zed/blob/main/crates/project/src/environment.rs#L178
Screenshots
No response
- Ngôn ngữ chính
- Swift
- Star
- 23k
- Fork
- 1.2k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CodeEditApp/CodeEdit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
CodeEditApp/CodeEdit#2190 ·
-
Is this project dead? Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 15/100
CodeEditApp/CodeEdit#2195 · 5 reaction ·
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
CodeEditApp/CodeEdit#2185 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
CodeEditApp/CodeEdit#2181 ·
-
creashes on starting Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
CodeEditApp/CodeEdit#2180 ·
Tất cả issue của CodeEditApp/CodeEdit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
area:general bug P1 security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
uttrflow/uttrflow-swift#1333 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
maxgoedjen/secretive#840 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
manaflow-ai/cmux#13763 ·