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

feat(diagnostic): add diagnostic.displayByVimDiagnostic #5236

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

fannheyward
Copy link
Member

@fannheyward fannheyward commented Jan 3, 2025

The diagnostic.displayByVimDiagnostic configuration will set diagnostics to nvim's vim.diagnostic, and prevent coc.nvim's handler to display them in virtualText/sign/floating etc.

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.35%. Comparing base (a6e54ae) to head (2a5c5cd).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/diagnostic/buffer.ts 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5236      +/-   ##
==========================================
- Coverage   97.37%   97.35%   -0.02%     
==========================================
  Files         291      291              
  Lines       27027    27038      +11     
  Branches     5607     5610       +3     
==========================================
+ Hits        26317    26323       +6     
- Misses        496      498       +2     
- Partials      214      217       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch from bd057c8 to b9d5d8f Compare January 3, 2025 07:27
plugin/coc.vim Outdated Show resolved Hide resolved
@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch from b9d5d8f to 5d5c363 Compare January 7, 2025 08:14
@fannheyward
Copy link
Member Author

fannheyward commented Jan 7, 2025

@luisdavim @davidosomething I've improved this. Add diagnostic.displayByVimDiagnostic configuration, disabled by default. This configuration will set coc.nvim's diagnostics to nvim's vim.diagnostic, and prevent coc.nvim's handler like display in virtualText/floating/sign etc, please give it a try. Feedback is welcome.

@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch 3 times, most recently from c609ba6 to 5425139 Compare January 7, 2025 08:35
@fannheyward fannheyward changed the title feat(diagnostic): sync to vim.diagnostic on nvim feat(diagnostic): add diagnostic.displayByNvimDiagnostic Jan 7, 2025
@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch from 5425139 to a91b5af Compare January 7, 2025 08:39
@fannheyward fannheyward changed the title feat(diagnostic): add diagnostic.displayByNvimDiagnostic feat(diagnostic): add diagnostic.displayByVimDiagnostic Jan 7, 2025
@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch 2 times, most recently from 94b7c09 to 58cc3a4 Compare January 7, 2025 09:58

local diagnostics = {}
for _, d in ipairs(items) do
diagnostics[#diagnostics + 1] = {
Copy link
Contributor

@davidosomething davidosomething Jan 7, 2025

Choose a reason for hiding this comment

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

can you add a user-definable function call here
i.e. diagnostics[#diagnostics + 1] = config.diagnosticFormatter({ ... })

or just on the message line
as in https://github.com/davidosomething/coc-diagnostics-shim.nvim/blob/main/lua/coc-diagnostics-shim/init.lua#L61

the use case is to apply formatting to the diagnostic message
i am currently able to do it by intercepting ale or via my diagnostic shim plugin (e.g. https://github.com/davidosomething/coc-diagnostics-shim.nvim/blob/main/lua/coc-diagnostics-shim/init.lua#L16 )

Copy link
Member Author

Choose a reason for hiding this comment

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

You can format the message with vim.diagnostic.config, for example:

vim.diagnostic.config({
    virtual_text = {
        format = function(diagnostic)
            return string.format('%s %s ', 'ꜰᴏʀᴍᴀᴛᴛᴇᴅ ᴡɪᴛʜ ꜰᴏʀᴍᴀᴛ-ᴛs-ᴇʀʀᴏʀs.ɴᴠɪᴍ', diagnostic.message)
        end,
    },
})

set coc.nvim's diagnostics to nvim's `vim.diagnostic`, disabled by default.

This should be useful for nvim's diagnostic-related plugins that request diagnostic from `vim.diagnostic`
@fannheyward fannheyward force-pushed the feat/sync-to-vim-diagnostic branch from 58cc3a4 to 2a5c5cd Compare January 8, 2025 03:21
@fannheyward fannheyward merged commit 674482c into master Jan 8, 2025
2 of 4 checks passed
@fannheyward fannheyward deleted the feat/sync-to-vim-diagnostic branch January 8, 2025 05:24
fannheyward added a commit that referenced this pull request Jan 21, 2025
baac60a fix(diagnostic): only set on displayByVimDiagnostic (#5245)
674482c feat: add `diagnostic.displayByVimDiagnostic` (#5236)
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.

3 participants