Skip to content

Commit cf83e31

Browse files
committed
add elixir lsp support
1 parent 3bc238b commit cf83e31

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

packages/opencode/src/lsp/server.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import path from "path"
44
import { Global } from "../global"
55
import { Log } from "../util/log"
66
import { BunProc } from "../bun"
7+
import { $ } from "bun"
8+
import fs from "fs/promises"
79

810
export namespace LSPServer {
911
const log = Log.create({ service: "lsp.server" })
@@ -144,4 +146,60 @@ export namespace LSPServer {
144146
}
145147
},
146148
}
149+
150+
export const ElixirLS: Info = {
151+
id: "elixir-ls",
152+
extensions: [".ex", ".exs"],
153+
async spawn() {
154+
let binary = Bun.which("elixir-ls")
155+
if (!binary) {
156+
const elixirLsPath = path.join(Global.Path.bin, "elixir-ls")
157+
binary = path.join(
158+
Global.Path.bin,
159+
"elixir-ls-master",
160+
"release",
161+
process.platform === "win32"
162+
? "language_server.bar"
163+
: "language_server.sh",
164+
)
165+
166+
if (!(await Bun.file(binary).exists())) {
167+
const elixir = Bun.which("elixir")
168+
if (!elixir) {
169+
log.error("elixir is required to run elixir-ls")
170+
return
171+
}
172+
173+
log.info("downloading elixir-ls from GitHub releases")
174+
175+
const response = await fetch(
176+
"https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip",
177+
)
178+
if (!response.ok) return
179+
const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
180+
await Bun.file(zipPath).write(response)
181+
182+
await $`unzip -o -q ${zipPath}`.cwd(Global.Path.bin).nothrow()
183+
184+
await fs.rm(zipPath, {
185+
force: true,
186+
recursive: true,
187+
})
188+
189+
await $`mix deps.get && mix compile && mix elixir_ls.release2 -o release`
190+
.quiet()
191+
.cwd(path.join(Global.Path.bin, "elixir-ls-master"))
192+
.env({ MIX_ENV: "prod", ...process.env })
193+
194+
log.info(`installed elixir-ls`, {
195+
path: elixirLsPath,
196+
})
197+
}
198+
}
199+
200+
return {
201+
process: spawn(binary),
202+
}
203+
},
204+
}
147205
}

packages/opencode/src/tool/edit.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ export function replace(
489489
BlockAnchorReplacer,
490490
WhitespaceNormalizedReplacer,
491491
IndentationFlexibleReplacer,
492-
EscapeNormalizedReplacer,
493-
TrimmedBoundaryReplacer,
494-
ContextAwareReplacer,
495-
MultiOccurrenceReplacer,
492+
// EscapeNormalizedReplacer,
493+
// TrimmedBoundaryReplacer,
494+
// ContextAwareReplacer,
495+
// MultiOccurrenceReplacer,
496496
]) {
497497
for (const search of replacer(content, oldString)) {
498498
const index = content.indexOf(search)

0 commit comments

Comments
 (0)