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

Multiline LSP diagnostics send to neovim's API are unwrapped #4880

Open
WhyNotHugo opened this issue Dec 16, 2024 · 3 comments
Open

Multiline LSP diagnostics send to neovim's API are unwrapped #4880

WhyNotHugo opened this issue Dec 16, 2024 · 3 comments
Labels

Comments

@WhyNotHugo
Copy link
Contributor

Information

VIM version

NVIM v0.10.2                                                                                                                             
Build type: MinSizeRel                                                                                                                   

Operating System: Alpine Linux, Edge

What went wrong

I'm using vim.g.ale_use_neovim_diagnostics_api = 1. When ALE sends diagnostics to neovim, ALE unwraps multiline diagnostics.

Some LSPs return multi-line diagnostics, and even align continuation lines to present the error in a visually clearer way. Joining lines breaks displaying of diagnostics in most interfaces.

Screenshots

The following compare how diagnostics from both sources, rendered via lsp_lines.nvim.

When using neovim with its native LSP client:

image

When using ALE:

image

Reproducing the bug

  1. Enable ale_use_neovim_diagnostics_api
  2. Open a go file with an error like strings.Replace("a", "b", 0) (note that the error returned by the LSP is multi-line, and continuation lines are deliberately aligned).

:ALEInfo

Expand Current Filetype: go Available Linters: ['bingo', 'cspell', 'gobuild', 'gofmt', 'golangci-lint', 'gopls', 'gosimple', 'gotype', 'govet', 'golangserver', 'revive', 'staticcheck'] Linter Aliases: 'gobuild' -> ['go build'] 'govet' -> ['go vet'] Enabled Linters: [] Ignored Linters: [] Suggested Fixers: 'gofmt' - Fix Go files with go fmt. 'gofumpt' - Fix Go files with gofumpt, a stricter go fmt. 'goimports' - Fix Go files imports with goimports. 'golangci_lint' - Fix Go files with golangci-lint. 'golines' - Fix Go file long lines with golines 'gopls' - Fix Go files with gopls. 'remove_trailing_lines' - Remove all blank lines at the end of a file. 'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.

Linter Variables:
" Press Space to read :help for a setting
let g:ale_go_go_executable = 'go'
let g:ale_go_golangci_lint_executable = 'golangci-lint'
let g:ale_go_golangci_lint_options = ''
let g:ale_go_golangci_lint_package = 0
let g:ale_go_langserver_executable = 'go-langserver'
let g:ale_go_langserver_options = ''

Global Variables:
" Press Space to read :help for a setting
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
let g:ale_command_wrapper = v:null
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 'auto'
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = v:null
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {'go': ['gofmt'], 'yaml': ['prettier'], 'scss': ['prettier'], 'json': ['prettier'], 'lua': ['stylua'], 'html': ['prettier'], 'vue': ['prettier'], '*': ['remove_trailing_lines', 'trim_whitespace'], 'typescript': ['prettier'], 'sql': ['pgformatter'], 'markdown': ['prettier']}
let g:ale_history_enabled = 1
let g:ale_info_default_mode = 'preview'
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'markdown': ['proselint', 'vale'], 'apkbuild': ['apkbuild_lint'], 'mail': ['proselint']}
let g:ale_linters_explicit = 1
let g:ale_linters_ignore = {}
let g:ale_list_vertical = v:null
let g:ale_list_window_size = v:null
let g:ale_loclist_msg_format = v:null
let g:ale_max_buffer_history_size = v:null
let g:ale_max_signs = v:null
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:null
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = v:null
let g:ale_sign_error = v:null
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = v:null
let g:ale_sign_highlight_linenrs = v:null
let g:ale_type_map = v:null
let g:ale_use_neovim_diagnostics_api = 1
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 'disabled'
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1

Command History:

@WhyNotHugo WhyNotHugo added the bug label Dec 16, 2024
@WhyNotHugo
Copy link
Contributor Author

I too unfamiliar with the codebase to figure out why this is happening, and can't think of useful keywords to search further.

Any pointers would be welcome.

@WhyNotHugo
Copy link
Contributor Author

WhyNotHugo commented Jan 7, 2025

The following patch fixes the issue:

diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim
index 498ec508..522ddb89 100644
--- a/autoload/ale/lsp/response.vim
+++ b/autoload/ale/lsp/response.vim
@@ -27,8 +27,9 @@ function! ale#lsp#response#ReadDiagnostics(response) abort
 
     for l:diagnostic in a:response.params.diagnostics
         let l:severity = get(l:diagnostic, 'severity', 0)
         let l:loclist_item = {
-        \   'text': substitute(l:diagnostic.message, '\(\r\n\|\n\|\r\)', ' ', 'g'),
+        \   'text': l:diagnostic.message,
         \   'type': 'E',
         \   'lnum': l:diagnostic.range.start.line + 1,
         \   'col': l:diagnostic.range.start.character + 1,

Diagnostics are rendered properly. I do have to further test this with other setups; I'm uncertain of how this displays in other contexts that are not using neovim's diagnostics API.

Small aside: when merging lines, leading indentation of continuation lines should be trimmed too.

@WhyNotHugo
Copy link
Contributor Author

:ALEPopulateLocList seems to continue rendering fine ­— it merges consecutive lines into one, and also trims whitespace from each one before doing so, so the patch actually improves the loclist.

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

No branches or pull requests

1 participant