summaryrefslogtreecommitdiff
path: root/ale_linters/hack
diff options
context:
space:
mode:
authorFred Emmott <fe@fb.com>2018-07-27 13:50:59 -0700
committerFred Emmott <fe@fb.com>2018-08-02 11:28:56 -0700
commit238201805dd23ea422a107b3170de7892335137b (patch)
treee214989c1a7dd048a0d162dc27d70a92479a62db /ale_linters/hack
parent5f024eda093dcce62159a6f262ffb084ccce4e51 (diff)
downloadale-238201805dd23ea422a107b3170de7892335137b.zip
Split Hack out from PHP, modernize
fixes #1738 - Replace previous `hh_client` usage with LSP client - Add `HHAST` linter - Split Hack from PHP: Hack is increasingly diverging from PHP: - Hack tools do not understand PHP - Most PHP tools do not handle Hack code well (including vim's syntax highightling files) - http://github.com/hhvm/vim-hack now sets filetype to `hack`
Diffstat (limited to 'ale_linters/hack')
-rw-r--r--ale_linters/hack/hack.vim27
-rw-r--r--ale_linters/hack/hhast.vim34
2 files changed, 61 insertions, 0 deletions
diff --git a/ale_linters/hack/hack.vim b/ale_linters/hack/hack.vim
new file mode 100644
index 00000000..0253767a
--- /dev/null
+++ b/ale_linters/hack/hack.vim
@@ -0,0 +1,27 @@
+" Author: Fred Emmott <fe@fb.com>
+" Description: Hack support via `hack lsp`
+
+call ale#Set('hack_hhclient_executable', 'hh_client')
+
+function! ale_linters#hack#hack#GetProjectRoot(buffer) abort
+ let l:hhconfig = ale#path#FindNearestFile(a:buffer, '.hhconfig')
+ return !empty(l:hhconfig) ? fnamemodify(l:hhconfig, ':h') : ''
+endfunction
+
+function! ale_linters#hack#hack#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'hack_hhclient_executable')
+endfunction
+
+
+function! ale_linters#hack#hack#GetCommand(buffer) abort
+ let l:executable = ale_linters#hack#hack#GetExecutable(a:buffer)
+ return ale#Escape(l:executable).' lsp --from vim-ale'
+endfunction
+
+call ale#linter#Define('hack', {
+\ 'name': 'hack',
+\ 'lsp': 'stdio',
+\ 'executable_callback': 'ale_linters#hack#hack#GetExecutable',
+\ 'command_callback': 'ale_linters#hack#hack#GetCommand',
+\ 'project_root_callback': 'ale_linters#hack#hack#GetProjectRoot',
+\})
diff --git a/ale_linters/hack/hhast.vim b/ale_linters/hack/hhast.vim
new file mode 100644
index 00000000..8ff5a962
--- /dev/null
+++ b/ale_linters/hack/hhast.vim
@@ -0,0 +1,34 @@
+" Author: Fred Emmott <fe@fb.com>
+" Description: Hack support via `hhast lsp`
+
+call ale#Set('hack_hhast_executable', 'vendor/bin/hhast-lint')
+
+function! ale_linters#hack#hhast#GetProjectRoot(buffer) abort
+ let l:root = ale_linters#hack#hack#GetProjectRoot(a:buffer)
+ if empty(l:root)
+ return ''
+ endif
+ let l:hhast_config = findfile('hhast-lint.json', l:root)
+ return !empty(l:hhast_config) ? l:root : ''
+endfunction
+
+function! ale_linters#hack#hhast#GetExecutable(buffer) abort
+ let l:root = ale_linters#hack#hhast#GetProjectRoot(a:buffer)
+ let l:relative = ale#Var(a:buffer, 'hack_hhast_executable')
+ let l:absolute = findfile(l:relative, l:root)
+ return !empty(l:absolute) ? l:absolute : ''
+endfunction
+
+
+function! ale_linters#hack#hhast#GetCommand(buffer) abort
+ let l:executable = ale_linters#hack#hhast#GetExecutable(a:buffer)
+ return ale#Escape(l:executable).' --mode lsp --from vim-ale'
+endfunction
+
+call ale#linter#Define('hack', {
+\ 'name': 'hhast',
+\ 'lsp': 'stdio',
+\ 'executable_callback': 'ale_linters#hack#hhast#GetExecutable',
+\ 'command_callback': 'ale_linters#hack#hhast#GetCommand',
+\ 'project_root_callback': 'ale_linters#hack#hhast#GetProjectRoot',
+\})