LanguageServer.jl icon indicating copy to clipboard operation
LanguageServer.jl copied to clipboard

Scratch.jl for symserver_store_path

Open colinxs opened this issue 3 years ago • 3 comments

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.

colinxs avatar Apr 11 '21 18:04 colinxs

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.

pfitzseb avatar Apr 12 '21 07:04 pfitzseb

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.

davidanthoff avatar May 05 '21 21:05 davidanthoff

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)

colinxs avatar May 18 '21 11:05 colinxs