From 56658fd3ada284a373afffb49b0ec2d66ad00445 Mon Sep 17 00:00:00 2001 From: Ye Jingchen Date: Wed, 26 Sep 2018 20:09:37 +0800 Subject: Add ccls support for C/C++/ObjC --- ale_linters/c/ccls.vim | 30 ++++++++++++++++++++++++++++++ ale_linters/cpp/ccls.vim | 30 ++++++++++++++++++++++++++++++ ale_linters/objc/ccls.vim | 30 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 ale_linters/c/ccls.vim create mode 100644 ale_linters/cpp/ccls.vim create mode 100644 ale_linters/objc/ccls.vim (limited to 'ale_linters') diff --git a/ale_linters/c/ccls.vim b/ale_linters/c/ccls.vim new file mode 100644 index 00000000..0aad0a3d --- /dev/null +++ b/ale_linters/c/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for C + +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') + elseif 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', +\}) diff --git a/ale_linters/cpp/ccls.vim b/ale_linters/cpp/ccls.vim new file mode 100644 index 00000000..e63849c3 --- /dev/null +++ b/ale_linters/cpp/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for C++ + +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') + elseif 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', +\}) diff --git a/ale_linters/objc/ccls.vim b/ale_linters/objc/ccls.vim new file mode 100644 index 00000000..f354c7d7 --- /dev/null +++ b/ale_linters/objc/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for Objective-C + +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') + elseif 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', +\}) -- cgit v1.2.3