Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'attempt to index a Boolean value' #290

Closed
Bridges369 opened this issue Jan 13, 2023 · 1 comment
Closed

'attempt to index a Boolean value' #290

Bridges369 opened this issue Jan 13, 2023 · 1 comment

Comments

@Bridges369
Copy link

Bridges369 commented Jan 13, 2023

I'm configuring the LSPs, following the tutorial and adapting it to my use. But the 'handlers.lua' file does not work as expected. It returns:
(it's in Portuguese and I know this is irrelevant)

Erro detectado ao processar C:\Users\55549.SAMSUNG-BOOK\AppData\Local\nvim\init.lua:
E5113: Error while calling lua chunk: C:\Users\55549.SAMSUNG-BOOK\AppData\Local\nvim\init.lua:10: attempt to index a boolean value
stack traceback:
        C:\Users\55549.SAMSUNG-BOOK\AppData\Local\nvim\init.lua:10: in main chunk

The default file init.lua is a symbolic link to ~/.dotfiles/.lua

content of .lua

package.path = os.getenv("USERPROFILE") .. "\\.dotfiles\\lua\\?.lua"

require "options"
require "keymaps"
require "packer"
require "colorscheme"
require "display"
require "spell"
-- {{ LSP }}
require "lsp.handlers".setup()
require "lsp.mason"
require "lsp.null-ls"
require "lsp-installer"
-- {{ PLUGINS }}
require "plugins.airline"
require "plugins.telescope"
require "plugins.treesitter"
require "plugins.cmp"

content of handlers.lua

local M = {}

-- TODO: backfill this to template
M.setup = function()
  local signs = {
    { name = "DiagnosticSignError", text = "" },
    { name = "DiagnosticSignWarn", text = "" },
    { name = "DiagnosticSignHint", text = "" },
    { name = "DiagnosticSignInfo", text = "" },
  }

  for _, sign in ipairs(signs) do
    vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
  end

  local config = {
    -- disable virtual text
    virtual_text = false,
    -- show signs
    signs = {
      active = signs,
    },
    update_in_insert = true,
    underline = true,
    severity_sort = true,
    float = {
      focusable = false,
      style = "minimal",
      border = "rounded",
      source = "always",
      header = "",
      prefix = "",
    },
  }

  vim.diagnostic.config(config)

  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
    border = "rounded",
  })

  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
    border = "rounded",
  })
end

local function lsp_highlight_document(client)
  -- Set autocommands conditional on server_capabilities
  if client.server_capabilities.documentHighlight then
    vim.api.nvim_exec(
      [[
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]],
      false
    )
  end
end

local function lsp_keymaps(bufnr)
  local opts = { noremap = true, silent = true }
  vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
  -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
  -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
  -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
  vim.api.nvim_buf_set_keymap(
    bufnr,
    "n",
    "gl",
    '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ border = "rounded" })<CR>',
    opts
  )
  vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
  vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
end

M.on_attach = function(client, bufnr)
  if client.name == "tsserver" then
    client.server_capabilities.documentFormattingProvider = false
  end
  lsp_keymaps(bufnr)
  lsp_highlight_document(client)
end

local capabilities = vim.lsp.protocol.make_client_capabilities()

local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not status_ok then
  return
end

M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities)

return M

Output of nvim --version

NVIM v0.8.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilado por runneradmin@fv-az28-353

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

    arquivo vimrc de sistema: "$VIM\sysinit.vim"
            padrão para $VIM: "C:/Program Files (x86)/nvim/share/nvim"

Run :checkhealth for more info

Output of command tre

(only relevant content)
.
├── lua
│   ├── colorscheme.lua
│   ├── display.lua
│   ├── keymaps.lua
│   ├── lsp.lua
│   ├── lsp
│   │   ├── handlers.lua
│   │   ├── lsp-installer.lua
│   │   ├── mason.lua
│   │   ├── null-ls.lua
│   │   └── settings
│   │       └── sumneko_lua.lua
│   ├── options.lua
│   ├── packer.lua
│   ├── plugins
│   │   ├── airline.lua
│   │   ├── autopairs.lua
│   │   ├── cmp.lua
│   │   ├── colorizer.lua
│   │   ├── telescope.lua
│   │   └── treesitter.lua
│   ├── snippets
│   │   ├── _.snippets
│   │   ├── lua.snippets
│   │   └── ruby.snippets
│   └── spell.lua
└── init.lua

@svfcode
Copy link

svfcode commented Mar 27, 2023

Had the same problem.. this fix helped me.

gnmearacaun added a commit that referenced this issue Mar 30, 2023
fixes issue #290 in branch 06-LSP. Cudos to [svfcode](#290 (comment)) for pointing to the fix. Closes pr #49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants