Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/project-nvim: take ownership of telescope integration #1236

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

khaneliman
Copy link
Contributor

Telescope extension option being toggled independently will throw an error in config trying to load a non existent plugin.

@traxys
Copy link
Member

traxys commented Mar 9, 2024

I'd rather add a warning than toggling it explictely

@khaneliman
Copy link
Contributor Author

khaneliman commented Mar 9, 2024

I'm not sure why, though. If I enable the extension manually I expected it to enable the plugin that it's dependent on for me.

It's a bug currently to try and load an extension that doesn't exist and breaks your init.lua just enabling this alone. The other instances of extensions fetch the package for you, as well.

I started going through and writing a warning, but it felt weird wording it basically saying that this option does nothing by itself other than cause errors so please go enable another option manually.

@khaneliman
Copy link
Contributor Author

khaneliman commented Mar 9, 2024

I wrote the warning around the concept of you possibly supplying the project-nvim outside of the nixvim options, if that was what you were thinking. This would require changing the default of project-nvim enable to be nullable, otherwise it's always false and will always show the warning.

{ lib
, config
, ...
}:
with lib; let
  cfg = config.plugins.telescope.extensions.project-nvim;
  project-nvim-cfg = config.plugins.project-nvim;
in
{
  options.plugins.telescope.extensions.project-nvim = {
    enable = mkEnableOption "project-nvim telescope extension";
  };

  config = mkIf cfg.enable {
    plugins.telescope.enabledExtensions = [ "projects" ];

    warnings = optional (!project-nvim-cfg.enable)
        ''
          You have enabled the `project-nvim` extension in telescope.
          You need to provide the project-nvim plugin itself otherwise this option will break your config.

          - To enable this extension, set `plugins.project-nvim.enable` to `true`.
          - If you've supplied the plugin outside of Nixvim, to silence this warning, explicitly set the option to `false`.
        '';
  };
}

Unless you were thinking something simpler in another example in the repo of, but this one implies it shouldn't break your config and just might have missing functionality... right now, loading an extension that doesn't exist causes lua errors:

in {
  meta.maintainers = [maintainers.GaetanLepage];

  options.plugins.hmts = {
    enable = mkEnableOption "hmts.nvim";

    package = helpers.mkPackageOption "hmts.nvim" pkgs.vimPlugins.hmts-nvim;
  };

  config = mkIf cfg.enable {
    warnings = optional (!config.plugins.treesitter.enable) [
      "Nixvim: treesitter-refactor needs treesitter to function as intended"
    ];

    extraPlugins = [cfg.package];
  };
}

@traxys
Copy link
Member

traxys commented Mar 12, 2024

Well if it breaks I'd suggest adding an assertion (so an error) instead of a warning, but I'd prefer we avoid having too much magic.

Ultimately I think I'd prefer having an option in the project.nvim plugin options called enableTelescope that would do this, and avoid using the config.plugins.telescope.extensions.project-nvim option, maybe even deprecating this way to enable telescope extensions.

I feel like it is more appropriate to have project.nvim manage this (and maybe warn the user if enableTelescope is set to true but telescope is not enabled)

@khaneliman
Copy link
Contributor Author

I feel like it is more appropriate to have project.nvim manage this (and maybe warn the user if enableTelescope is set to true but telescope is not enabled)

I agree with this sentiment. I'll go this direction.

@khaneliman
Copy link
Contributor Author

khaneliman commented Mar 13, 2024

In testing, I noticed telescope is automatically enabled in yanky and todo-comments. So I had to mkForce disable to test the warning. Should that be removed to get rid of the magic you were talking about?

I also saw that harpoon is doing an assertion instead of a warning for the telescope integration. Should we change that to a warning like this or make this one an assertion? Looks like others are warnings, as well and that's the outlier.

@khaneliman khaneliman changed the title plugins/telescope: fix project-nvim extension plugins/utils/project-nvim: take ownership of telescope integration Mar 13, 2024
@khaneliman khaneliman changed the title plugins/utils/project-nvim: take ownership of telescope integration plugins/project-nvim: take ownership of telescope integration Mar 13, 2024
@traxys traxys merged commit 29b6ede into nix-community:main Mar 13, 2024
51 checks passed
@khaneliman khaneliman deleted the telescope branch March 13, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants