@@ -4,6 +4,8 @@ import path from "path"
44import { Global } from "../global"
55import { Log } from "../util/log"
66import { BunProc } from "../bun"
7+ import { $ } from "bun"
8+ import fs from "fs/promises"
79
810export 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}
0 commit comments