Skip to content

plugins/todo-comments: migrate to mkNeovimPlugin#2030

Merged
mergify[bot] merged 1 commit intonix-community:mainfrom
khaneliman:todo
Aug 18, 2024
Merged

plugins/todo-comments: migrate to mkNeovimPlugin#2030
mergify[bot] merged 1 commit intonix-community:mainfrom
khaneliman:todo

Conversation

@khaneliman
Copy link
Copy Markdown
Contributor

No description provided.

@khaneliman khaneliman force-pushed the todo branch 5 times, most recently from 8ecf733 to 3fb4211 Compare August 17, 2024 05:31
@khaneliman khaneliman marked this pull request as ready for review August 17, 2024 05:33
(mkIf (cfg.keymaps.todoTrouble != null) { trouble.enable = true; })
(mkIf (cfg.keymaps.todoTelescope != null) { telescope.enable = true; })
];
mkCompositeOption "Keymap settings for the `:${funcName}` function." {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this is a way that complies with #603?

Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're unfamiliar, the idea is that plugin keymaps should make use of mkMapOptionSubmodule instead of implementing their own keymap submodule types.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mkMapOptionSubmodule is too limiting, because it doesn't support additional options (cwd, keywords) I'm open to making it more powerful by adding an extraOptions argument or similar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in #2030 (comment) this can done in be another PR

@khaneliman khaneliman force-pushed the todo branch 2 times, most recently from 826f39a to e550f80 Compare August 17, 2024 20:18
Comment on lines +393 to +408
keymaps = flatten (
mapAttrsToList (
optionName: funcName:
let
keymap = cfg.keymaps.${optionName};

cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}";
in
optional (keymap != null) {
mode = "n";
inherit (keymap) key options;
action = ":${funcName}${cwd}${keywords}<CR>";
}
) commands
);
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is unchanged from the previous implementation, other than being indented further.

However, I think this would be simpler mapping over cfg.keymaps instead of mapping over commands?

Ideally, I'd like to avoid using optional+flatten, perhaps we could do something like:

keymaps = lib.pipe cfg.keymaps [
  (filterAttrs (n: v: v != null))
  (mapAttrsToList (name: keymap: {
    inherit (keymap) key option;
    mode = "n";
    action =
      let
        cmd = commands.${name};
        cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
        keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}";
      in
      "<cmd>${cmd}${cwd}${keywords}<cr>";
  }))
];

Looking at the commands attrset, we could probably replace it with a upperFirstChar style helper.

However, many of the details would be slightly different if we can go down the #603 route.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is unchanged from the previous implementation, other than being indented further.

Yeah, sorry I didn't touch this bit. I wasn't sure what to do with it, yet.

I think the suggested solution is a lot cleaner. But, I need to get more familiar with that keymap issue that was mentioned here and above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always tackle it in another PR, but the other suggestions above could be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can tackle that separately it would give me a bit to figure it out and maybe get the extraOptions support for mkMapOptionSubmodule

@khaneliman khaneliman force-pushed the todo branch 3 times, most recently from 970e1df to f602326 Compare August 18, 2024 05:11
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think these are the final comments 🚀

Comment on lines +17 to 23
keymapsActions = {
todoQuickFix = "TodoQuickFix";
todoLocList = "TodoLocList";
todoTrouble = "TodoTrouble";
todoTelescope = "TodoTelescope";
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, we could drop this, since we have lib.nixvim.upperFirstChar:

nixvim/lib/utils.nix

Lines 81 to 104 in 78fc4be

/**
Capitalize a string by making the first character uppercase.
# Example
```nix
upperFirstChar "hello, world!"
=> "Hello, world!"
```
# Type
```
upperFirstChar :: String -> String
```
*/
upperFirstChar =
s:
let
first = substring 0 1 s;
rest = substring 1 (stringLength s) s;
result = (toUpper first) + rest;
in
optionalString (s != "") result;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess it's used in the option declaration as well as the keymap transformation. So maybe best to keep it?

mode = "n";
action =
let
cmd = keymapsActions.${name};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide to drop the keymapsActions attrs:

Suggested change
cmd = keymapsActions.${name};
cmd = lib.nixvim.upperFirstChar name;

Comment on lines +143 to +142
keywords =
defaultNullOpts.mkAttrsOf
(types.submodule {
options = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this will be affected by #1618, however that doesn't affect how you should implement it here. It's just another reason for us to investigate the issue.

@khaneliman khaneliman force-pushed the todo branch 4 times, most recently from eb58f12 to a8437a8 Compare August 18, 2024 18:17
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't see any remaining issues. Thanks for another quality PR! 🎉

Using mkMapOptionSubmodule as per #603 can be postponed to another PR, and may be best done after #2035 is merged anyway.

Up to you if you're happy merging now if if you'd like to ping other maintainers for a second opinion.

No need to wait for the tests to pass though, since mergify will do that for us.

@khaneliman
Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 18, 2024

queue

🛑 The pull request has been removed from the queue default

Details

The pull request #2030 has been manually updated.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

@MattSturgeon
Copy link
Copy Markdown
Member

@Mergifyio refresh

@MattSturgeon
Copy link
Copy Markdown
Member

@Mergifyio queue

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 18, 2024

refresh

✅ Pull request refreshed

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 18, 2024

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 379ae77

@mergify mergify bot merged commit 379ae77 into nix-community:main Aug 18, 2024
@mergify mergify bot temporarily deployed to github-pages August 18, 2024 19:37 Inactive
@khaneliman khaneliman deleted the todo branch August 19, 2024 02:58
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