From 8891b7c349328120e5ec3f8022399f884a67e088 Mon Sep 17 00:00:00 2001 From: Ye Jingchen Date: Fri, 28 Sep 2018 03:26:57 +0800 Subject: [PATCH] Move ccls functions to autoload/ale/handler Tests are kept as-is. --- ale_linters/c/ccls.vim | 22 ++-------------------- ale_linters/cpp/ccls.vim | 22 ++-------------------- ale_linters/objc/ccls.vim | 22 ++-------------------- autoload/ale/handlers/ccls.vim | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 60 deletions(-) create mode 100644 autoload/ale/handlers/ccls.vim diff --git a/ale_linters/c/ccls.vim b/ale_linters/c/ccls.vim index d0fa566e..5dc2339f 100644 --- a/ale_linters/c/ccls.vim +++ b/ale_linters/c/ccls.vim @@ -4,29 +4,11 @@ call ale#Set('c_ccls_executable', 'ccls') call ale#Set('c_ccls_init_options', {}) -function! ale_linters#c#ccls#GetProjectRoot(buffer) abort - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') - endif - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') - endif - - return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' -endfunction - -function! ale_linters#c#ccls#GetInitializationOptions(buffer) abort - return ale#Var(a:buffer, 'c_ccls_init_options') -endfunction - call ale#linter#Define('c', { \ 'name': 'ccls', \ 'lsp': 'stdio', \ 'executable_callback': ale#VarFunc('c_ccls_executable'), \ 'command': '%e', -\ 'project_root_callback': 'ale_linters#c#ccls#GetProjectRoot', -\ 'initialization_options_callback': 'ale_linters#c#ccls#GetInitializationOptions', +\ 'project_root_callback': 'ale#handlers#ccls#GetProjectRoot', +\ 'initialization_options_callback':ale#VarFunc('c_ccls_init_options'), \}) diff --git a/ale_linters/cpp/ccls.vim b/ale_linters/cpp/ccls.vim index f1604f30..501fd685 100644 --- a/ale_linters/cpp/ccls.vim +++ b/ale_linters/cpp/ccls.vim @@ -4,29 +4,11 @@ call ale#Set('cpp_ccls_executable', 'ccls') call ale#Set('cpp_ccls_init_options', {}) -function! ale_linters#cpp#ccls#GetProjectRoot(buffer) abort - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') - endif - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') - endif - - return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' -endfunction - -function! ale_linters#cpp#ccls#GetInitializationOptions(buffer) abort - return ale#Var(a:buffer, 'cpp_ccls_init_options') -endfunction - call ale#linter#Define('cpp', { \ 'name': 'ccls', \ 'lsp': 'stdio', \ 'executable_callback': ale#VarFunc('cpp_ccls_executable'), \ 'command': '%e', -\ 'project_root_callback': 'ale_linters#cpp#ccls#GetProjectRoot', -\ 'initialization_options_callback': 'ale_linters#cpp#ccls#GetInitializationOptions', +\ 'project_root_callback': 'ale#handlers#ccls#GetProjectRoot', +\ 'initialization_options_callback': ale#VarFunc('cpp_ccls_init_options'), \}) diff --git a/ale_linters/objc/ccls.vim b/ale_linters/objc/ccls.vim index e6736df7..0aa6a5e5 100644 --- a/ale_linters/objc/ccls.vim +++ b/ale_linters/objc/ccls.vim @@ -4,29 +4,11 @@ call ale#Set('objc_ccls_executable', 'ccls') call ale#Set('objc_ccls_init_options', {}) -function! ale_linters#objc#ccls#GetProjectRoot(buffer) abort - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') - endif - - if empty(l:project_root) - let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') - endif - - return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' -endfunction - -function! ale_linters#objc#ccls#GetInitializationOptions(buffer) abort - return ale#Var(a:buffer, 'objc_ccls_init_options') -endfunction - call ale#linter#Define('objc', { \ 'name': 'ccls', \ 'lsp': 'stdio', \ 'executable_callback': ale#VarFunc('objc_ccls_executable'), \ 'command': '%e', -\ 'project_root_callback': 'ale_linters#objc#ccls#GetProjectRoot', -\ 'initialization_options_callback': 'ale_linters#objc#ccls#GetInitializationOptions', +\ 'project_root_callback': 'ale#handlers#ccls#GetProjectRoot', +\ 'initialization_options_callback': ale#VarFunc('objc_ccls_init_options'), \}) diff --git a/autoload/ale/handlers/ccls.vim b/autoload/ale/handlers/ccls.vim new file mode 100644 index 00000000..29dd6aed --- /dev/null +++ b/autoload/ale/handlers/ccls.vim @@ -0,0 +1,17 @@ +scriptencoding utf-8 +" Author: Ye Jingchen +" Description: Utilities for ccls + +function! ale#handlers#ccls#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + endif + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') + endif + + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction