简体   繁体   English

如何查看合成词的状态?

[英]How to check syntastic's status?

I updated node with homebrew today and that meant that all the npm modules got blown away. 我今天用自制软件更新了节点,这意味着所有npm模块都被淘汰了。 This of course means that the jshint executable (eg obtained by npm install -g jshint ) is no longer present so Syntastic just silently stopped checking syntax in my js files. 当然,这意味着jshint可执行文件(例如,通过npm install -g jshint )不再存在,因此Syntastic只是默默地停止了检查我js文件中的语法。

It didnt take me too long to notice, but I'd like to be able to know about this change. 我花了很长时间才注意到,但是我希望能够了解这一变化。 I'd like syntastic to display something (preferably in red) in the command statusline to the tune of Syntastic - cannot run jshint . 我希望syntastic在命令状态栏中显示某些内容(最好以红色显示),以符合Syntastic - cannot run jshint

The simplest solution would be to edit the file 最简单的解决方案是编辑文件

syntastic/syntax_checkers/javascript/jshint.vim

And change the function from 并从

function! SyntaxCheckers_javascript_jshint_IsAvailable()
    return executable('jshint')
endfunction

to

function! SyntaxCheckers_javascript_jshint_IsAvailable()
    if executable('jshint') != 1 
        echohl Error
        echo "Syntastic - cannot run jshint" 
        echohl None
    endif
    return executable('jshint')
endfunction

echohl sets the highlight color of echo to the hightlight group Error (which is most likely red but it may not be). echohl将回显的突出显示颜色设置为高光组“错误”(很可能是红色,但可能不是红色)。 Then it prints out the message you want to print when you save. 然后,它会在您保存时打印出您要打印的消息。 However this is not on the status line. 但是,这不在状态行上。

It seems Syntastic unfortunately lacks the ability to report missing checkers with the visibility one could expect. 不幸的是,Syntastic似乎缺乏报告可能具有可见性的缺少检查程序的功能。 Ideally such functionality should be added. 理想情况下,应添加此类功能。 For those not up for patching Syntastic, a possible workaround is to turn on debugging, search for strings known to be problematic and alert on them. 对于不适合打补丁Syntastic的用户,可能的解决方法是打开调试,搜索已知有问题的字符串并对其发出警报。 Eg by marking the first line with an error sign and bringing up the log in a new buffer. 例如,用错误符号标记第一行,然后在新缓冲区中调出日志。 I added that to my .vimrc as shown below. 我将其添加到我的.vimrc ,如下所示。

let g:syntastic_debug = 1

function! SyntasticCheckerNotFound()
  redir => messages
  silent messages
  redir END
  let pos = match(messages, "syntastic.*Checker.*is not available")
  if pos != -1
    new
    setlocal buftype=nofile
    put =messages
    sign place 1 line=1 name=SyntasticError buffer=1
"   goto pos
  endif
  let g:syntastic_debug = 0
endfunction

autocmd VimEnter <buffer> call SyntasticCheckerNotFound()

When running the function above on the VimEnter event, it only executes one time when vim is started and only on the first file provided as an argument. VimEnter事件上运行上述函数时,它仅在启动vim时执行一次,并且仅在作为参数提供的第一个文件上执行。 Far from perfect, but it could be good enough to decrease the time and effort required to determine broken linting due to missing checkers. 远非完美,但它可能足以减少确定由于缺少检查器而导致的棉绒断裂所需的时间和精力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM