diff --git a/.vim/plugin/cdg.py b/.vim/plugin/cdg.py index 9efa317..9e9c601 100755 --- a/.vim/plugin/cdg.py +++ b/.vim/plugin/cdg.py @@ -4,7 +4,7 @@ import json import sys import re -import os +from os import getcwd '''A simple compilation database generator, or cdg in short. @@ -12,11 +12,11 @@ It works by parsing the output of the GNU make command.''' file_name_regex = re.compile(r"[\w./+\-]+\.(s|cc?|cpp|cxx)\b", re.IGNORECASE) -enter_dir_regex = re.compile(r"^\s*make(?:\[\d+\])?: Entering directory [`\'\"](?P.*)[`\'\"]\s*$", +enter_dir_regex = re.compile(r"^\s*(?:make|ninja)(?:\[\d+\])?: Entering directory [`\'\"](?P.*)[`\'\"]\s*$", re.MULTILINE) -leave_dir_regex = re.compile(r"^\s*make(?:\[\d+\])?: Leaving directory .*$", +leave_dir_regex = re.compile(r"^\s*(?:make|ninja)(?:\[\d+\])?: Leaving directory .*$", re.MULTILINE) -compilers_regex = re.compile(r'\b(g?cc|[gc]\+\+|clang\+?\+?|icecc|s?ccache)\s') +compilers_regex = re.compile(r'\b(g?cc|[gc]\+\+|clang\+?\+?|icecc|s?ccache)(?:.exe)?"?\s') def parse(make_output): @@ -49,11 +49,17 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html # look backward and discard anything before delimiters i = match.start() - while i > 0: - j = i - 1 - if line[j] in (' ', '\t', '\n', ';', '&'): - break - i -= 1 + if line[match.start():match.end()].rstrip()[-1] == '"': + while i > 0: + i -= 1 + if line[i] == '"' and (i == 0 or line[i-1] != '\\'): + break + else: + while i > 0: + j = i - 1 + if line[j] in (' ', '\t', '\n', ';', '&'): + break + i -= 1 line = line[i:] file_match = file_name_regex.search(line) @@ -63,7 +69,7 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html # To workaround that there is no "entering directory..." if not pwd: - pwd = os.getcwd() + pwd = getcwd() path_stack.append(pwd) # Special handling for projects like Redis,