Sublime Text安裝SublimeLinter進行PHP程式碼檢查

Sublime Text是個輕量又強大的程式碼編輯器
其它的好插件我不說了,但是安裝SublimeLinter時遇到一些問題,所以寫下來記錄一下。

照網路上的部驟安裝完後,也設定了Preferences->Package Settings->SublimeLinter->Settings – User
未命名-2

但是在程式碼輸入完儲存時,偵錯依然沒有作用

開啟Console後,發現有一些錯誤訊息,原來跟儲存檔案時編碼有關…._

類似

Traceback (most recent call last):
File ".\sublime_plugin.py", line 190, in on_post_save
File ".\sublime_plugin.py", line 154, in run_timed_function
File ".\sublime_plugin.py", line 189, in
File ".\SublimeLinter.py", line 744, in on_post_save
File ".\SublimeLinter.py", line 611, in reload_view_module
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 9: ordinal not in range(128)

google大神拜了之後,找到我一輩子也無法自己發現的解決方案

1.Preferences->Browser Packages

2.找到SublimeLinter/SublimeLinter.py 並開啟它

3.找到這個function

def reload_view_module(view):
 for name, linter in LINTERS.items():
 module = sys.modules[linter.__module__]

if module.__file__.encode('utf-8') == (view.file_name() or '').encode('utf-8'):
 print 'SublimeLinter: reloading language:', linter.language
 MOD_LOAD.reload_module(module)
 lint_views(linter)
 break

4.將這個function連內容替換如下

def reload_view_module(view):
    for name, linter in LINTERS.items():
        module = sys.modules[linter.__module__]
        module_file = module.__file__
        if isinstance(module_file, unicode):
            module_file = module_file.encode('utf-8')
        if module_file == view.file_name().encode('utf-8'):
            print 'SublimeLinter: reloading language:', linter.language
            MOD_LOAD.reload_module(module)
            lint_views(linter)
            break

鏘鏘!!!大功告成,有錯誤訊息了!!!

未命名-2

發表迴響