Skip to content

Commit cdb2565

Browse files
committed
improve snapshot speed
1 parent 25c876c commit cdb2565

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

packages/opencode/src/lsp/client.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,20 @@ export namespace LSPClient {
9292
},
9393
}),
9494
5_000,
95-
).catch(() => {
96-
throw new InitializeError({ serverID })
95+
).catch((err) => {
96+
log.error("initialize error", { error: err })
97+
throw new InitializeError(
98+
{ serverID },
99+
{
100+
cause: err,
101+
},
102+
)
97103
})
104+
98105
await connection.sendNotification("initialized", {})
99-
log.info("initialized")
106+
log.info("initialized", {
107+
serverID,
108+
})
100109

101110
const files: {
102111
[path: string]: number
@@ -174,7 +183,6 @@ export namespace LSPClient {
174183
log.info("shutting down", { serverID })
175184
connection.end()
176185
connection.dispose()
177-
server.process.kill("SIGTERM")
178186
log.info("shutdown", { serverID })
179187
},
180188
}

packages/opencode/src/lsp/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export namespace LSP {
4747
const handle = await server.spawn(App.info())
4848
if (!handle) break
4949
const client = await LSPClient.create(server.id, handle).catch(
50-
() => {},
50+
(err) => log.error("", { error: err }),
5151
)
5252
if (!client) break
5353
clients.set(server.id, client)

packages/opencode/src/snapshot/index.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,32 @@ export namespace Snapshot {
1616
const log = Log.create({ service: "snapshot" })
1717

1818
export async function create(sessionID: string) {
19+
log.info("creating snapshot")
1920
const app = App.info()
2021
const git = gitdir(sessionID)
2122
const files = await Ripgrep.files({
2223
cwd: app.path.cwd,
2324
limit: app.git ? undefined : 1000,
2425
})
26+
log.info("found files", { count: files.length })
2527
// not a git repo and too big to snapshot
2628
if (!app.git && files.length === 1000) return
2729
await init({
2830
dir: app.path.cwd,
2931
gitdir: git,
3032
fs,
3133
})
34+
log.info("initialized")
3235
const status = await statusMatrix({
3336
fs,
3437
gitdir: git,
3538
dir: app.path.cwd,
3639
})
37-
await add({
38-
fs,
39-
gitdir: git,
40-
parallel: true,
41-
dir: app.path.cwd,
42-
filepath: files,
40+
log.info("matrix", {
41+
count: status.length,
4342
})
44-
for (const [file, _head, workdir, stage] of status) {
43+
const added = []
44+
for (const [file, head, workdir, stage] of status) {
4545
if (workdir === 0 && stage === 1) {
4646
log.info("remove", { file })
4747
await remove({
@@ -50,8 +50,21 @@ export namespace Snapshot {
5050
dir: app.path.cwd,
5151
filepath: file,
5252
})
53+
continue
54+
}
55+
if (workdir !== head) {
56+
added.push(file)
5357
}
5458
}
59+
log.info("removed files")
60+
await add({
61+
fs,
62+
gitdir: git,
63+
parallel: true,
64+
dir: app.path.cwd,
65+
filepath: added,
66+
})
67+
log.info("added files")
5568
const result = await commit({
5669
fs,
5770
gitdir: git,

0 commit comments

Comments
 (0)