summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-28 11:05:14 +0100
committerw0rp <devw0rp@gmail.com>2017-05-28 11:05:14 +0100
commit945ed7d4e7d801108103e97ac41063a85c3b4c5d (patch)
treec41908add632730fa47a2196492afd2dc944912b /autoload
parent505b591b22c002dec04abe98c5cf1575c4b707a0 (diff)
downloadale-945ed7d4e7d801108103e97ac41063a85c3b4c5d.zip
Add untested code for searching for C and C++ headers in basic projects
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/c.vim59
1 files changed, 59 insertions, 0 deletions
diff --git a/autoload/ale/handlers/c.vim b/autoload/ale/handlers/c.vim
new file mode 100644
index 00000000..d80f5e74
--- /dev/null
+++ b/autoload/ale/handlers/c.vim
@@ -0,0 +1,59 @@
+" Author: w0rp <devw0rp@gmail.com>
+" Desciption: Functions for integrating with C and C++ compilers.
+
+function! ale#handlers#c#FindProjectRoot(buffer) abort
+ for l:project_filename in ['Makefile', 'CMakeLists.txt']
+ let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename)
+
+ if !empty(l:full_path)
+ return fnamemodify(l:full_path, ':h')
+ endif
+ endfor
+
+ return ''
+endfunction
+
+" Given a buffer number, search for a project root, and output a List
+" of directories to include based on some heuristics.
+"
+" For projects with headers in the project root, the project root will
+" be returned.
+"
+" For projects with an 'include' directory, that directory will be returned.
+function! ale#handlers#c#FindLocalHeaderPaths(buffer) abort
+ let l:project_root = ale#handlers#c#FindProjectRoot(a:buffer)
+
+ if empty(l:project_root)
+ return []
+ endif
+
+ " See if we can find .h files directory in the project root.
+ " If we can, that's our include directory.
+ if !empty(globpath(l:project_root, '*.h', 0))
+ return [l:project_root]
+ endif
+
+ " Look for .hpp files too.
+ if !empty(globpath(l:project_root, '*.hpp', 0))
+ return [l:project_root]
+ endif
+
+ " If we find an 'include' directory in the project root, then use that.
+ if isdirectory(l:project_root . '/include')
+ return [simplify(l:project_root . '/include')]
+ endif
+
+ return []
+endfunction
+
+" Given a List of include paths, create a string containing the -I include
+" options for those paths, with the paths escaped for use in the shell.
+function! ale#handlers#c#IncludeOptions(include_paths) abort
+ let l:option_list = []
+
+ for l:path in a:include_paths
+ call add(l:option_list, '-I' . ale#Escape(l:path))
+ endfor
+
+ return join(l:option_list)
+endfunction