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

Use the sign gutter for diagnostics #165

Open
natebosch opened this issue Mar 13, 2019 · 1 comment
Open

Use the sign gutter for diagnostics #165

natebosch opened this issue Mar 13, 2019 · 1 comment

Comments

@natebosch
Copy link
Owner

No description provided.

@pwntester
Copy link

pwntester commented Nov 13, 2019

Im using the following config to display both signs and right-aligned virtual text just in case anyone finds it useful:

" define signs
call sign_define("vim-lsc-error", {"text" : "x", "texthl" : "lscSignDiagnosticError"})
call sign_define("vim-lsc-warning", {"text" : "x", "texthl" : "lscSignDiagnosticWarning"})

" virtual text namespace
let s:namespace_id = nvim_create_namespace("vim-lsc")

" update diagnostic visualizations
function! s:updateDiagnosticVisuals() abort
    let buf_id = nvim_get_current_buf()
    let file_path = nvim_buf_get_name(buf_id)
    let diagnostics = lsc#diagnostics#forFile(file_path).ListItems()
    call s:setVirtualText(buf_id, diagnostics)
    call s:setSigns(buf_id, diagnostics)
endfunction

function! s:setVirtualText(buf_id, diagnostics) abort

    " clear previous virtual texts
    call nvim_buf_clear_namespace(a:buf_id, s:namespace_id, 0, -1)

    " add virtual texts
    for diagnostic in a:diagnostics
        let available_space = winwidth('%') - strwidth(getline(l:diagnostic['lnum'])) - 8
        let text = strwidth(l:diagnostic['text']) < l:available_space ?  repeat(" ", l:available_space - strwidth(l:diagnostic['text'])).l:diagnostic['text'] : l:diagnostic['text']
        let hl_group = l:diagnostic['type'] == 'E' ? 'lscVTDiagnosticError' : 'lscVTDiagnosticWarning'
        call nvim_buf_set_virtual_text(l:diagnostic['bufnr'], s:namespace_id, l:diagnostic['lnum']-1, [[l:text, l:hl_group]], {})
    endfor
endfunction

function! s:setSigns(buf_id, diagnostics) abort

    " clear previous virtual texts
    call sign_unplace('vim-lsc', {'buffer' : a:buf_id})

    " add signs
    for diagnostic in a:diagnostics
        if l:diagnostic['type'] == 'E'
            let sign = 'vim-lsc-error'
        elseif l:diagnostic['type'] == 'W'
            let sign = 'vim-lsc-warning'
        else 
            return
        endif
        call sign_place(1, 'vim-lsc', l:sign, l:diagnostic['bufnr'], {'lnum' : l:diagnostic['lnum']})
    endfor
endfunction

autocmd BufEnter * if has_key(g:lsc_server_commands, &filetype) | call s:updateDiagnosticVisuals() | endif
autocmd User LSCDiagnosticsChange call s:updateDiagnosticVisuals()

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