refactor(tui): replace v2 sync with data context (#31826)

This commit is contained in:
Dax
2026-06-10 23:34:35 -04:00
committed by GitHub
parent 69623c2b79
commit 47a45601fd
16 changed files with 1113 additions and 2380 deletions
@@ -9,7 +9,7 @@ import { useEditorContext } from "../../context/editor"
import { useProject } from "../../context/project"
import { useSDK } from "../../context/sdk"
import { useSync } from "../../context/sync"
import { useSyncV2 } from "../../context/sync-v2"
import { useData } from "../../context/data"
import { getScrollAcceleration } from "../../util/scroll"
import { useTuiPaths } from "../../context/runtime"
import { useTuiConfig } from "../../config"
@@ -85,7 +85,7 @@ export function Autocomplete(props: {
const editor = useEditorContext()
const sdk = useSDK()
const sync = useSync()
const syncV2 = useSyncV2()
const data = useData()
const project = useProject()
const slashes = useCommandSlashes()
const modeStack = useOpencodeModeStack()
@@ -273,12 +273,14 @@ export function Autocomplete(props: {
}
}
const references = createMemo(() => data.location.reference.list() ?? [])
const referenceMatch = createMemo(() => {
if (!store.visible || store.visible === "/") return
const { baseQuery } = extractLineRange(search())
const slash = baseQuery.indexOf("/")
const alias = slash === -1 ? baseQuery : baseQuery.slice(0, slash)
return syncV2.data.reference.find((item) => !item.hidden && item.name === alias)
return references().find((item) => !item.hidden && item.name === alias)
})
function normalizeMentionPath(filePath: string) {
@@ -312,14 +314,12 @@ export function Autocomplete(props: {
async (query) => {
if (!store.visible || store.visible === "/") return []
if (referenceMatch()) return []
const { lineRange, baseQuery } = extractLineRange(query ?? "")
// Get files from SDK
const result = await sdk.client.v2.fs.find({
const result = await sdk.client.find.files({
query: baseQuery,
limit: "20",
location: { workspace: project.workspace.current() },
workspace: project.workspace.current(),
})
const options: AutocompleteOption[] = []
@@ -329,14 +329,15 @@ export function Autocomplete(props: {
if (!result.error && result.data) {
const width = props.anchor().width - 4
options.push(
...result.data.data.map((item): AutocompleteOption => {
const { filename, url, part } = createFilePart(item.path, lineRange)
...result.data.map((item): AutocompleteOption => {
const { filename, url, part } = createFilePart(item, lineRange)
const isDir = item.endsWith("/")
return {
display: Locale.truncateMiddle(filename, width),
value: filename,
isDirectory: item.type === "directory",
path: item.path,
isDirectory: isDir,
path: item,
onSelect: () => {
insertPart(filename, part)
},
@@ -389,16 +390,15 @@ export function Autocomplete(props: {
})
const agents = createMemo(() => {
const agents = sync.data.agent
return agents
return (data.location.agent.list() ?? [])
.filter((agent) => !agent.hidden && agent.mode !== "primary")
.map(
(agent): AutocompleteOption => ({
display: "@" + agent.name,
display: "@" + agent.id,
onSelect: () => {
insertPart(agent.name, {
insertPart(agent.id, {
type: "agent",
name: agent.name,
name: agent.id,
source: {
start: 0,
end: 0,
@@ -411,7 +411,7 @@ export function Autocomplete(props: {
})
const referenceAliases = createMemo(() =>
syncV2.data.reference
references()
.filter((reference) => !reference.hidden)
.map(
(reference): AutocompleteOption => ({
@@ -471,8 +471,6 @@ export function Autocomplete(props: {
const commandsValue = commands()
const searchValue = search()
// @<alias>/... — narrow to the matched reference, files come from fff
// already ranked so there is no re-ranking here.
if (store.visible === "@" && referenceMatchValue) {
return referenceAliasesValue.filter((item) => item.display === `@${referenceMatchValue.name}`)
}