mirror of
https://github.com/sst/opencode.git
synced 2025-07-07 16:14:59 +00:00
improve snapshot speed
This commit is contained in:
parent
25c876caa2
commit
cdb25656d5
3 changed files with 33 additions and 12 deletions
|
@ -92,11 +92,20 @@ export namespace LSPClient {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
5_000,
|
5_000,
|
||||||
).catch(() => {
|
).catch((err) => {
|
||||||
throw new InitializeError({ serverID })
|
log.error("initialize error", { error: err })
|
||||||
|
throw new InitializeError(
|
||||||
|
{ serverID },
|
||||||
|
{
|
||||||
|
cause: err,
|
||||||
|
},
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
await connection.sendNotification("initialized", {})
|
await connection.sendNotification("initialized", {})
|
||||||
log.info("initialized")
|
log.info("initialized", {
|
||||||
|
serverID,
|
||||||
|
})
|
||||||
|
|
||||||
const files: {
|
const files: {
|
||||||
[path: string]: number
|
[path: string]: number
|
||||||
|
@ -174,7 +183,6 @@ export namespace LSPClient {
|
||||||
log.info("shutting down", { serverID })
|
log.info("shutting down", { serverID })
|
||||||
connection.end()
|
connection.end()
|
||||||
connection.dispose()
|
connection.dispose()
|
||||||
server.process.kill("SIGTERM")
|
|
||||||
log.info("shutdown", { serverID })
|
log.info("shutdown", { serverID })
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ export namespace LSP {
|
||||||
const handle = await server.spawn(App.info())
|
const handle = await server.spawn(App.info())
|
||||||
if (!handle) break
|
if (!handle) break
|
||||||
const client = await LSPClient.create(server.id, handle).catch(
|
const client = await LSPClient.create(server.id, handle).catch(
|
||||||
() => {},
|
(err) => log.error("", { error: err }),
|
||||||
)
|
)
|
||||||
if (!client) break
|
if (!client) break
|
||||||
clients.set(server.id, client)
|
clients.set(server.id, client)
|
||||||
|
|
|
@ -16,12 +16,14 @@ export namespace Snapshot {
|
||||||
const log = Log.create({ service: "snapshot" })
|
const log = Log.create({ service: "snapshot" })
|
||||||
|
|
||||||
export async function create(sessionID: string) {
|
export async function create(sessionID: string) {
|
||||||
|
log.info("creating snapshot")
|
||||||
const app = App.info()
|
const app = App.info()
|
||||||
const git = gitdir(sessionID)
|
const git = gitdir(sessionID)
|
||||||
const files = await Ripgrep.files({
|
const files = await Ripgrep.files({
|
||||||
cwd: app.path.cwd,
|
cwd: app.path.cwd,
|
||||||
limit: app.git ? undefined : 1000,
|
limit: app.git ? undefined : 1000,
|
||||||
})
|
})
|
||||||
|
log.info("found files", { count: files.length })
|
||||||
// not a git repo and too big to snapshot
|
// not a git repo and too big to snapshot
|
||||||
if (!app.git && files.length === 1000) return
|
if (!app.git && files.length === 1000) return
|
||||||
await init({
|
await init({
|
||||||
|
@ -29,19 +31,17 @@ export namespace Snapshot {
|
||||||
gitdir: git,
|
gitdir: git,
|
||||||
fs,
|
fs,
|
||||||
})
|
})
|
||||||
|
log.info("initialized")
|
||||||
const status = await statusMatrix({
|
const status = await statusMatrix({
|
||||||
fs,
|
fs,
|
||||||
gitdir: git,
|
gitdir: git,
|
||||||
dir: app.path.cwd,
|
dir: app.path.cwd,
|
||||||
})
|
})
|
||||||
await add({
|
log.info("matrix", {
|
||||||
fs,
|
count: status.length,
|
||||||
gitdir: git,
|
|
||||||
parallel: true,
|
|
||||||
dir: app.path.cwd,
|
|
||||||
filepath: files,
|
|
||||||
})
|
})
|
||||||
for (const [file, _head, workdir, stage] of status) {
|
const added = []
|
||||||
|
for (const [file, head, workdir, stage] of status) {
|
||||||
if (workdir === 0 && stage === 1) {
|
if (workdir === 0 && stage === 1) {
|
||||||
log.info("remove", { file })
|
log.info("remove", { file })
|
||||||
await remove({
|
await remove({
|
||||||
|
@ -50,8 +50,21 @@ export namespace Snapshot {
|
||||||
dir: app.path.cwd,
|
dir: app.path.cwd,
|
||||||
filepath: file,
|
filepath: file,
|
||||||
})
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (workdir !== head) {
|
||||||
|
added.push(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("removed files")
|
||||||
|
await add({
|
||||||
|
fs,
|
||||||
|
gitdir: git,
|
||||||
|
parallel: true,
|
||||||
|
dir: app.path.cwd,
|
||||||
|
filepath: added,
|
||||||
|
})
|
||||||
|
log.info("added files")
|
||||||
const result = await commit({
|
const result = await commit({
|
||||||
fs,
|
fs,
|
||||||
gitdir: git,
|
gitdir: git,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue