nvf icon indicating copy to clipboard operation
nvf copied to clipboard

Path error after updating flake.lock

Open ecribia opened this issue 7 months ago • 11 comments

⚠️ Please verify that this bug has NOT been reported before.

  • [x] I checked all existing issues and didn't find a similar issue

Description

After updating my flake.lock, my configuration have issues dealing with paths. For example the telescope explorer can't create new files/directories and gives the error message:

[file_browser.to_absolute_path] Given path ':%:p:h' doesn't exist

And nvim-cmp/blink-cmp doesn't autocomplete paths anymore. If i revert to the old lock file, i dont have these issues. My previous lock file is from March 12th

👟 Reproduction steps

use telescope file explorer or nvim-cmp path autocompletion

👀 Expected behavior

Be able to get autocompletion on paths, and create files/folders with the explorer

😓 Actual Behavior

Either getting error message, or no completion.

💻 Metadata

  • system: "x86_64-linux" - host os: Linux 6.14.2, NixOS, 24.11 (Vicuna), 24.11.20250412.26d499f - multi-user?: yes - sandbox: yes - version: nix-env (Nix) 2.24.14 - nixpkgs: /nix/store/hzaj4d6ari2wq2cbg1j60n9zw42gnshy-source

📝 Relevant log output

-

ecribia avatar Apr 18 '25 20:04 ecribia

Sorry, I cannot reproduce either of those issues. Would you be able to prepare a minimal reproducable example so that I can try and fix it*

NotAShelf avatar Apr 20 '25 15:04 NotAShelf

Thanks for the response! Ive cut down alot on my config here, but let certain parts related to telescope and language stay there. https://github.com/Nocxium/minimal-nvf

About telescope file picker: I can create files there now, but i still get the error message first. And the biggest problem I have is the autocomplete on paths not working.

Edit: Typo. I meant "not working", and not "now working"

ecribia avatar Apr 20 '25 19:04 ecribia

Just bumping my post here, since my typo earlier might have suggested that my problem was solved, which it unfortunately isn't. Would really appreciate if you could take a look at the above repo whenever you have the time 😄

ecribia avatar Apr 22 '25 13:04 ecribia

I did not forget about this issue. Definitely meaning to take a look, but I'm simply swamped at work.

Tomorrow is my day off, if I get to finish my work today I'll be taking a closer look to this and some other issues that have been on my backlog. Thank you for the reproducer, it'll make my life easier.

NotAShelf avatar Apr 22 '25 13:04 NotAShelf

Okay I'm finally on my system and found the time to test. Two things I've noticed are:

  1. path is already in blink-cmp by default sources. Unless they're overriden, you should be seeing those in completion. I'm not actually sure why this is not working. My guess is this is a plugin conflict, I'll investigate.

  2. file_browser.path appears to be expecting a function. You're passing it a string. Something like

path = lib.generators.mkLuaInline ''
	function()
    	return ":%:p:h"
    end
'';

seems to avoid the error.

NotAShelf avatar Apr 23 '25 12:04 NotAShelf

Thanks alot for the help and your time :) Although Im pretty sure file_browser.path expects a string? Did the above solution work for you?

Error executing Lua callback: ...im-pack-dir/pack/mnw/start/lz-n/lua/lz/n/handler/cmd.lua:81: Vim:Error executing Lua callback: Vim:E729: Using a Funcref as a String
stack traceback:
        [C]: in function 'expand'
        ...er.nvim/lua/telescope/_extensions/file_browser/utils.lua:229: in function 'to_absolute_path'
        ...r.nvim/lua/telescope/_extensions/file_browser/picker.lua:151: in function 'fb_picker'
        ...-browser.nvim/lua/telescope/_extensions/file_browser.lua:101: in function <...-browser.nvim/lua/telescope/_extensions/file_browser.lua:70>
        ...ack-dir/pack/mnw/opt/telescope/lua/telescope/command.lua:199: in function 'run_command'
        ...ack-dir/pack/mnw/opt/telescope/lua/telescope/command.lua:259: in function 'load_command'
        ...02cd1da3dc78c7d2f20f2ef3ed3cdf0e6e4/plugin/telescope.lua:108: in function <...02cd1da3dc78c7d2f20f2ef3ed3cdf0e6e4/plugin/telescope.lua:107>
        [C]: in function 'cmd'
        ...im-pack-dir/pack/mnw/start/lz-n/lua/lz/n/handler/cmd.lua:81: in function <...im-pack-dir/pack/mnw/start/lz-n/lua/lz/n/handler/cmd.lua:43>
stack traceback:
        [C]: in function 'cmd'
        ...im-pack-dir/pack/mnw/start/lz-n/lua/lz/n/handler/cmd.lua:81: in function <...im-pack-dir/pack/mnw/start/lz-n/lua/lz/n/handler/cmd.lua:43>

The error message also seem to suggest its expecting a string, if im not reading the error message completely wrong 😅

ecribia avatar Apr 23 '25 15:04 ecribia

For

extensions = {
          file_browser = {
            cwd_to_path = true;
            initial_mode = "normal";
            path = lib.generators.mkLuaInline ''
              function()
                return ":%:p:h"
              end
            '';
          };
        };

Telescope starts as intended. I've noticed that the default for file_browser.path is a function, so assumed it expects a function as well. When do you get the error?

NotAShelf avatar Apr 23 '25 15:04 NotAShelf

I get the error as soon as I launch telescope file_browser.... no error if I just launch telescope find_files.

Its very possible, that im missing something obvious and doing something wrong though. I just pushed to my repo again, if you have the time to just try out the config to see if it works for you?

ecribia avatar Apr 23 '25 15:04 ecribia

I've cloned your repo again and ran it with nix run .#. :Telescope file_browser opens the file browser window as intended.

NotAShelf avatar Apr 23 '25 15:04 NotAShelf

Hmm that is odd. But then i atleast know that its probably some outside factor that i need to look into. Thanks once again! 😄

ecribia avatar Apr 23 '25 15:04 ecribia

Anytime.

NotAShelf avatar Apr 23 '25 15:04 NotAShelf

Sorry for the bump, just checking in if you've had some updates on the path autocomplete thing? Due to recent maintainer bug on unstable that was fixed, i needed to update my nvf. So cant use the old lock file anymore :/

ecribia avatar May 04 '25 17:05 ecribia

I'm afraid I haven't found anything on that. It seems to be working no matter what do I. If you could isolate a plugin conflict, that would help me find a fix. E.g., does it refuse to complete with just blink enabled?

NotAShelf avatar May 04 '25 19:05 NotAShelf

I just checked, and if i only have the following, it doesn't work:

    autocomplete.blink-cmp = {
      enable = true;
      friendly-snippets.enable = true;
    };

But if i instead have this, it works:

    autocomplete.nvim-cmp = {
      enable = true;
      sourcePlugins = [
        "cmp-path"
      ];
      setupOpts.sorting.comparators = [
        {
          _type = "lua-inline";
          expr = "deprio(kinds.Text)";
        }
        "exact"
        "score"
        "kind"
        "length"
        "sort_text"
        "offset"
      ];
    };

However, If i turn EITHER of these two options on, nvim-cmp stops showing path autocompletions:

    vim.lsp.enable = true;
    vim.treesitter.enable = true;

Edit, just to clarity, I turned off all other options in my flake.

ecribia avatar May 04 '25 20:05 ecribia

Here is the entirety of my blink setup:

{lib, ...}: let
  inherit (lib.generators) mkLuaInline;
in {
  programs.nvf.settings.vim = {
    autocomplete.blink-cmp = {
      enable = true;
      setupOpts = {
        signature = {
          enabled = true;
          window.border = "rounded";
        };

        appearance = {
          nerd_font_variant = "normal";
        };

        completion = {
          ghost_text = {
            enabled = true;
            show_with_menu = false;
          };

          documentation = {
            auto_show = true;
            auto_show_delay_ms = 500;
            window.border = "rounded";
          };

          menu = {
            border = "rounded";

            draw = {
              # nvim-cmp-like menu drawing
              columns = [
                {
                  "@1" = "label";
                  "@2" = "label_description";
                  gap = 2;
                }

                ["kind_icon" "kind"]
              ];

              # https://cmp.saghen.dev/recipes.html#completion-menu-drawing
              components = {
                kind_icon = {
                  text = mkLuaInline ''
                    function(ctx)
                      local lspkind = require("lspkind")
                      local icon = ctx.kind_icon
                      if vim.tbl_contains({ "Path" }, ctx.source_name) then
                          local dev_icon, _ = require("nvim-web-devicons").get_icon(ctx.label)
                          if dev_icon then
                              icon = dev_icon
                          end
                      else
                          icon = lspkind.symbolic(ctx.kind, {
                              mode = "symbol",
                          })
                      end

                      return icon  ..  "" .. ctx.icon_gap
                    end
                  '';

                  highlight = mkLuaInline ''
                    function(ctx)
                      local hl = ctx.kind_hl
                      if vim.tbl_contains({ "Path" }, ctx.source_name) then
                        local dev_icon, dev_hl = require("nvim-web-devicons").get_icon(ctx.label)
                        if dev_icon then
                          hl = dev_hl
                        end
                      end

                      return hl
                    end
                  '';
                };
              };
            };
          };
        };
      };

      mappings = {
        close = "<C-e>";
        confirm = "<C-y>";
        next = "<C-n>";
        previous = "<C-p>";
        complete = "<C-Space>";

        scrollDocsDown = "<C-j>";
        scrollDocsUp = "<C-k>";
      };
    };
  };
}

I don't see anything that would explicitly unbreak path completions, and I have both lsp/treesitter enabled. Little unsure still. Maybe @horriblename has a better idea.

NotAShelf avatar May 04 '25 21:05 NotAShelf

Just tried with your code as well, and unfortunately its not working for me :/

I wonder if it can have anything to do with me running my nvf config from a standalone flake?

Edit: Just saw that your @ is inside the codeblock, so dont know if it will ping them Edit2: Just tried it as a regular home-module, and the problem persists.

ecribia avatar May 04 '25 21:05 ecribia

Update: I looked at some other configs online, and one thing that made blink work (it doesnt work at all without it), is adding these to my config:

      config.vim.languages.rust = {
        enable = true;
        crates = {
          enable = true;
          codeActions = true;
        };
      };

With these enabled, blink picks up other completions as well, but not without it. nvim-cmp still doesnt work even with these enabled though (which it used to before). My nvim-cmp settings are:

 config.vim.autocomplete.nvim-cmp = {
      enable = true;

      sourcePlugins = [
        "cmp-path"
      ];
      setupOpts.sorting.comparators = [
        {
          _type = "lua-inline";
          expr = "deprio(kinds.Text)";
        }
        "exact"
        "score"
        "kind"
        "length"
        "sort_text"
        "offset"
      ];
    };

ecribia avatar May 05 '25 09:05 ecribia

Alright, found a fix for nvim-cmp!

This might sound like an obvious solution, and maybe something i should have tried earlier. I added the cmp-path package manually to my config (which was not needed prior to march for me)

  config.vim = {
    extraPlugins = with pkgs.vimPlugins; {
      cmp-path = {
        package = cmp-path;
        setup = ''
          require('cmp').setup {
            sources = {
              { name = 'path' }
            }
          }
        '';
      };
  };

Thanks for all the help so far @NotAShelf , and sorry if I've been too annoying :)

Edit: Guess i celebrated too early. Now paths work, but it breaks the other autocompletes. Well, atleast im closer to find a solution

Edit2: Alright, finally found the real solution!

Adding cmp-path as a plugin manually is not needed. What i actually had to do was add:

vim.autocomplete.nvim-cmp.sources = {
  buffer = "[Buffer]";
  path = "[Path]";
};

These should be in the default settings though according to the documentation? Maybe something was changed recently? Anyways it fixed my issues with nvim-cmp

ecribia avatar May 05 '25 10:05 ecribia

turns out it was this: https://github.com/NotAShelf/nvf/issues/701#issuecomment-2781431490

@NotAShelf we should make some contribution guidelines about this topic: for attrsOf/listOf (maybe for submodules also?) "default" values should be set using the "user" priority to prevent user configuration overwriting defaults, when it was meant to append to the default value

don't have time for this rn, will talk to you in a bit

horriblename avatar May 05 '25 11:05 horriblename

Worth considering, ping me on discord when you'd like to discuss this.

NotAShelf avatar May 05 '25 11:05 NotAShelf