puppetlabs / puppet-editor-services

Puppet Language Server for editors
Apache License 2.0
46 stars 21 forks source link

Autocompletion not working (nvim) #351

Closed dadav closed 11 months ago

dadav commented 11 months ago

Describe the Bug

Autocompletions for basic resources like package or service are not working, while module specific autocompletions are working.

Not working:

package

Working (with --puppet-settings=--modulepath,/tmp/puppetlabs-haproxy set):

haproxy

Expected Behavior

Get autocompletions/hover functionality for resources.

Steps to Reproduce

Create this 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 = "puppet"
local cmd = {
    "puppet-languageserver",
    "--stdio",
    "--puppet-settings=--modulepath,/tmp/puppetlabs-haproxy",
} -- needed for elixirls, lua_ls, omnisharp
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.]]
)

Clone any puppet module repo and open the init.pp:

git clone git@github.com:puppetlabs/puppetlabs-haproxy.git
nvim -u minimal_init.lua puppetlabs-haproxy/manifests/init.pp

Environment

dadav commented 11 months ago

Relevant log msg:

E, [2023-10-12T08:45:33.061715 #15746] ERROR -- : (textDocument/hover) package is not a valid puppet type
dadav commented 11 months ago

Fixed, basically I downgraded from ruby 3 to 2.7..like in #285