Git Product home page Git Product logo

Comments (9)

ifonajs avatar ifonajs commented on June 8, 2024

Found the root cause of my problems. I was installing extras with a file defined in ~/.config/nvim/lua/plugins/extras.lua. When I moved importing to ~/.config/nvim/lua/config/lazy.lua, now I'm able to change configuration of nvim-dap.

This is not super user friendly as I followed the example where plugin modules are imported in plugins/ folder. To reproduce:

~/.config/nvim/lua/plugins/extras.lua

return {
    { import = "lazyvim.plugins.extras.lang.clangd" },
}

(this configuration change doesn't get applied)
~/.config/nvim/lua/plugins/clangd-extra.lua

return {
  {
    "mfussenegger/nvim-dap",
    opts = function()
      local dap = require("dap")
      dap.adapters["cppdbg"] = {
        id = "cppdbg",
        type = "executable",
        command = "/usr/bin/vscode-cpptools/OpenDebugAD7",
      }
      for _, lang in ipairs({ "c", "cpp" }) do
        dap.configurations[lang] = {
          {
            type = "cppdbg",
            request = "launch",
            name = "Launch file",
            program = function()
              return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
            end,
            cwd = "${workspaceFolder}",
          },
          {
            name = "Attach to gdbserver :1234",
            type = "cppdbg",
            request = "launch",
            MIMode = "gdb",
            miDebuggerServerAddress = "localhost:1234",
            miDebuggerPath = "/usr/bin/gdb",
            cwd = "${workspaceFolder}",
            program = function()
              return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
            end,
          },
        }
      end
    end,
  },
}

from lazyvim.

dpetka2001 avatar dpetka2001 commented on June 8, 2024

It mentions it in the docs for each extra that it should be imported either via :LazyExtras or /lua/config/lazy.lua manually.

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.
Alternatively, you can add it to your lazy.nvim imports

-- lua/config/lazy.lua
require("lazy").setup({
  spec = {
    { "LazyVim/LazyVim", import = "lazyvim.plugins" },
    { import = "lazyvim.plugins.extras.lang.clangd" },
    { import = "plugins" },
  },
})

Could you kindly close the issue if your problem is resolved?

from lazyvim.

ifonajs avatar ifonajs commented on June 8, 2024

The example.lua suggests otherwise and it seems it only doesn't work if opts is a function() (which is also not something you should assign to opts according to documentation). If you think this is a user error, I will close the issue.

from lazyvim.

dpetka2001 avatar dpetka2001 commented on June 8, 2024

What do you mean the example.lua suggests otherwise? I specifically quoted what is mentioned in the clangd docs itself, where it mentions how you can enable this Extra. Where did you see that opts can't be a function? It can be a function that returns a table. From lazy.nvim docs

opts should be a table (will be merged with parent specs), return a table (replaces parent specs) or should change a table.

The only difference here is that the table is created and then can be modified via the required dap module, because that's how the nvim-dap plugin works.

from lazyvim.

ifonajs avatar ifonajs commented on June 8, 2024

https://www.lazyvim.org/configuration/examples has examples of importing extras in plugins/ directory. I also wanted to have it in plugin/ folder to have all of my modifications in one place but it's not a big deal.

Where did you see that opts can't be a function?

More precisely, function that doesn't take arguments and doesn't return anything. But DAP is a special in this case as you described. From the same lazy.nvim docs I could also assume function() is not supported at all:

opts | table or fun(LazyPlugin, opts:table)

From my point of view, the fact that importing extras somewhere in plugins/ folder works in 50% of the cases (when opts is a table or configured with function(_, opts)), means there's area for improvement. Things should work in all cases or shouldn't work at all.

from lazyvim.

dpetka2001 avatar dpetka2001 commented on June 8, 2024

The difference that you notice when you import the Extras in your /lua/plugins/ folder is because lazy.nvim parses files in alphabetical order. In your previous example you had the import in /lua/plugins/extras.lua, but you had your custom spec of nvim-dap in /lua/plugins/clangd-extra.lua. So, the clangd-extra.lua will get parsed first by lazy and then the extras.lua file. In this case the latter overrides the former. You can check that with the following config

  {
    "mfussenegger/nvim-dap",
    opts = function()
      local dap = require("dap")
      dap.configurations.c[1].name = "test"
    end,
  },
  { import = "lazyvim.plugins.extras.lang.clangd" },

It won't be like you want it to. Now if you put it like

  { import = "lazyvim.plugins.extras.lang.clangd" },
  {
    "mfussenegger/nvim-dap",
    opts = function()
      local dap = require("dap")
      dap.configurations.c[1].name = "test"
    end,
  },

It will work as expected. This is why in the Extras documentation it says to put the import in your /lua/config/lazy.lua, because that file and everything in it will get parsed before the files in /lua/plugins/ directory.

The safest way is to enable the Extras you want via the command LazyExtras, because that takes into consideration the correct ordering of parsing the Extras files.

Anyway, this is not a LazyVim bug. If you'd like you could make a PR in the docs repo or create an issue with enhancement label to clarify this in the LazyVim website.

from lazyvim.

ifonajs avatar ifonajs commented on June 8, 2024

What do you think about commenting out this or putting a warning in the comments not to include Extras like that? This is what lead me to the wrong assumptions in the first place.

from lazyvim.

dpetka2001 avatar dpetka2001 commented on June 8, 2024

Yes, I'm in favor of this because it seems to mislead new users. But I'm just a user like you with no access to this project. That's why I suggested for you to create an issue with enhancement label or create a PR yourself in the docs repo that I linked above that comments out or even deletes the current section that you're referring to.

from lazyvim.

dpetka2001 avatar dpetka2001 commented on June 8, 2024

@ifonajs Did you reopen this issue by mistake or is there any particular problem you keep having?

from lazyvim.

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.