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

vimPlugins.codesnap-nvim: init at 2024-05-08 #321030

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

GaetanLepage
Copy link
Contributor

@GaetanLepage GaetanLepage commented Jun 19, 2024

Description of changes

Add codesnap.nvim, a snapshot plugin with rich features that can make pretty code snapshots for Neovim.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@GaetanLepage
Copy link
Contributor Author

Result of nixpkgs-review pr 321030 run on aarch64-darwin 1

1 package built:
  • vimPlugins.codesnap-nvim

@GaetanLepage
Copy link
Contributor Author

Result of nixpkgs-review pr 321030 run on x86_64-darwin 1

1 package built:
  • vimPlugins.codesnap-nvim

@GaetanLepage
Copy link
Contributor Author

Result of nixpkgs-review pr 321030 run on x86_64-linux 1

1 package built:
  • vimPlugins.codesnap-nvim

@GaetanLepage
Copy link
Contributor Author

Result of nixpkgs-review pr 321030 run on aarch64-linux 1

1 package built:
  • vimPlugins.codesnap-nvim

Copy link
Contributor

@eljamm eljamm left a comment

Choose a reason for hiding this comment

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

Aside from this, everything looks good to me.

pkgs/applications/editors/vim/plugins/overrides.nix Outdated Show resolved Hide resolved
pkgs/applications/editors/vim/plugins/overrides.nix Outdated Show resolved Hide resolved
@GaetanLepage
Copy link
Contributor Author

Result of nixpkgs-review pr 321030 run on x86_64-linux 1

1 package built:
  • vimPlugins.codesnap-nvim

Result of nixpkgs-review pr 321030 run on aarch64-linux 1

1 package built:
  • vimPlugins.codesnap-nvim

Result of nixpkgs-review pr 321030 run on x86_64-darwin 1

1 package built:
  • vimPlugins.codesnap-nvim

Result of nixpkgs-review pr 321030 run on aarch64-darwin 1

1 package built:
  • vimPlugins.codesnap-nvim


# https://github.com/mistricky/codesnap.nvim/blob/main/scripts/build_generator.sh
postInstall = let
extension = if stdenv.isDarwin then "dylib" else "so";
Copy link
Member

Choose a reason for hiding this comment

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

you can use sthg like stdenv.hostPlatform.extensions.sharedLibrary instead. in this case I guess it should be targetPlatform ? I dont know ^^' but I think hostPlatform is for the builder.

Copy link
Contributor

@eljamm eljamm Jun 20, 2024

Choose a reason for hiding this comment

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

According to the docs:

The "host platform" is the platform on which a package will be run.

So I think you're right, there.

Also, doesn't the library need to be copied to lua/generator${extension} instead of lua/generator.so ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I thought, but looking at the script suggests that the destination should always be generator.so...
But now that I have a look at it again, it feels like a mistake...
Could you please help us with this @mistricky ?

Choose a reason for hiding this comment

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

Hi @GaetanLepage, sorry to reply late, wow thank u for packing codesnap to nixpkgs.

The generator.so is build from rust source, and called by Lua, both on Mac OS and Linux, the suffix should be .so, so the script just rename the generator.[dylib | so] to generator.so, it's not a mistake.

But there is another situation, if the user on Windows, the suffix should be .dll, but CodeSnap does not support Windows platform yet, so the filename of generator should always belua/generator.so for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, very good to know, thanks for coming in and helping !
I went and trust the script, so we have nothing to change.

'';

doInstallCheck = true;
nvimRequireCheck = "codesnap";
Copy link
Member

Choose a reason for hiding this comment

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

does it rely on an external service or do you think you could try to generate a picture in the test ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any documentation for writing tests for Vim plugins?

Copy link
Member

Choose a reason for hiding this comment

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

No just the code. It's not hard: nvimRequireCheck starts nvim with :lua require'<nvimRequireCheck-value>' while vimCommandHook starts nvim with :vimCommandHook

Copy link
Contributor

Choose a reason for hiding this comment

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

So I was able to make the plugin work with just a single keymap:

vim.keymap.set(
  'n',
  '<leader>cs',
  ':lua require("codesnap").setup({save_path="/tmp/out.png"})<CR>:norm! ggVG<CR>:CodeSnapSave txt<CR>',
  { desc = 'Snap Code' }
)

Which is basically a combination of 3 commands:

  1. :lua require("codesnap").setup({save_path="/tmp/out.png"}): setup & set out path for the snapshot
  2. :norm! ggVG: go to top, select all the code until the bottom
  3. :CodeSnapSave txt: snap that with document type txt

I'm having difficulties adding this to the vimCommandHook, though, which I think only checks that the command exists.

My attempt is at eljamm@0a9aa3d

Copy link
Member

Choose a reason for hiding this comment

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

@eljamm wow nice ! you are trying a more elaborate test than vimCommandHook or nvimRequireCheck in which case you will need to write your own checkPhase.
The test you tried to write shouldn't live in nixpkgs IMO, it should be a basic test that codesnap upstream already has and we should just run it.
Now I can't find a testsuite in their repo (dont they have tests) ? If you are really motivated by this you can contribute to upstream, otherwise maybe just add nvimRequireCheck = "codesnap".

You can check what it does in pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are really motivated by this you can contribute to upstream, otherwise maybe just add nvimRequireCheck = "codesnap".

This is what is already done in this PR. Do you want me to add anything else ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for the help. I'll check and see what I can do upstream, but for now nvimRequireCheck might be enough.

@GaetanLepage GaetanLepage merged commit 9b8794f into NixOS:master Jun 21, 2024
30 checks passed
@GaetanLepage GaetanLepage deleted the codesnap branch June 21, 2024 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants