{"action":"created","issue":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1871","labels_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1871/labels{/name}","comments_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1871/comments","events_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1871/events","html_url":"https://github.com/Valloric/YouCompleteMe/issues/1871","id":124535869,"number":1871,"title":"Missing support for editing nested header files","user":{"login":"odabrunz","id":2596130,"avatar_url":"https://avatars.githubusercontent.com/u/2596130?v=3","gravatar_id":"","url":"https://api.github.com/users/odabrunz","html_url":"https://github.com/odabrunz","followers_url":"https://api.github.com/users/odabrunz/followers","following_url":"https://api.github.com/users/odabrunz/following{/other_user}","gists_url":"https://api.github.com/users/odabrunz/gists{/gist_id}","starred_url":"https://api.github.com/users/odabrunz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odabrunz/subscriptions","organizations_url":"https://api.github.com/users/odabrunz/orgs","repos_url":"https://api.github.com/users/odabrunz/repos","events_url":"https://api.github.com/users/odabrunz/events{/privacy}","received_events_url":"https://api.github.com/users/odabrunz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-01T07:56:55Z","updated_at":"2016-01-01T18:10:39Z","closed_at":null,"body":"For projects that have nested header files, for example\r\n```c\r\n  top.h:\r\n    /* ... some declarations and definitions ... */\r\n    #include \"nested1.h\"\r\n    /* ... more declarations and definitions ... */\r\n    #include \"nested2.h\"\r\n    ...\r\n```\r\nwhen editing one of the nested header files (e.g. ```nested1.h```), there seems to be no way to configure the compiler used by YCM to include exactly the parts of the top level header file that come before the inclusion of the nested header file, but not the parts that come after it.\r\n\r\nThe idea behind nested header files is that the top level header file (```top.h```) is typically the only project header file that needs to be included in a ```.c``` file, while some large and distinguishable sections of a large header can be divided into several files, e.g. function prototypes separate from the definition of global types and structures.\r\n\r\nWhen ```nested1.h``` is edited, YCM tries to compile it.  But no flags given to the compiler can tell it to only include ```top.h``` up to just before the ```#include \"nested1.h\"```, but not beyond.  In particular, ```nested1.h``` itself should not be included before compiling ```nested1.h```, and also nothing after it should be included.\r\n\r\nThis is needed so that declarations and definitions (and ```#undef```s) that appear in ```top.h``` **after** ```#include \"nested1.h\"``` are not falsely included **before** ```nested1.h```, as during actual compilation of the project these declarations and definitions would also not be made before including ```nested1.h```.\r\n\r\nOne idea to do this is to let ```ycm_extra_conf.py``` provide an alternative text to compile.\r\n\r\nSo, in the above example, when the ```FlagsForFile()``` function is asked for the compile flags for a nested header file ```nestedX.h```, it could be smart enough to also provide an alternative text to compile instead of ```nestedX.h```: it copies the text of ```top.h```, truncates it after the ```#include \"nestedX.h\"```, and passes that text back (along with the compiler flags) to YCM to compile.\r\n\r\nThis does not seem to be too hackish, because the preprocessor also must be able to recognize ```#include``` directives easily, without full knowledge of C syntax, so recognition of ```#include``` directives could be implemented relatively easily.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/comments/168325009","html_url":"https://github.com/Valloric/YouCompleteMe/issues/1871#issuecomment-168325009","issue_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1871","id":168325009,"user":{"login":"odabrunz","id":2596130,"avatar_url":"https://avatars.githubusercontent.com/u/2596130?v=3","gravatar_id":"","url":"https://api.github.com/users/odabrunz","html_url":"https://github.com/odabrunz","followers_url":"https://api.github.com/users/odabrunz/followers","following_url":"https://api.github.com/users/odabrunz/following{/other_user}","gists_url":"https://api.github.com/users/odabrunz/gists{/gist_id}","starred_url":"https://api.github.com/users/odabrunz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odabrunz/subscriptions","organizations_url":"https://api.github.com/users/odabrunz/orgs","repos_url":"https://api.github.com/users/odabrunz/repos","events_url":"https://api.github.com/users/odabrunz/events{/privacy}","received_events_url":"https://api.github.com/users/odabrunz/received_events","type":"User","site_admin":false},"created_at":"2016-01-01T18:10:39Z","updated_at":"2016-01-01T18:10:39Z","body":"Difficulties:\r\n\r\nWhile trying this, I realized that truncating a header file does not work: ```#ifdef```s must be closed. But maybe the compilation error is not a problem, as it appears on a line after the nested header file is included. This may need more investigation.\r\n\r\nAlso, some header files may be nested in multiple other headers, depending on the configuration of the project:\r\n```c\r\n  top_win32.h:\r\n    /* ... some declarations and definitions ... */\r\n    #include \"common.h\"\r\n    ...\r\n\r\n  top_win16.h:\r\n    /* ... some declarations and definitions ... */\r\n    #include \"common.h\"\r\n    ...\r\n```\r\nThis makes automated generation of a replacement file depend on the current project configuration, which may be difficult to detect."}}