Exemplo n.º 1
0
 def run_impl(self, arg):
     start = time.clock()
     self.build_cmd_output_file.truncate()
     cmd = "cd " + self.build_cmd_dir + " && " + self.build_cmd
     ret = subprocess.call(cmd, shell=True, stdout=self.build_cmd_output_file, stderr=self.build_cmd_output_file)
     end = time.clock()
     logging.info("Cmd '{0}' took {1}".format(cmd, end-start))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_ProjectBuilder_Apply('" + self.build_cmd_output_file.name + "')")
Exemplo n.º 2
0
 def run_impl(self, args):
     contents_filename = str(args[0])
     original_filename = str(args[1])
     compiler_args = list(str(args[2]).split())
     project_root_directory = str(args[3])
     start = time.clock()
     self.syntax_highlighter.generate_vim_syntax_file_from_clang(contents_filename, compiler_args, project_root_directory)
     end = time.clock()
     logging.info("Generating vim syntax for '{0}' took {1}.".format(original_filename, end-start))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeHighlighter_Apply('" + original_filename + "'" + ", '" + self.output_syntax_file + "')")
Exemplo n.º 3
0
 def __call__(self, args):
     filename, apply_fixes = args
     cmd = self.cmd + ' ' + filename + ' ' + str('-fix' if apply_fixes else '') + ' ' + self.compiler_options
     logging.info("Triggering clang-tidy over '{0}' with '{1}'".format(filename, cmd))
     with open(self.output_file.name, 'w') as f:
         start = time.clock()
         subprocess.call(cmd, shell=True, stdout=f)
         end = time.clock()
     logging.info("Clang-Tidy over '{0}' completed in {1}s.".format(filename, end-start))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_ClangTidy_Apply('" + self.output_file.name + "')")
Exemplo n.º 4
0
 def __startup_callback(self, args):
     self.config_file = args[0]
     compilation_database = args[1]
     root, ext = os.path.splitext(compilation_database)
     if ext == '.json':  # In case we have a JSON compilation database we simply use one
         self.compiler_options = '-p ' + compilation_database
         logging.info("clang-tidy will extract compiler flags from existing JSON database.")
     else:               # Otherwise we provide compilation flags inline
         with open(compilation_database) as f:
             self.compiler_options = '-- ' + f.read().replace('\n', ' ')
         logging.info("clang-tidy will use compiler flags given inline: '{0}'.".format(self.compiler_options))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_ClangTidy_StartCompleted()")
