Coder Social home page Coder Social logo

Comments (10)

fishBone000 avatar fishBone000 commented on July 23, 2024 1

Yes, the first solution works. The override function will be scheduled in the main event-loop, and the loop is after NvChad's on_attach func call, if I understood correctly.
The second one works as well, in lspconfig.lua I setup lua_ls again, providing your attach func.

Hey but though they both work, this isn't intuitive at all. To override NvChad's key map, I have to use schedule which I have never seen before. I can imagine people who encounter problems like mine will have to find this issue to get the answer. Or override on_attach func calls. Plus overriding lua_ls's on_attach means that I need to set up lua_ls again, like:

lspconfig.lua_ls.setup {
  on_attach = on_attach, -- Override on_attach
  ...
}

And this will override NvChad's default lua_ls settings as wel, especially the library imports. So I have to copy NvChad's lua_ls.setup{ ... } to get them work again.

Compared to v2.5, in v2.0 I didn't need to solve this problem at all, 'cause v2.0 didn't set up the key maps in on_attach.
Is it possible to make a change in the future?

from nvchad.

siduck avatar siduck commented on July 23, 2024

please add mappings which are set on_attach to lspattach event, make an autocmd

from nvchad.

fishBone000 avatar fishBone000 commented on July 23, 2024

Thanks for reply, but it's not making effect.
In my mappings.lua:

local map = vim.keymap.set
local nomap = vim.keymap.del
local autocmd = vim.api.nvim_create_autocmd

autocmd("LspAttach", {
  callback = function()
    -- Override keymaps provided by NvChad
    nomap("n", "gd")
    nomap("n", "gr")
    nomap("n", "gi")
    map("n", "gd", "<cmd> Telescope lsp_definitions <CR>", { desc = "LSP defininitions"})
    map("n", "gr", "<cmd> Telescope lsp_references <CR>", { desc = "LSP references"})
    map("n", "gi", "<cmd> Telescope lsp_implementations <CR>", { desc = "LSP implementations"})
  end
})

In :Telescope keymap, I can still see two "gd" entries are set, and using the "gd" key combination still pops up the QuickFix list.

from nvchad.

siduck avatar siduck commented on July 23, 2024

@fishBone000 that isnt enough, u should add the {bufnr} opt! like we did for lsp

from nvchad.

fishBone000 avatar fishBone000 commented on July 23, 2024

It's still not working...

autocmd("LspAttach", {
  callback = function(args)
    -- Override keymaps provided by NvChad

    -- Commented out because Nvim warns about "no such key map"
    -- Is this autocmd really taking precedence over NvChad's on_attach func?
    -- nomap("n", "gd", { buffer = args.buf })
    -- nomap("n", "gr", { buffer = args.buf })
    -- nomap("n", "gi", { buffer = args.buf })
    map("n", "gd", "<cmd> Telescope lsp_definitions <CR>", { buffer = args.buf, desc = "LSP defininitions"})
    map("n", "gr", "<cmd> Telescope lsp_references <CR>", { buffer = args.buf, desc = "LSP references"})
    map("n", "gi", "<cmd> Telescope lsp_implementations <CR>", { buffer = args.buf, desc = "LSP implementations"})
  end
})

from nvchad.

siduck avatar siduck commented on July 23, 2024

hmmm ig there's some race condition , this should work

autocmd("LspAttach", {
  callback = function(args)
    vim.schedule(function()
      write here
    end)
  end,
})

or make custom onattach which loads our first and yours, in order

local function attach(client, bufnr)
  on_attach(client, bufnr)
  map("n", "gd", "<cmd> Telescope lsp_implementations <CR>", { buffer = bufnr, desc = "bruh" })
end

from nvchad.

siduck avatar siduck commented on July 23, 2024

@fishBone000 you only override via autocmd cuz those are "LSP" related mappings and are attached to the buffer on lspattach, i dont think why do you expect your mapping code to work on startup without putting it in lspattach.

I wanted to keep things simple + no abstraction, you are free to not use out onattach and just declare your mappings.

you can completely opt out of our default lspconfig too, just remove it from the config function of your lspconfig spec

from nvchad.

fishBone000 avatar fishBone000 commented on July 23, 2024

I know why my code didn't work earlier and I can modify my code to not use the NvChad default config, as you have shown me earlier.
It's just that, for a simple functional change as adding a new key map, in our case here I need to something big like reading NvChad's code to find out why my code is overridden. I expect one to approach sth small by doing small things, and approach sth big by doing big things, not approach small things by doing big things. Not that I want to say reading NvChad code and modifying one's own code is a big stuff, nor do I feel too lazy to do that, it's just not matched to sth small as adding a new key map. It's more like a UX stuff. Imagine if u r working on a proj, and suddenly want to add a key map to make things faster, and: oops, it just doesn't work, and you need to check NvChad's code for why.

from nvchad.

siduck avatar siduck commented on July 23, 2024

that isnt a downside, making a new abstracted syntax for this would confuse more :/

i'll just mention in the mappings page before hand that the lsp mappings must be overriden onattach.

from nvchad.

fishBone000 avatar fishBone000 commented on July 23, 2024

Nah, ain't saying you should add abstraction, just I think some measures to improve this should be taken, from my aspect of view.

i'll just mention in the mappings page before hand that the lsp mappings must be overriden onattach.

Yes, I think users will know this overriding stuff in this way and won't scratch their head like me.
Thanks for your help!

from nvchad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.