neovim | nvchad not suggesting packages methods

506 Views Asked by At

I'm trying to switch to neovim from vscode, after following a tutorial on nvchad and installing it, I setup the lsp configuration for both golang and javascript, the problem I'm having is that there is absolutely no auto-complete for any package, just the language snippets are working, such as function, var and the current buffer words, but if I for example import "strings" in golang and write the keyword strings. I don't get any autocomplete, same thing in javascript, tried importing fs and got no suggestions for that one as well.

here's my custom lspconfig.lua

local config = require("plugins.configs.lspconfig")
local on_attach = config.on_attach
-- local capabilities = config.capabilities

local lspconfig = require("lspconfig")
local util = require "lspconfig/util"

local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities()

lspconfig.gopls.setup = {
  on_attach = on_attach,
  capabilities = cmp_capabilities,
  cmd = {"gopls"},
  filetypes = { "go", "gomod", "gowork", "gotmpl" },
  root_dir = util.root_pattern("go.work", "go.mod", ".git"),
  settings = {
    gopls = {
      staticcheck = true,
      gofumpt = true,
      usePlaceholders = true,
      analyses = {
        unusedparam = true,
        fieldalignment = true,
      }
    }
  }
}

lspconfig.tsserver.setup = {
  on_attach = on_attach,
  capabilities = cmp_capabilities,
  init_options = {
    preferences = {
      disableSuggestions = true,
    }
  }
}

here's my plugins.lua

local plugins = {
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "lua-language-server",
        "gopls",
        "typescript-language-server",
        "prettier",
      },
    },
  },
  {
    "neovim/nvim-lspconfig",
    config = function()
      require "plugins.configs.lspconfig"
      require "custom.configs.lspconfig"
    end,
  },
}

and finally, here's an example of my problem

I tried installing nvim-cmp and friendly-snippets after following a couple of tutorials, turned out they are already installed, I don't have any experience in lsp and cmp packages, because as a vscode user, all I did was installing packages

1

There are 1 best solutions below

1
On

have you added your preferred (and installed) LSP in cmp.lua? i just recently config LSP for Golang and i was confused as to why it didn't work despite i have installed gopls both locally and via Mason. hope this helps.

sninppet screenshot