Using directory local environment for language servers and other functionality
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- swift
- Domain
- developer-experience, tooling
Research direction
Start with the proposed EnvironmentProvider protocol and EnvironmentProviderStore design; no CodeEdit files or tests are named in the issue. Use the linked Zed shell_env.rs and environment.rs references for context, then map the work into the two stated stages. Done means directory-local environments support direnv, venv, asdf, and dotenv, are passed to relevant processes, and can later be extended through an extension API.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Swift
- Stars
- 23k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CodeEditApp/CodeEdit
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CodeEditApp/CodeEdit#2190 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 15/100
CodeEditApp/CodeEdit#2195 · 7 reactions ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
CodeEditApp/CodeEdit#2185 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
CodeEditApp/CodeEdit#2181 ·
-
creashes on starting Openbug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
CodeEditApp/CodeEdit#2180 ·
All issues in CodeEditApp/CodeEdit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
steipete/CodexBar#4009 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
auth: ServiceAccountCredentials silently ignores quota_project_id in service account JSON files Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/google-cloud-swift#1194 · 2 comments ·
Maintainers usually reply within 1 day
-
product / auth product / databases product / sites product / vcs
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Test: "nextTrack returns stream handoff for mixed playlist" depends on the saved Repeat setting Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100