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

/* … */ always split into multiple lines #366

Open
sellout opened this issue Dec 6, 2022 · 3 comments
Open

/* … */ always split into multiple lines #366

sellout opened this issue Dec 6, 2022 · 3 comments

Comments

@sellout
Copy link

sellout commented Dec 6, 2022

LnL7/vim-nix#28 proposes using inline comments as editor hints for highlighting foreign code blocks. But Alejandra doesn’t currently behave well with that. Here’s a before/after Alejandra excerpt from my experiment using that style:

-      initExtra = /* sh */ ''
-        source "${pkgs.darcs}/share/bash-completion/completions/darcs"
-      '';
+      initExtra =
+        /*
+        sh
+        */
+        ''
+          source "${pkgs.darcs}/share/bash-completion/completions/darcs"
+        '';

This isn’t yet a settled convention, so raising it here for consideration as to whether supporting one-line /* … */ in Alejandra is the way to go, or if there should be some other approach for handling foreign code blocks.

@rummik
Copy link

rummik commented Dec 7, 2022

Other community support for hint prefixes can found floating around:

donovanglover added a commit to donovanglover/nix-config that referenced this issue Jun 11, 2023
Note that alejandra currently does not handle these comments properly.

See: kamadorueda/alejandra#366
@MattSturgeon
Copy link

nvim-treesitter also added support in nvim-treesitter/nvim-treesitter#3842

This format appears to be gaining traction and personally I'm a fan of it. Perhaps Alejandra could allow "short" comments to be kept inline?

A simple definition of "short" might be the comment does not contain multiple words. Or alternatively perhaps a max char length?

Some additional examples:

mapping = {
  "<CR>" = /* lua */ "cmp.mapping.confirm({ select = true })";
  "C-y" = /* lua */ "cmp.mapping.confirm({ select = true })";
  "<Tab>" = /* lua */ ''
    function(fallback)
      -- ...
    end
  '';
  "<S-Tab>" = /* lua */ ''
    function(fallback)
      -- ...
    end
  '';
};

@musjj
Copy link

musjj commented Dec 28, 2023

Would love support for this too. For now I'm working around this by using linewise comments instead:

{
  attribute =
    # bash
    ''
      echo "hello world"
    '';
}

It saves two whole lines compared to the way that inline comments are currently formatted, with a plus of better readability. But it still wastes two extra lines compared to the ideal format:

{
  attribute = /* bash */ ''
    echo "hello world"
  '';
}

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

No branches or pull requests

4 participants