neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.74k stars 2.08k forks source link

jsonnet_ls client doesn't attach to buffer #2420

Open rlankfo opened 1 year ago

rlankfo commented 1 year ago

Description

the jsonnet_ls client doesn't attach to a buffer when opening jsonnet files

Neovim version

NVIM v0.7.2 Build type: Release LuaJIT 2.1.0-beta3 Compiled by brew@Monterey

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/local/Cellar/neovim/0.7.2_1/share/nvim"

Run :checkhealth for more info

Nvim-lspconfig version

47a521e621570da77e25c31988e2b74412db25e4

Operating system and version

macOS 12.3.1

Affected language servers

jsonnet_ls

Steps to reproduce

install jsonnet language server

go install github.com/grafana/jsonnet-language-server@latest

create a jsonnet file

echo '{}' > f.jsonnet nvim -nu minimal_init.lua f.jsonnet

Actual behavior

:LspInfo reports that there are 0 clients attached to the buffer

Expected behavior

:LspInfo shows the jsonnet_ls client attached to the buffer when opening a jsonnet file (and it works)

Minimal config

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'jsonnet_ls'
local cmd = { 'jsonnet-language-server', '-t' } -- needed for elixirls, omnisharp, sumneko_lua
if not name then
  print 'You have not defined a server name, please edit minimal_init.lua'
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
  print [[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]]
end

nvim_lsp[name].setup {
  cmd = cmd,
  on_attach = on_attach,
}

print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]

LSP log

https://gist.github.com/rlankfo/6ab306bb77692e579e9a509b9bc8eb8f

folliehiyuki commented 1 year ago

https://github.com/neovim/nvim-lspconfig/blob/bfdf2e91e7297a54bcc09d3e092a12bff69a1cf4/lua/lspconfig/server_configurations/jsonnet_ls.lua#L17

The server only starts when you are inside a git repo, or there is a jsonnetfile.json in the current directory (when you're using jsonnet-bundler).