Closed purpleblackferret closed 1 year ago
Seems something with the LSP config. go cpp
I suspect the lsp is not running. what is result of :LspInfo
?
Also, you can setup lsp yourself to make sure it works in your scenario/project structure.
I do not use c++ in daily based. the default ccls setup
ccls = {
on_attach = on_attach,
init_options = {
compilationDatabaseDirectory = 'build',
root_dir = [[ util.root_pattern("compile_commands.json", "compile_flags.txt", "CMakeLists.txt", "Makefile", ".git") or util.path.dirname ]],
index = { threads = 2 },
clang = { excludeArgs = { '-frounding-math' } },
},
flags = { allow_incremental_sync = true },
},
You can override the settings.
@ray-x I dont think its issue with lsp lsp seems to be running as usual I ran :Lspinfo when navigator is disabled and when its enabled
I think it might be some issue with nvim-cmp or luasnip most probably could you check once ?
also, how can I override the settings ?
Is the issue happening because navigator is trying to use ccls but my lsp configuration is only done with clangd ?
I disabled ccls , but it still seems to be not working
In readme.md check the tsserver/gopls section You can either set lsp.enable = false to skip lsp setup and you can use your own setup (check https://github.com/ray-x/navigator.lua/#integrate-with-mason-williambomanmasonnvim), or put your own config in ccls or clangd to replace what navigator has:
{
lsp = {
enable = true, -- skip lsp setup, and only use treesitter in navigator.
tsserver = {
filetypes = {'typescript'} -- disable javascript etc,
-- set to {} to disable the lspclient for all filetypes
},
gopls = { -- gopls setting
on_attach = function(client, bufnr) -- on_attach for gopls
-- your special on attach here
-- e.g. disable gopls format because a known issue https://github.com/golang/go/issues/45732
print("i am a hook, I will disable document format")
client.resolved_capabilities.document_formatting = false
end,
settings = {
gopls = {gofumpt = false} -- disable gofumpt etc,
}
}
}
}
I disabled lsp completely and its still not working I think the issue is with luasnip I think enabling navigator is creating some issues with luasnip actually Could you check/do something about that ?
TBH, I am using luasnip, navigator and cmp on a daily basics. Also there is a sample config in the playground folder and you can try those out. playground/init_packer.lua
that init_packer.lua does not contain any config for c++ what should i change in it to make it work with c++
sorry to annoy , i am sorta beginner in these things
and is there any chance that using lsp with mason would make things work ?
or could you provide any config for c++ with cmp, luasnip and navigator which sorta works and doesnt have the quirk i have been facing ?
I do not think you will need additional setup. Either ccls or clangd should work out-of-the-box. Navigator has default config for both.
I have done setup with default settings/recommended settings with most of my plugins actually but still this quirk is going nowhere after enabling navigator
here is my init.lua
what can i do about it now ? i have clangd installed in my machine
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " "
require("lazy").setup({
{
"catppuccin/nvim", name = "catppuccin", priority = 1000,
config = function() require("catppuccin").setup({flavour = "frappe",}) end,
},
{
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require('lspconfig')
lspconfig.clangd.setup {}
end,
},
{
'ray-x/navigator.lua',
dependencies = {
{ 'ray-x/guihua.lua', build = 'cd lua/fzy && make' },
{ 'neovim/nvim-lspconfig' },
},
config = function()
require('navigator').setup({
})
end,
},
{
"L3MON4D3/LuaSnip",
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
opts = {
history = true,
delete_check_events = "TextChanged",
},
keys = {
{
"<tab>",
function()
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next" or "<tab>"
end,
expr = true, silent = true, mode = "i",
},
{ "<tab>", function() require("luasnip").jump(1) end, mode = "s" },
{ "<s-tab>", function() require("luasnip").jump(-1) end, mode = { "i", "s" } },
},
},
{
'hrsh7th/nvim-cmp',
dependencies = {
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
},
config = function ()
-- Add additional capabilities supported by nvim-cmp
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd'}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
end,
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "cpp", "lua", "vim", "vimdoc","javascript", "html","c","python" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
{
"nvim-treesitter/nvim-treesitter-textobjects",
dependencies = {
"nvim-treesitter/nvim-treesitter",
},
},
})
require("catppuccin").setup({flavour = "mocha",})
vim.cmd("autocmd FileType guihua lua require('cmp').setup.buffer { enabled = false }")
vim.cmd("autocmd FileType guihua_rust lua require('cmp').setup.buffer { enabled = false }")
vim.cmd.colorscheme "catppuccin"
vim.opt.clipboard = "unnamedplus"
vim.opt.autoread = true
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.mouse = "a"
vim.opt.smarttab = true
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.cindent = true
vim.opt.smartindent = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.autowrite = true
vim.opt.incsearch = true
vim.opt.backup = true
vim.opt.undofile = true
vim.opt.writebackup = true
vim.opt.undolevels = 1000000
vim.opt.backupdir = "~/.vim/backups//"
vim.opt.directory = "~/.vim/swapdir//"
vim.opt.undodir = "~/.vim/undodir//"
vim.opt.history = 9999
vim.opt.hlsearch = false
vim.keymap.set('i','jk','<esc>')
vim.keymap.set('n','<C-h>','<C-w>h')
vim.keymap.set('n','<C-j>','<C-w>j')
vim.keymap.set('n','<C-k>','<C-w>k')
vim.keymap.set('n','<C-l>','<C-w>l')
vim.keymap.set({'n','v','i','x'},'<F4>','<esc>:wa<CR>:qa<CR>')
I used your setup and ran tests under ubuntu with ccls
. It works fine for me
I no longer use c++ and clangd is too heavy for me to install and test. But I do not see anything wrong with ccls.
Also I pushed a update to playground/init.lua so it supports cmp
as well
https://github.com/ray-x/navigator.lua/blob/master/playground/init.lua
navigator.lua/playground/cpp❯ nvim -u ../init.lua main.cpp
works fine for me:
The issue is not that autocompletion is not working , autocompletion is working. Here is the issue. When navigator is disabled - and when navigator is enabled - it does not write the template part and this things keeps happening even with minimum config with nvim cmp and with both clangd and ccls
everything else works fine, just this thing keeps happening when navigator is enabled, i have tested with many other plugins , i think navigator is the reason why it might be happening
can we do anything about this ?
I tested with the init.lua you posted in the commit, i think it has the same issue actually
Would you try latest the version? It should be fixed for cpp with ccls. I did not try clangd.
Yeah it is now working with latest version. Clangd is working too.
Thanks you very much. That was a big help.
I am using lazy.nvim this is my plugins.nvim file https://pastebin.com/kLG0wtaw
whenever i enable navigator.lua the autocompletion(I use nvim-cmp btw) behaves abnormally , the complete snippet doesnt get printed
when navigator is disabled , in the following scenario after pressing enter it would print the complete template like this
but when i enable navigator, pressing enter on the same scenario would print only the word 'map' kinda like this
what can i do about it now
i have disabled guihua with autocmd as mentioned here, but that does not make any difference Help me out please