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

change the format in sources/diagnostics.lua #508

Closed
1 task done
xz47sv opened this issue Jun 14, 2024 · 4 comments · Fixed by #504
Closed
1 task done

change the format in sources/diagnostics.lua #508

xz47sv opened this issue Jun 14, 2024 · 4 comments · Fixed by #504
Labels
enhancement New feature or request

Comments

@xz47sv
Copy link

xz47sv commented Jun 14, 2024

Did you check the docs?

  • I have read all the trouble.nvim docs

Is your feature request related to a problem? Please describe.

The current format at

format = "{severity_icon} {message:md} {item.source} ({code}) {pos}",
contains parentheses around the code so if a user wants to register a custom formatter for the code the parentheses will stick around.

Describe the solution you'd like

Remove the parentheses and change the format to

format = "{severity_icon} {message:md} {item.source} {code} {pos}",

add

  code = function(ctx)
    return {
      text = ctx.item.code and "(" .. ctx.item.code .. ")" or "",
    }
  end,

to

M.formatters = {

Additional context

This could probably be done for other formats that contain braces or any other special characters for the sake of more customizability.

(or optionally just make the format itself directly customizable)

@xz47sv xz47sv added the enhancement New feature or request label Jun 14, 2024
@folke
Copy link
Owner

folke commented Jun 14, 2024

Yiou can just override the format too in your config.

opts.modes.diagnostics.format = ...

@folke folke closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@xz47sv
Copy link
Author

xz47sv commented Jun 14, 2024

Ok, but the current default leaves an empty pair of parentheses "()" if the diagnostic doesn't contain a code, wouldn't it be objectively better to not do that by default and return ""?

Plus {pos} also adds the brackets in the formatter and not in the format string, why not do it for each of them so the user can override just the specific formatter instead of the entire string.

@b0ae989c
Copy link
Contributor

User defined formatter is already implemented in trouble, but it is not yet documented fully. In your example, we can do the following

-- Lazy config
{
  'folke/trouble.nvim',
  opts = {
    modes = {
      my_diagnostics = {
        mode = 'diagnostics',
        format = '{my_pos} {my_code}',
      },
    },
    formatters = {
        my_pos = function(ctx)
          return { text = ctx.item.pos[1] .. ':' .. (ctx.item.pos[2] + 1) },
        end,
        my_code = function(ctx)
          return { text = ctx.item.code and '(' .. ctx.item.code .. ')' or '' },
        end,
    },
  },
}

@folke
Copy link
Owner

folke commented Jun 14, 2024

I've updated the default format for code. Better indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants