LanguageServer.jl
LanguageServer.jl copied to clipboard
Scratch.jl for symserver_store_path
So I recently heard about Scratch.jl, which provides a mutable data store for packages. I thought it would be interesting for LanguageServer.jl/SymbolServer.jl to make use of it for symserver_store_path, possibly as a default? I know with julia-vscode you want to take advantage of VSCode's syncable extension storage, but as someone who regularly hops between neovim and VSCode this would make sharing the SymbolServer.jl cache easier.
It's nice enhancement for sure, but comes at the cost of having to maintain two code paths because we can't really drop support for Julia versions < 1.5.
And also, I am keen to keep the cache that VS Code uses "private" and not shared with anything else, it helps us greatly with stability.
Valid arguments all around! For those not using VS Code I threw together a script that I've been using with NeoVim that might be useful to others. If you'd like I could make a PR.
As for the separate code paths, you could swap out the scratchspace store for something like "~/.cache/julia-lsp/store-$(ver)" for Julia < 1.5 (at least on Linux). But yeah, it's more work. The VS Code extension is awesome and I'd like to extend that beyond VS Code where possible. The NeoVim LSP is getting quite good.
Here it is:
#!/usr/bin/env bash
#=
JULIA_PROJECT="$(dirname "${BASH_SOURCE[0]}")"
JULIA_LOAD_PATH=":${JULIA_LOAD_PATH:+:${JULIA_LOAD_PATH}}"
JULIA_DEPOT_PATH="${JULIA_DEPOT_PATH:+${JULIA_DEPOT_PATH}:}:"
export JULIA_PROJECT
export JULIA_LOAD_PATH
export JULIA_DEPOT_PATH
JULIA="julia --color=yes --history-file=no --startup-file=no -O1 --compile=min"
CMD="${JULIA} ${BASH_SOURCE[0]}"
exec $CMD "$@"
=#
using Pkg
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
Pkg.instantiate()
using ArgParse
using Scratch
using LanguageServer
using SymbolServer
if VERSION < v"1.5"
error("NeoVim Julia language server only works with julia 1.5+")
end
function default_store_path()
ver = Pkg.dependencies()[Base.UUID("cf896787-08d5-524d-9de7-132aaa0cb996")].version
suffix = ver.major == 0 ? "0.$(ver.minor)" : "$(ver.major)"
return "store-$suffix"
end
s = ArgParseSettings()
@add_arg_table s begin
"env"
required = false
default = dirname(something(Base.current_project(pwd()), Base.active_project()))
"--depot"
arg_type = String
default = first(DEPOT_PATH)
"--symserver_store_path"
arg_type = String
default = get_scratch!(SymbolServer, default_store_path())
"--debug"
help = "Enable verbose output"
action = :store_true
end
args = parse_args(ARGS, s)
@info "ARGS" args
if args["debug"]
ENV["JULIA_DEBUG"] = "all"
end
store = args["symserver_store_path"]
isfile(store) && error("Store path is a file: $store")
mkpath(store)
server = LanguageServerInstance(
stdin,
stdout,
args["env"],
args["depot"],
nothing, # TODO error handler
store,
)
@info "Starting the Julia Language Server"
run(server)