Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support reading C/C++ including path from EditorConfig files. #287

Closed
wants to merge 1 commit into from

3 participants

Hong Xu Mihai Sucan LCD 047
Hong Xu

Add discussed in #220 and #215,

As long as there is no global architecture for configuration files for syntax checkers this one has to do the trick I guess. Comments and further suggestions are appreciated anyways.

This pull request will support EditorConfig as the global architecture of configuration for editors and IDEs, for the same purpose as #220.

EditorConfig has been used by many projects, and is supported on many editors/IDEs, so I believe it is time to include this feature in syntastic.

This pull request read a property called c_include_path in the .editorconfig files, which will be added in the official standard in the future. This feature also depends on the EditorConfig Vim plugin, and takes use of its hook mechanism, which was first introduced in editorconfig/editorconfig#45.

Wish this could be included. Thanks!

Mihai Sucan

I would also like editorconfig support in syntastic. Can we get something like this for other syntax checkers as well? Specifically, i would like to define custom options for jshint using editorconfig.

LCD 047
Collaborator

@mihaisucan: I'm afraid this is unlikely to happen. EditorConfig is not a generic config format, using it for all the 140+ checkers currently supported by syntastic would be a little far fetched.

These days syntastic has its own notion of config files. They are mostly generic, but they do have their own set of problems. And those too are used only for a small subset of the existing checkers. Making all checkers search for this kind of config files would be possible in principle, but not particularly useful in practice, since most checkers already solve that problem on their own, one way or another. Case in point, jshint looks for .jshintrc in the same directory as the file being checked, then upwards.

LCD 047 lcd047 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
52 autoload/syntastic/c.vim
View
@@ -101,6 +101,58 @@ function! syntastic#c#ReadConfig(file)
return join(parameters, ' ')
endfunction
+let s:include_path = ''
+
+function! syntastic#c#EditorConfigHook(config)
+ if has_key(a:config, 'c_include_path')
+ let s:include_path = a:config['c_include_path']
+ else
+ let s:include_path = ''
+ endif
+endfunction
+
+function! syntastic#c#ReadEditorConfigIncludePath()
+ " Load the include path from EditorConfig
+
+ " If this is the first time to run this function, add the hook
+ if !exists('s:EditorConfig_hook')
+ silent! call editorconfig#AddNewHook(function('syntastic#c#EditorConfigHook'))
+ let s:EditorConfig_hook = 1
+ endif
+
+ silent! EditorConfigReload " Force reload to trigger the Hook
+
+ let l:include_args = ''
+ if !empty(s:include_path)
+
+ let l:pos0 = 0
+ let l:pos1 = -1
+
+ " s:include_path is a string of include paths separated by ':'
+ while 1
+ if l:pos0 >= strlen(s:include_path)
+ break
+ endif
+
+ let l:pos1 = match(s:include_path, ':', l:pos0)
+
+ if l:pos1 < 0
+ break
+ endif
+
+ let l:include_args .= ' -I ' . "'" . strpart(s:include_path, l:pos0, l:pos1 - l:pos0) . "'"
+
+ let l:pos0 = l:pos1 + 1
+ endwhile
+
+ if l:pos0 < strlen(s:include_path)
+ let l:include_args .= ' -I ' . "'" . strpart(s:include_path, l:pos0) . "'"
+ endif
+ endif
+
+ return l:include_args
+endfunction
+
" search the first 100 lines for include statements that are
" given in the handlers dictionary
function! syntastic#c#SearchHeaders()
1  syntax_checkers/c.vim
View
@@ -126,6 +126,7 @@ function! SyntaxCheckers_c_GetLocList()
" add optional config file parameters
let makeprg .= ' '.syntastic#c#ReadConfig(g:syntastic_c_config_file)
+ let makeprg .= ' ' . syntastic#c#ReadEditorConfigIncludePath()
" process makeprg
let errors = SyntasticMake({ 'makeprg': makeprg,
1  syntax_checkers/cpp.vim
View
@@ -114,6 +114,7 @@ function! SyntaxCheckers_cpp_GetLocList()
" add optional config file parameters
let makeprg .= ' ' . syntastic#c#ReadConfig(g:syntastic_cpp_config_file)
+ let makeprg .= ' ' . syntastic#c#ReadEditorConfigIncludePath()
" process makeprg
let errors = SyntasticMake({ 'makeprg': makeprg,
Something went wrong with that request. Please try again.