rust-analyzer/test-neovim-lsp: format

+69 -56
+69 -56
pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix
··· 1 - { runCommand, cargo, neovim, rust-analyzer, rustc }: 2 - runCommand "test-neovim-rust-analyzer" { 3 - nativeBuildInputs = [ cargo neovim rust-analyzer rustc ]; 1 + { 2 + runCommand, 3 + cargo, 4 + neovim, 5 + rust-analyzer, 6 + rustc, 7 + }: 8 + runCommand "test-neovim-rust-analyzer" 9 + { 10 + nativeBuildInputs = [ 11 + cargo 12 + neovim 13 + rust-analyzer 14 + rustc 15 + ]; 4 16 5 - testRustSrc = /* rust */ '' 6 - fn main() { 7 - let mut var = vec![None]; 8 - var.push(Some("hello".to_owned())); 9 - } 10 - ''; 17 + testRustSrc = '' 18 + fn main() { 19 + let mut var = vec![None]; 20 + var.push(Some("hello".to_owned())); 21 + } 22 + ''; 11 23 12 - # NB. Wait for server done type calculations before sending `hover` request, 13 - # otherwise it would return `{unknown}`. 14 - # Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status 15 - nvimConfig = /* lua */ '' 16 - local caps = vim.lsp.protocol.make_client_capabilities() 17 - caps["experimental"] = { serverStatusNotification = true } 18 - vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({ 19 - cmd = { "rust-analyzer" }, 20 - capabilities = caps, 21 - handlers = { 22 - ["experimental/serverStatus"] = function(_, msg, ctx) 23 - if msg.health == "ok" then 24 - if msg.quiescent then 25 - vim.cmd("goto 23") -- let mut |var =... 26 - vim.lsp.buf.hover() 24 + # NB. Wait for server done type calculations before sending `hover` request, 25 + # otherwise it would return `{unknown}`. 26 + # Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status 27 + nvimConfig = '' 28 + local caps = vim.lsp.protocol.make_client_capabilities() 29 + caps["experimental"] = { serverStatusNotification = true } 30 + vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({ 31 + cmd = { "rust-analyzer" }, 32 + capabilities = caps, 33 + handlers = { 34 + ["experimental/serverStatus"] = function(_, msg, ctx) 35 + if msg.health == "ok" then 36 + if msg.quiescent then 37 + vim.cmd("goto 23") -- let mut |var =... 38 + vim.lsp.buf.hover() 39 + end 40 + else 41 + print("error: server status is not ok: ") 42 + vim.cmd("q") 43 + end 44 + end, 45 + ["textDocument/hover"] = function(_, msg, ctx) 46 + if msg then 47 + -- Keep newlines. 48 + io.write(msg.contents.value) 49 + vim.cmd("q") 27 50 end 28 - else 29 - print("error: server status is not ok: ") 30 - vim.cmd("q") 31 - end 32 - end, 33 - ["textDocument/hover"] = function(_, msg, ctx) 34 - if msg then 35 - -- Keep newlines. 36 - io.write(msg.contents.value) 37 - vim.cmd("q") 38 - end 39 - end, 40 - }, 41 - on_error = function(code) 42 - print("error: " .. code) 43 - vim.cmd("q") 44 - end 45 - })) 46 - ''; 51 + end, 52 + }, 53 + on_error = function(code) 54 + print("error: " .. code) 55 + vim.cmd("q") 56 + end 57 + })) 58 + ''; 47 59 48 - } '' 49 - # neovim requires a writable HOME. 50 - export HOME="$(pwd)" 60 + } 61 + '' 62 + # neovim requires a writable HOME. 63 + export HOME="$(pwd)" 51 64 52 - cargo new --bin test-rust-analyzer 53 - cd test-rust-analyzer 54 - cat <<<"$testRustSrc" >src/main.rs 55 - cat <<<"$nvimConfig" >script.lua 65 + cargo new --bin test-rust-analyzer 66 + cd test-rust-analyzer 67 + cat <<<"$testRustSrc" >src/main.rs 68 + cat <<<"$nvimConfig" >script.lua 56 69 57 - # `-u` doesn't work 58 - result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)" 59 - echo "$result" 60 - [[ "$result" == *"var: Vec<Option<String>>"* ]] 61 - touch $out 62 - '' 70 + # `-u` doesn't work 71 + result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)" 72 + echo "$result" 73 + [[ "$result" == *"var: Vec<Option<String>>"* ]] 74 + touch $out 75 + ''