mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
add elixir lsp support
This commit is contained in:
parent
3bc238b58b
commit
cf83e31f23
2 changed files with 62 additions and 4 deletions
|
@ -4,6 +4,8 @@ import path from "path"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { BunProc } from "../bun"
|
import { BunProc } from "../bun"
|
||||||
|
import { $ } from "bun"
|
||||||
|
import fs from "fs/promises"
|
||||||
|
|
||||||
export namespace LSPServer {
|
export namespace LSPServer {
|
||||||
const log = Log.create({ service: "lsp.server" })
|
const log = Log.create({ service: "lsp.server" })
|
||||||
|
@ -144,4 +146,60 @@ export namespace LSPServer {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ElixirLS: Info = {
|
||||||
|
id: "elixir-ls",
|
||||||
|
extensions: [".ex", ".exs"],
|
||||||
|
async spawn() {
|
||||||
|
let binary = Bun.which("elixir-ls")
|
||||||
|
if (!binary) {
|
||||||
|
const elixirLsPath = path.join(Global.Path.bin, "elixir-ls")
|
||||||
|
binary = path.join(
|
||||||
|
Global.Path.bin,
|
||||||
|
"elixir-ls-master",
|
||||||
|
"release",
|
||||||
|
process.platform === "win32"
|
||||||
|
? "language_server.bar"
|
||||||
|
: "language_server.sh",
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!(await Bun.file(binary).exists())) {
|
||||||
|
const elixir = Bun.which("elixir")
|
||||||
|
if (!elixir) {
|
||||||
|
log.error("elixir is required to run elixir-ls")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("downloading elixir-ls from GitHub releases")
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
"https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip",
|
||||||
|
)
|
||||||
|
if (!response.ok) return
|
||||||
|
const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
|
||||||
|
await Bun.file(zipPath).write(response)
|
||||||
|
|
||||||
|
await $`unzip -o -q ${zipPath}`.cwd(Global.Path.bin).nothrow()
|
||||||
|
|
||||||
|
await fs.rm(zipPath, {
|
||||||
|
force: true,
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
await $`mix deps.get && mix compile && mix elixir_ls.release2 -o release`
|
||||||
|
.quiet()
|
||||||
|
.cwd(path.join(Global.Path.bin, "elixir-ls-master"))
|
||||||
|
.env({ MIX_ENV: "prod", ...process.env })
|
||||||
|
|
||||||
|
log.info(`installed elixir-ls`, {
|
||||||
|
path: elixirLsPath,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
process: spawn(binary),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -489,10 +489,10 @@ export function replace(
|
||||||
BlockAnchorReplacer,
|
BlockAnchorReplacer,
|
||||||
WhitespaceNormalizedReplacer,
|
WhitespaceNormalizedReplacer,
|
||||||
IndentationFlexibleReplacer,
|
IndentationFlexibleReplacer,
|
||||||
EscapeNormalizedReplacer,
|
// EscapeNormalizedReplacer,
|
||||||
TrimmedBoundaryReplacer,
|
// TrimmedBoundaryReplacer,
|
||||||
ContextAwareReplacer,
|
// ContextAwareReplacer,
|
||||||
MultiOccurrenceReplacer,
|
// MultiOccurrenceReplacer,
|
||||||
]) {
|
]) {
|
||||||
for (const search of replacer(content, oldString)) {
|
for (const search of replacer(content, oldString)) {
|
||||||
const index = content.indexOf(search)
|
const index = content.indexOf(search)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue