run.jl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Load LanguageServer from the project next to this file
  2. ## Save old load path
  3. old_load_path = copy(LOAD_PATH)
  4. push!(empty!(LOAD_PATH), @__DIR__)
  5. ## Load packages
  6. using LanguageServer, SymbolServer
  7. ## Restore old load path
  8. append!(empty!(LOAD_PATH), old_load_path)
  9. # Figure out the active project
  10. ## This configuration is a good default
  11. project_path = let
  12. dirname(something(
  13. ## 1. Finds an explicitly set project (JULIA_PROJECT)
  14. Base.load_path_expand((
  15. p = get(ENV, "JULIA_PROJECT", nothing);
  16. p === nothing ? nothing : isempty(p) ? nothing : p
  17. )),
  18. ## 2. Look for a Project.toml file in the current working directory,
  19. ## or parent directories, with $HOME as an upper boundary
  20. Base.current_project(),
  21. ## 3. First entry in the load path
  22. get(Base.load_path(), 1, nothing),
  23. ## 4. Fallback to default global environment,
  24. ## this is more or less unreachable
  25. Base.load_path_expand("@v#.#"),
  26. ))
  27. end
  28. # Depot path for the server to index (empty uses default).
  29. depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
  30. # Start the server
  31. @info "Running julia language server" VERSION project_path depot_path
  32. server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path)
  33. server.runlinter = true
  34. run(server)