Fix error when parsing compile_commands for c languages #2272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This little error caused that when parsing compile_commands json, the
filename was used to fetch entries in dir_lookup dictionary (dirname is supposed to be used), hence, when
adding new json commands, it never found anything in dir_lookup and
instead rewrote the previous entry. Hence, the dir_lookup always
contained list of only one compile_command per directory instead of all
compile_commands for given directory.
Someone evidently didn't check his/her code when implementing the parse_compile_command code and this super minor code inaccuracy caused me quite a headache whenever my c++ project had multiple compile commands per one directory.
Just to be clear what is fixed here: before, in line 205 in
c.vim
the json entry for filename was fetched and then json entry for directory name was appended to that entry. However, since the dictionary used here was the one that used directory names as keys, the json entry for filename was always empty. What wasn't empty was entry with the same directory key, but that entry was overwritten with the new json entry for the same directory. Hence, in the line 205 the json entry for the given dirname was always overwriting the previous entry instead of appending it.