refactor(lsp): move ty flag to runtime flags (#27610)

This commit is contained in:
Shoubhit Dash
2026-05-15 03:40:30 +05:30
committed by GitHub
parent 93b1ccc029
commit e22cfa435a
6 changed files with 87 additions and 10 deletions

View File

@@ -34,6 +34,7 @@ describe("RuntimeFlags", () => {
expect(flags.enableQuestionTool).toBe(true)
expect(flags.experimentalScout).toBe(true)
expect(flags.experimentalBackgroundSubagents).toBe(true)
expect(flags.experimentalLspTy).toBe(false)
expect(flags.experimentalLspTool).toBe(true)
expect(flags.experimentalOxfmt).toBe(true)
expect(flags.experimentalPlanMode).toBe(true)
@@ -44,6 +45,20 @@ describe("RuntimeFlags", () => {
}),
)
it.effect("defaultLayer parses OPENCODE_EXPERIMENTAL_LSP_TY", () =>
Effect.gen(function* () {
const flags = yield* readFlags.pipe(
Effect.provide(
fromConfig({
OPENCODE_EXPERIMENTAL_LSP_TY: "true",
}),
),
)
expect(flags.experimentalLspTy).toBe(true)
}),
)
it.effect("layer accepts partial test overrides and fills defaults from Config definitions", () =>
Effect.gen(function* () {
const flags = yield* readFlags.pipe(

View File

@@ -1,6 +1,8 @@
import { describe, expect, spyOn } from "bun:test"
import path from "path"
import { Effect, Layer } from "effect"
import { Config } from "@/config/config"
import { RuntimeFlags } from "@/effect/runtime-flags"
import { LSP } from "@/lsp/lsp"
import * as LSPServer from "@/lsp/server"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
@@ -8,6 +10,12 @@ import { provideTmpdirInstance } from "../fixture/fixture"
import { testEffect } from "../lib/effect"
const it = testEffect(Layer.mergeAll(LSP.defaultLayer, CrossSpawnSpawner.defaultLayer))
const experimentalTyIt = testEffect(
Layer.mergeAll(
LSP.layer.pipe(Layer.provide(Config.defaultLayer), Layer.provide(RuntimeFlags.layer({ experimentalLspTy: true }))),
CrossSpawnSpawner.defaultLayer,
),
)
describe("lsp.spawn", () => {
it.live("does not spawn builtin LSP for files outside instance", () =>
@@ -106,4 +114,56 @@ describe("lsp.spawn", () => {
},
),
)
it.live("uses pyright instead of ty by default", () =>
provideTmpdirInstance(
(dir) =>
LSP.Service.use((lsp) =>
Effect.gen(function* () {
const ty = spyOn(LSPServer.Ty, "spawn").mockResolvedValue(undefined)
const pyright = spyOn(LSPServer.Pyright, "spawn").mockResolvedValue(undefined)
try {
yield* lsp.hover({
file: path.join(dir, "src", "inside.py"),
line: 0,
character: 0,
})
expect(ty).toHaveBeenCalledTimes(0)
expect(pyright).toHaveBeenCalledTimes(1)
} finally {
ty.mockRestore()
pyright.mockRestore()
}
}),
),
{ config: { lsp: true } },
),
)
experimentalTyIt.live("uses ty instead of pyright when experimentalLspTy is enabled", () =>
provideTmpdirInstance(
(dir) =>
LSP.Service.use((lsp) =>
Effect.gen(function* () {
const ty = spyOn(LSPServer.Ty, "spawn").mockResolvedValue(undefined)
const pyright = spyOn(LSPServer.Pyright, "spawn").mockResolvedValue(undefined)
try {
yield* lsp.hover({
file: path.join(dir, "src", "inside.py"),
line: 0,
character: 0,
})
expect(ty).toHaveBeenCalledTimes(1)
expect(pyright).toHaveBeenCalledTimes(0)
} finally {
ty.mockRestore()
pyright.mockRestore()
}
}),
),
{ config: { lsp: true } },
),
)
})