fix(tui): gate Zed context on terminal env (#28517)
This commit is contained in:
@@ -195,6 +195,10 @@ export function resolveZedDbPath() {
|
||||
return candidates.find((item) => isFile(item))
|
||||
}
|
||||
|
||||
export function isZedTerminal() {
|
||||
return process.env.ZED_TERM === "true" || process.env.TERM_PROGRAM?.toLowerCase() === "zed"
|
||||
}
|
||||
|
||||
function isFile(item: string) {
|
||||
try {
|
||||
return Filesystem.stat(item)?.isFile() === true
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createStore } from "solid-js/store"
|
||||
import { Option, Schema, SchemaGetter } from "effect"
|
||||
import { isRecord } from "@/util/record"
|
||||
import { createSimpleContext } from "./helper"
|
||||
import { resolveZedDbPath, resolveZedSelection } from "./editor-zed"
|
||||
import { isZedTerminal, resolveZedDbPath, resolveZedSelection } from "./editor-zed"
|
||||
|
||||
const MCP_PROTOCOL_VERSION = "2025-11-25"
|
||||
|
||||
@@ -173,6 +173,12 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||
|
||||
const connection = resolveEditorConnection(directory)
|
||||
if (!connection) {
|
||||
if (!isZedTerminal()) {
|
||||
setStore("status", "disabled")
|
||||
scheduleReconnect()
|
||||
return
|
||||
}
|
||||
|
||||
const dbPath = resolveZedDbPath()
|
||||
if (!dbPath) {
|
||||
setStore("status", "disabled")
|
||||
@@ -311,7 +317,7 @@ export const { use: useEditorContext, provider: EditorContextProvider } = create
|
||||
|
||||
return {
|
||||
enabled() {
|
||||
return Boolean(resolveEditorConnection(directory) || resolveZedDbPath())
|
||||
return Boolean(resolveEditorConnection(directory) || (isZedTerminal() && resolveZedDbPath()))
|
||||
},
|
||||
connected() {
|
||||
return store.status === "connected"
|
||||
|
||||
@@ -48,12 +48,14 @@ export const Service =
|
||||
}
|
||||
|
||||
static get defaultLayer() {
|
||||
const tag = this
|
||||
return Layer.effect(
|
||||
this,
|
||||
Config.all(fields).pipe(
|
||||
tag,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.all(fields)
|
||||
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- Config.all preserves the field shape, but its conditional return type also supports iterable inputs.
|
||||
Effect.map((config) => this.of(config as Shape<Fields>)),
|
||||
),
|
||||
return tag.of(config as Shape<Fields>)
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user