Using directory local environment for language servers and other functionality
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- swift
调研方向
从提议的 EnvironmentProvider 协议和 EnvironmentProviderStore 设计开始;issue 中没有指定任何 CodeEdit 文件或测试。使用链接的 Zed shell_env.rs 和 environment.rs 参考作为上下文,然后将工作划分为所述的两个阶段。完成意味着目录本地环境支持 direnv、venv、asdf 和 dotenv,将其传递给相关进程,并且之后可以通过扩展 API 进行扩展。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Swift
- 星标
- 23k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CodeEditApp/CodeEdit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
CodeEditApp/CodeEdit#2190 ·
-
难度 1/5 1 小时以内 新手友好度 15/100
CodeEditApp/CodeEdit#2195 · 7 个 reaction ·
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
CodeEditApp/CodeEdit#2185 ·
-
难度 5/5 一周以上 新手友好度 25/100
CodeEditApp/CodeEdit#2181 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
CodeEditApp/CodeEdit#2180 ·
查看 CodeEditApp/CodeEdit 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
area:general bug P1 security
难度 2/5 1-3 小时 新手友好度 75/100
uttrflow/uttrflow-swift#1333 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
maxgoedjen/secretive#840 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
manaflow-ai/cmux#13763 ·