Skip to content

Commit

Permalink
Merge pull request neovim#547 from mjlbach/update_julia_documentation
Browse files Browse the repository at this point in the history
Update julia cmd and documentation
  • Loading branch information
mjlbach authored Jan 7, 2021
2 parents beb1170 + cf8a9c4 commit f913316
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 26 deletions.
45 changes: 40 additions & 5 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1833,14 +1833,49 @@ require'lspconfig'.jsonls.setup{}
## julials

https://github.com/julia-vscode/julia-vscode

`LanguageServer.jl` can be installed with `julia` and `Pkg`:
```sh
julia --project=julials -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'
julia -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'
```
The default config lazily evaluates the location of the julia language server from the your global julia packages.
This adds a small overhead on first opening of a julia file. To avoid this overhead, replace server_path in on_new_config with
a hard-coded path to the server.

```lua
require'lspconfig'.julials.setup{
on_new_config = function(new_config,new_root_dir)
server_path = "/path/to/directory/containing/LanguageServer.jl/src"
cmd = {
"julia",
"--project="..server_path,
"--startup-file=no",
"--history-file=no",
"-e", [[
using Pkg;
Pkg.instantiate()
using LanguageServer; using SymbolServer;
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
# Make sure that we only load packages from this environment specifically.
@info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
\]\]
};
new_config.cmd = cmd
end
}
```
If you want to install the LanguageServer manually, you will have to ensure that the Julia environment is stored in this location:
```vim
:lua print(require'lspconfig'.util.path.join(require'lspconfig'.util.base_install_dir, "julials"))
You can find the path to the globally installed LanguageServer.jl package with the following command:
```bash
julia -e 'print(Base.find_package("LanguageServer"))'
```
Note: the directory passed to `--project=...` should terminate with src, not LanguageServer.jl.
This server accepts configuration via the `settings` key.
<details><summary>Available settings:</summary>
Expand Down Expand Up @@ -2077,8 +2112,8 @@ require'lspconfig'.julials.setup{}
Commands:
Default Values:
cmd = { "julia", "--project=julials", "--startup-file=no", "--history-file=no", "-e", ' using Pkg;\n Pkg.instantiate()\n using LanguageServer; using SymbolServer;\n depot_path = get(ENV, "JULIA_DEPOT_PATH", "")\n project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))\n # Make sure that we only load packages from this environment specifically.\n empty!(LOAD_PATH)\n push!(LOAD_PATH, "@")\n @info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path\n server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);\n server.runlinter = true;\n run(server);\n ' }
filetypes = { "julia" }
on_new_config = <function 1>
root_dir = <function 1>
```
Expand Down
81 changes: 60 additions & 21 deletions lua/lspconfig/julials.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,82 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'

local environment_directory = util.path.join(util.base_install_dir, "julials")

configs.julials = {
default_config = {
cmd = {
"julia", "--project=" .. environment_directory, "--startup-file=no", "--history-file=no", "-e", [[
using Pkg;
Pkg.instantiate()
using LanguageServer; using SymbolServer;
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
# Make sure that we only load packages from this environment specifically.
empty!(LOAD_PATH)
push!(LOAD_PATH, "@")
@info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
on_new_config = function(new_config,new_root_dir)
local server_path = vim.fn.system("julia -e 'print(Base.find_package(\"LanguageServer\"))'")
local cmd = {
"julia",
"--project="..server_path:sub(0,-19),
"--startup-file=no",
"--history-file=no",
"-e", [[
using Pkg;
Pkg.instantiate()
using LanguageServer; using SymbolServer;
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
# Make sure that we only load packages from this environment specifically.
@info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
]]
};
new_config.cmd = cmd
end,
filetypes = {'julia'};
root_dir = function(fname)
return util.find_git_ancestor(fname) or vim.loop.os_homedir()
return util.find_git_ancestor(fname) or vim.fn.getcwd()
end;
};
docs = {
package_json = "https://raw.githubusercontent.com/julia-vscode/julia-vscode/master/package.json";
description = [[
https://github.com/julia-vscode/julia-vscode
`LanguageServer.jl` can be installed with `julia` and `Pkg`:
```sh
julia --project=]] .. environment_directory .. [[ -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'
julia -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'
```
If you want to install the LanguageServer manually, you will have to ensure that the Julia environment is stored in this location:
```vim
:lua print(require'lspconfig'.util.path.join(require'lspconfig'.util.base_install_dir, "julials"))
The default config lazily evaluates the location of the julia language server from the your global julia packages.
This adds a small overhead on first opening of a julia file. To avoid this overhead, replace server_path in on_new_config with
a hard-coded path to the server.
```lua
require'lspconfig'.julials.setup{
on_new_config = function(new_config,new_root_dir)
server_path = "/path/to/directory/containing/LanguageServer.jl/src"
cmd = {
"julia",
"--project="..server_path,
"--startup-file=no",
"--history-file=no",
"-e", [[
using Pkg;
Pkg.instantiate()
using LanguageServer; using SymbolServer;
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = dirname(something(Base.current_project(pwd()), Base.load_path_expand(LOAD_PATH[2])))
# Make sure that we only load packages from this environment specifically.
@info "Running language server" env=Base.load_path()[1] pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
\]\]
};
new_config.cmd = cmd
end
}
```
You can find the path to the globally installed LanguageServer.jl package with the following command:
```bash
julia -e 'print(Base.find_package("LanguageServer"))'
```
Note: the directory passed to `--project=...` should terminate with src, not LanguageServer.jl.
]];
};
}
Expand Down

0 comments on commit f913316

Please sign in to comment.