Exemplo n.º 5
0
    def __call__(self, diagnostics_iter, args):
        def clang_severity_to_quickfix_type(severity):
            # Clang severity | Vim Quickfix type
            # ----------------------------------
            #   Ignored = 0     0 ()
            #   Note    = 1     I (info)
            #   Warning = 2     W (warning)
            #   Error   = 3     E (error)
            #   Fatal   = 4     other ()
            # ----------------------------------
            if severity == 0:
                return '0'
            elif severity == 1:
                return 'I'
            elif severity == 2:
                return 'W'
            elif severity == 3:
                return 'E'
            elif severity == 4:
                return 'other'
            return '0'

        diagnostics = []
        if diagnostics_iter:
            for d in diagnostics_iter:
                diagnostics.append(
                    "{'filename': '" + str(args[1]) + "', " +
                    "'lnum': '" + str(d.location.line) + "', " +
                    "'col': '" + str(d.location.column) + "', " +
                    "'type': '" + clang_severity_to_quickfix_type(d.severity) + "', " +
                    "'text': '" + d.category_name + " | " + str(d.spelling).replace("'", r"") + "'}"
                )

                fixits = "Hint:"
                for f in d.fixits:
                    fixits += \
                        " Try using '" + str(f.value) + "' instead. [col=" + \
                        str(f.range.start.column) + ":" + str(f.range.end.column) + "]"
                        # TODO How to handle multiline quickfix entries? It would be nice show each fixit in its own line.

                if len(d.fixits):
                    diagnostics.append(
                        "{'filename': '" + str(args[1]) + "', " +
                        "'lnum': '" + str(d.location.line) + "', " +
                        "'col': '" + str(d.location.column) + "', " +
                        "'type': 'I', " +
                        "'text': '" + str(fixits).replace("'", r"") + "'}"
                    )

        YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeDiagnostics_Apply(" + str(diagnostics).replace('"', r"") + ")")
        logging.debug("Diagnostics: " + str(diagnostics))
Exemplo n.º 6
0
    def __init__(self, params):
        self.file_types_whitelist = params.file_types
        self.indexers = {}

        # Build a list of indexers which correspond to the given file types
        programming_languages = set()
        for file_type in self.file_types_whitelist:
            programming_languages.add(
                YavideUtils.file_type_to_programming_language(file_type))
        for programming_language in programming_languages:
            self.indexers[
                programming_language] = YavideSourceCodeIndexerFactory.getIndexer(
                    programming_language, params)

        # Setup the filesystem event monitoring
        self.event_handler = YavideFileSystemEventHandler(self)
        self.observer = Observer()
        self.observer.deamon = True
        self.observer.schedule(self.event_handler,
                               params.proj_root_directory,
                               recursive=True)

        # Print some debug information
        logging.info("File extension whitelist: {0}".format(
            self.file_types_whitelist))
        logging.info("Active indexers:")
        for prog_language in programming_languages:
            logging.info(
                "For [{0}] programming language:".format(prog_language))
            indexers = self.indexers[prog_language]
            if indexers:
                for indexer in indexers:
                    logging.info("\t\t {0}".format(indexer))
Exemplo n.º 7
0
    def __init__(self, params):
        self.file_types_whitelist = params.file_types
        self.indexers             = {}

        # Build a list of indexers which correspond to the given file types
        programming_languages = set()
        for file_type in self.file_types_whitelist:
            programming_languages.add(YavideUtils.file_type_to_programming_language(file_type))
        for programming_language in programming_languages:
            self.indexers[programming_language] = YavideSourceCodeIndexerFactory.getIndexer(programming_language, params)

        # Setup the filesystem event monitoring
        self.event_handler = YavideFileSystemEventHandler(self)
        self.observer = Observer()
        self.observer.deamon = True
        self.observer.schedule(self.event_handler, params.proj_root_directory, recursive=True)

        # Print some debug information
        logging.info("File extension whitelist: {0}".format(self.file_types_whitelist))
        logging.info("Active indexers:")
        for prog_language in programming_languages:
            logging.info("For [{0}] programming language:".format(prog_language))
            indexers = self.indexers[prog_language]
            if indexers:
                for indexer in indexers:
                    logging.info("\t\t {0}".format(indexer))
Exemplo n.º 8
0
    def __call__(self, tunit, clang_parser, args):
        def visitor(ast_node, ast_parent_node, client_data):
            if ast_node.location.file and ast_node.location.file.name == tunit.spelling:  # we're only interested in symbols from associated translation unit
                ast_node_id = client_data.clang_parser.get_ast_node_id(ast_node)
                if ast_node_id != ASTNodeId.getUnsupportedId():
                    highlight_rule = VimSyntaxGenerator.__tag_id_to_vim_syntax_group(ast_node_id) + " " + client_data.clang_parser.get_ast_node_name(ast_node)
                    client_data.vim_syntax_element.append(
                        "call matchaddpos('" +
                        str(VimSyntaxGenerator.__tag_id_to_vim_syntax_group(ast_node_id)) +
                        "', [[" +
                        str(client_data.clang_parser.get_ast_node_line(ast_node)) +
                        ", " +
                        str(client_data.clang_parser.get_ast_node_column(ast_node)) +
                        ", " +
                        str(len(client_data.clang_parser.get_ast_node_name(ast_node))) +
                        "]], -1)" +
                        "\n"
                    )
                else:
                    logging.debug("Unsupported token id: [{0}, {1}]: {2} '{3}'".format(
                            ast_node.location.line, ast_node.location.column,
                            ast_node.kind, client_data.clang_parser.get_ast_node_name(ast_node)
                        )
                    )
                return ChildVisitResult.RECURSE.value  # If we are positioned in TU of interest, then we'll traverse through all descendants
            return ChildVisitResult.CONTINUE.value  # Otherwise, we'll skip to the next sibling

        # Build Vim syntax highlight rules
        start = time.clock()
        vim_syntax_element = ['call clearmatches()\n']
        if tunit:
            client_data = collections.namedtuple('client_data', ['clang_parser', 'vim_syntax_element'])
            clang_parser.traverse(tunit.cursor, client_data(clang_parser, vim_syntax_element), visitor)

        # Write Vim syntax file
        vim_syntax_file = open(self.output_syntax_file, "w", 0)
        vim_syntax_file.writelines(vim_syntax_element)
        time_elapsed = time.clock() - start

        # Apply newly generated syntax rules
        YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeHighlighter_Apply('" + str(args[1]) + "'" + ", '" + self.output_syntax_file + "')")

        # Write some debug information
        clang_parser.dump_ast_nodes(tunit)

        # Log how long generating Vim syntax file took
        logging.info("Vim syntax generator for '{0}' took {1}.".format(str(args[1]), time_elapsed))
    def __startup_callback(self, args):
        project_root_directory = args[0]
        compiler_args_filename = args[1]

        # Instantiate source-code-model services with Clang parser configured
        self.parser        = ClangParser(compiler_args_filename, TranslationUnitCache(FifoCache(20)))
        self.clang_indexer = ClangIndexer(self.parser, project_root_directory, VimIndexer(self.yavide_instance))
        self.service = {
            0x0 : self.clang_indexer,
            0x1 : SyntaxHighlighter(self.parser, VimSyntaxGenerator(self.yavide_instance, "/tmp/yavideSyntaxFile.vim")),
            0x2 : Diagnostics(self.parser, VimQuickFixDiagnostics(self.yavide_instance)),
            0x3 : TypeDeduction(self.parser, VimTypeDeduction(self.yavide_instance)),
            0x4 : GoToDefinition(self.parser, self.clang_indexer.get_symbol_db(), VimGoToDefinition(self.yavide_instance)),
            0x5 : GoToInclude(self.parser, VimGoToInclude(self.yavide_instance))
        }

        YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeModel_StartCompleted()")
        logging.info("SourceCodeModel configured with: project root directory='{0}', compiler args='{1}'".format(project_root_directory, compiler_args_filename))
Exemplo n.º 10
0
    def __find_all_references(self, args):
        other_args, references = args
        quickfix_list = []
        for ref in references:
            quickfix_list.append("{'filename': '" + str(ref[0]) + "', " +
                                 "'lnum': '" + str(ref[1]) + "', " +
                                 "'col': '" + str(ref[2]) + "', " +
                                 "'type': 'I', " + "'text': '" +
                                 str(ref[4]).replace("'", r"''").rstrip() +
                                 "'}")

        with open(self.find_all_references_output, 'w', 0) as f:
            f.writelines(', '.join(item for item in quickfix_list))

        YavideUtils.call_vim_remote_function(
            self.yavide_instance,
            "Y_SrcCodeIndexer_FindAllReferencesCompleted('" +
            self.find_all_references_output + "')")
        logging.debug("References: " + str(quickfix_list))
Exemplo n.º 11
0
    def __call__(self, clang_parser, args):
        start = time.clock()

        # Build Vim syntax highlight rules
        vim_syntax_element = ['call clearmatches()\n']
        ast_node_list = clang_parser.get_ast_node_list()
        for ast_node in ast_node_list:
            ast_node_id = clang_parser.get_ast_node_id(ast_node)
            if ast_node_id != ASTNodeId.getUnsupportedId():
                highlight_rule = self.__tag_id_to_vim_syntax_group(ast_node_id) + " " + clang_parser.get_ast_node_name(ast_node)
                vim_syntax_element.append(
                    "call matchaddpos('" +
                    str(self.__tag_id_to_vim_syntax_group(ast_node_id)) +
                    "', [[" +
                    str(clang_parser.get_ast_node_line(ast_node)) +
                    ", " +
                    str(clang_parser.get_ast_node_column(ast_node)) +
                    ", " +
                    str(len(clang_parser.get_ast_node_name(ast_node))) +
                    "]], -1)" +
                    "\n"
                )
            else:
                logging.debug("Unsupported token id: [{0}, {1}]: {2} '{3}'".format(
                        ast_node.location.line, ast_node.location.column, 
                        ast_node.kind, clang_parser.get_ast_node_name(ast_node)
                    )
                )

        # Write Vim syntax file
        vim_syntax_file = open(self.output_syntax_file, "w", 0)
        vim_syntax_file.writelines(vim_syntax_element)
        time_elapsed = time.clock() - start

        # Apply newly generated syntax rules
        YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeHighlighter_Apply('" + clang_parser.filename + "'" + ", '" + self.output_syntax_file + "')")

        # Write some debug information
        clang_parser.dump_ast_nodes()

        # Log how long generating Vim syntax file took
        logging.info("Vim syntax generator for '{0}' took {1}.".format(clang_parser.filename, time_elapsed))
Exemplo n.º 12
0
 def update(self, filename, event_type):
     file_type = os.path.splitext(filename)[1]
     if file_type in self.file_types_whitelist:
         programming_language = YavideUtils.file_type_to_programming_language(file_type)
         if programming_language in self.indexers:
             logging.info("Filename: '{0}' Event_type: '{1}' Programming lang: '{2}'".format(
                 os.path.basename(filename), event_type, programming_language)
             )
             indexers = self.indexers[programming_language]
             for indexer in indexers:
                 indexer.update(filename, event_type)
Exemplo n.º 13
0
    def __find_all_references(self, args):
        other_args, references = args
        quickfix_list = []
        for ref in references:
            quickfix_list.append(
                "{'filename': '" + str(ref[0]) + "', " +
                "'lnum': '" + str(ref[1]) + "', " +
                "'col': '" + str(ref[2]) + "', " +
                "'type': 'I', " +
                "'text': '" + str(ref[4]).replace("'", r"''").rstrip() + "'}"
            )

        with open(self.find_all_references_output, 'w', 0) as f:
            f.writelines(', '.join(item for item in quickfix_list))

        YavideUtils.call_vim_remote_function(
            self.yavide_instance,
            "Y_SrcCodeIndexer_FindAllReferencesCompleted('" + self.find_all_references_output + "')"
        )
        logging.debug("References: " + str(quickfix_list))
Exemplo n.º 14
0
 def update(self, filename, event_type):
     file_type = os.path.splitext(filename)[1]
     if file_type in self.file_types_whitelist:
         programming_language = YavideUtils.file_type_to_programming_language(
             file_type)
         if programming_language in self.indexers:
             logging.info(
                 "Filename: '{0}' Event_type: '{1}' Programming lang: '{2}'"
                 .format(os.path.basename(filename), event_type,
                         programming_language))
             indexers = self.indexers[programming_language]
             for indexer in indexers:
                 indexer.update(filename, event_type)
Exemplo n.º 15
0
def do_init():
    # Find first available port number
    port = YavideUtils.get_available_port(
                int(vim.eval('g:YAVIDE_SOURCE_CODE_INDEXER_PORT')),
                65535
    )

    # Save it in environment variable for later usage
    var = 'let g:YAVIDE_SOURCE_CODE_INDEXER_PORT = ' + str(port)
    vim.command(var)

    # Build a command string
    cmd  = 'python '
    cmd += vim.eval('g:YAVIDE_SOURCE_CODE_INDEXER')
    cmd += ' '
    cmd += str(port)

    # Run the indexer server listening on a given port
    new_env = os.environ.copy()
    new_env['PYTHONPATH'] = vim.eval('g:YAVIDE_CORE_DIRECTORY')
    subprocess.Popen(shlex.split(cmd), shell=False, env=new_env)
Exemplo n.º 16
0
 def db_reset(self):
     function = 'Y_SrcNav_ReInit()'
     YavideUtils.call_vim_remote_function(self.yavide_instance, function)
     logging.info("Resetting the db connection: '{0}'".format(cmd))
Exemplo n.º 17
0
 def db_add(self):
     cmd = ':cscope add ' + os.path.join(self.root_directory,
                                         self.tags_filename)
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Adding a new db connection: '{0}'".format(cmd))
Exemplo n.º 18
0
 def db_set_default_params(self):
     cmd = ':set cscopetag | set cscopetagorder=0'
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Setting default parameters: '{0}'".format(cmd))
Exemplo n.º 19
0
 def __call__(self, include, args):
     YavideUtils.call_vim_remote_function(
         self.yavide_instance,
         "Y_SrcCodeNavigation_GoToIncludeCompleted('" + str(include) + "')")
     logging.info("include filename = " + str(include))
Exemplo n.º 20
0
 def __drop_single_file(self, args):
     YavideUtils.call_vim_remote_function(
         self.yavide_instance, "Y_SrcCodeIndexer_DropSingleFileCompleted()")
Exemplo n.º 21
0
 def db_reset(self):
     cmd = ':cscope reset'
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Resetting the db connection: '{0}'".format(cmd))
Exemplo n.º 22
0
 def db_add(self):
     cmd = ':cscope add ' + os.path.join(self.root_directory, self.tags_filename)
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Adding a new db connection: '{0}'".format(cmd))
Exemplo n.º 23
0
 def __call__(self, include, args):
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeNavigation_GoToIncludeCompleted('" + str(include) + "')")
     logging.info("include filename = " + str(include))
Exemplo n.º 24
0
 def __run_on_directory(self, args):
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_RunOnDirectoryCompleted()")
Exemplo n.º 25
0
 def __drop_all(self, args):
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_DropAllCompleted()")
Exemplo n.º 26
0
 def __startup_callback(self, args):
     self.build_cmd_dir = args[0]
     self.build_cmd_output_file = tempfile.NamedTemporaryFile(prefix='yavide', suffix='build', delete=True)
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_ProjectBuilder_StartCompleted()")
     logging.info("Args = {0}, build_cmd_output_file = {1}.".format(args, self.build_cmd_output_file.name))
Exemplo n.º 27
0
 def run_impl(self, filename):
     cmd = self.format_cmd + " " + filename
     ret = subprocess.call(cmd, shell=True)
     logging.info("Filename = {0}. Cmd = {1}".format(filename, cmd))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeFormatter_Apply('" + filename + "')")
Exemplo n.º 28
0
 def __run_on_directory(self, args):
     YavideUtils.call_vim_remote_function(
         self.yavide_instance, "Y_SrcCodeIndexer_RunOnDirectoryCompleted()")
Exemplo n.º 29
0
 def db_set_default_params(self):
     cmd = ':set cscopetag | set cscopetagorder=0'
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Setting default parameters: '{0}'".format(cmd))
Exemplo n.º 30
0
 def __shutdown_callback(self, args):
     reply_with_callback = bool(args)
     if reply_with_callback:
         YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_ClangTidy_StopCompleted()")
Exemplo n.º 31
0
 def db_reset(self):
     function = 'Y_SrcNav_ReInit()'
     YavideUtils.call_vim_remote_function(self.yavide_instance, function)
     logging.info("Resetting the db connection: '{0}'".format(cmd))
Exemplo n.º 32
0
 def __call__(self, type_spelling, args):
     YavideUtils.call_vim_remote_function(
         self.yavide_instance,
         "Y_SrcCodeTypeDeduction_Apply('" + str(type_spelling) + "')")
     logging.debug("type_spelling = " + str(type_spelling))
Exemplo n.º 33
0
 def __call__(self, type_spelling, args):
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeTypeDeduction_Apply('" + str(type_spelling) + "')")
     logging.debug("type_spelling = " + str(type_spelling))
Exemplo n.º 34
0
 def __drop_all(self, args):
     YavideUtils.call_vim_remote_function(
         self.yavide_instance, "Y_SrcCodeIndexer_DropAllCompleted()")
Exemplo n.º 35
0
 def __drop_single_file(self, args):
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_DropSingleFileCompleted()")
 def run_impl(self, filename):
     start = time.clock()
     self.syntax_highlighter.generate_vim_syntax_file(filename)
     end = time.clock()
     logging.info("Generating vim syntax for '{0}' took {1}.".format(filename, end-start))
     YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeHighlighter_Apply('" + filename + "'" + ", '" + self.output_syntax_file + "')")
Exemplo n.º 37
0
 def db_reset(self):
     cmd = ':cscope reset'
     YavideUtils.send_vim_remote_command(self.yavide_instance, cmd)
     logging.info("Resetting the db connection: '{0}'".format(cmd))
Exemplo n.º 38
0
 def db_reset(self):
     function = "Y_SrcNav_ReInit()"
     YavideUtils.call_vim_remote_function(self.yavide_instance, function)
     logging.info("Resetting the db connection")