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

ale#statusline#Count couldn't return a proper result #764

Closed
blurm opened this issue Jul 12, 2017 · 5 comments
Closed

ale#statusline#Count couldn't return a proper result #764

blurm opened this issue Jul 12, 2017 · 5 comments

Comments

@blurm
Copy link

blurm commented Jul 12, 2017

Hi, I try to integrate ale message into my own statusline function, and I found out ale#statusline#Count maybe the right method to call

below is a test code I put into init.vim (neovim)

function! LinterStatus() abort
    let l:counts = ale#statusline#Count(bufnr(''))

    let l:all_errors = l:counts.error + l:counts.style_error
    let l:all_non_errors = l:counts.total - l:all_errors

    return l:counts.total == 0 ? 'OK' : printf(
                \   '%dW %dE',
                \   all_non_errors,
                \   all_errors
                \)
endfunction

function! MyTest() abort
    let m = LinterStatus()
    echom m
endfunction

autocmd BufWinEnter,BufRead,BufReadPost,WinEnter,FileType * call MyTest()

ale plugin works perfectly, but the test script have problems

It doesn't work (print 'OK' with error files):

  • run nvim file_with_error.py in terminal
  • run :e file_with_error.py in neovim
    It works:
  • run :vs in neovim
  • :w save buffer if I add BufWrite in autocmd
@blurm blurm changed the title ale#statusline#Count doesn't return a proper result ale#statusline#Count couldn't return a proper result Jul 12, 2017
@w0rp
Copy link
Member

w0rp commented Jul 12, 2017

See :help <abuf>. bufnr('') might be returning a different buffer number. You also might be calling the function before linting has been completed.

@blurm
Copy link
Author

blurm commented Jul 12, 2017

The buffer number should be OK. I replaced with <abuf>, it print the same buf number.

How should I calling the function after linting completing?
I tried autocmd User ALELint echom "ALE run!" but it didn't executed

@w0rp
Copy link
Member

w0rp commented Jul 13, 2017

The example in the documentation is wrong. I'll fix it so the autocmd can be used to echo things.

The autocmd is run with silent, so echo won't work.

w0rp added a commit that referenced this issue Jul 13, 2017
@w0rp
Copy link
Member

w0rp commented Jul 13, 2017

I updated the documentation in the end to include unsilent.

autocmd User ALELint unsilent echom 'ALE run!'

@blurm
Copy link
Author

blurm commented Jul 14, 2017

It works perfectly! Thanks!

@blurm blurm closed this as completed Jul 14, 2017
rsrchboy added a commit to rsrchboy/ale that referenced this issue Jul 15, 2017
* upstream/master: (23 commits)
  dense-analysis#764 - Update the documentation to mention how to echo messages with the ALELint autocmd
  Simplify the tests for the ALELint autocmd command
  Add scalastyle linter (dense-analysis#766)
  dense-analysis#697 - Remove highlights more thoroughly
  dense-analysis#769 Ignore stderr output and output without JSON we can read for rubocop
  Make tsserver completion more reliable, but not quite ready for documentation yet
  Rubocop: handle empty 'files' array in output
  Fix dense-analysis#760 - Report problems with configuration files for rubocop
  Add rails_best_practices handler (resolves dense-analysis#655) (dense-analysis#751)
  Fix docs for FindProjectRoot function
  Fixup dense-analysis#756
  dense-analysis#756 Escape the paths used for the --include parameter for gometalinter, which uses RE2
  Fix documentation typo
  Fix dense-analysis#747 - Lint and fix files after they have been been written to disk, not during writing them
  Look for ini file to spot python project root (dense-analysis#755)
  Make gometalinter work again
  Prefer --fast for stack-build (dense-analysis#754)
  Fix comment typo
  Brakeman: Remove unused cache var from tests
  Kotlin and general Gradle support. (dense-analysis#745)
  ...
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