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

Functions in arguments get formatted into an unreadable style #606

Closed
WhyNotHugo opened this issue Oct 15, 2022 · 5 comments
Closed

Functions in arguments get formatted into an unreadable style #606

WhyNotHugo opened this issue Oct 15, 2022 · 5 comments

Comments

@WhyNotHugo
Copy link

This:

vim.keymap.set(
  "n",
  "<Leader>e",
  function()
    require("trouble").toggle({ "document_diagnostics", group = false })
  end,
  { desc = "Show LSP errors/diagnostics" }
)

Gets formatted into this:

vim.keymap.set("n", "<Leader>e", function()
  require("trouble").toggle({ "document_diagnostics", group = false })
end, { desc = "Show LSP errors/diagnostics" })

This only seems to happen if the function is too short. I guess only character count for parameters is taken into account, but not the fact that one parameter is a function?

@JohnnyMorganz
Copy link
Owner

JohnnyMorganz commented Oct 15, 2022

This looks like a duplicate of #276, and there is some comments there about why its currently done.
Mainly because of some React-like Lua code:

Roact.createElement("Name", {
    ...
}, {
    ...
})

where keeping it inline is nicer.

I agree with you here though that this seems a bit harder to read.
Maybe if its a function followed by a table, it shouldn't be inlined? But we leave trailing functions and tables arguments alone.

You can view the function-call-XXX snapshots in https://github.com/JohnnyMorganz/StyLua/tree/main/tests/snapshots (inputs: https://github.com/JohnnyMorganz/StyLua/tree/main/tests/inputs) to see what we currently do

@WhyNotHugo
Copy link
Author

An approach possible simpler than #276, is: if a function is short enough to fit in one line when passed as a parameter, then just oneline it, e.g.:

vim.keymap.set(
  "n",
  "<Leader>e",
  function() require("trouble").toggle({ "document_diagnostics", group = false }) end,
  { desc = "Show LSP errors/diagnostics" }
)

Though this would only address some cases.

@WhyNotHugo
Copy link
Author

I'm not sure I fully understand the snapshot files.

@JohnnyMorganz
Copy link
Owner

JohnnyMorganz commented Oct 15, 2022

An approach possible simpler than #276, is: if a function is short enough to fit in one line when passed as a parameter, then just oneline it, e.g.:

vim.keymap.set(
  "n",
  "<Leader>e",
  function() require("trouble").toggle({ "document_diagnostics", group = false }) end,
  { desc = "Show LSP errors/diagnostics" }
)

Though this would only address some cases.

This is already possible, but it requires configuring collapse_simple_statement = "FunctionOnly" or "Always" (#493)

@JohnnyMorganz
Copy link
Owner

Going to fold this issue into #276 as a duplicate. I think the formatting here could be improved though.
As above, you can also configure collapse_simple_statement = "FunctionOnly" to achieve the one-line formatting

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

2 participants