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 + "')")
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))
def __startup_callback(self, args): self.config_file = args self.format_cmd += self.config_file YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeFormatter_StartCompleted()") logging.info("Config_file = {0}. Format_cmd = {1}".format( self.config_file, self.format_cmd))
def __call__(self, args): filename, line, column = args YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeNavigation_GoToDefinitionCompleted('" + filename + "', " + str(line) + ", " + str(column) + ")") logging.info('Definition found at {0} [{1}, {2}]'.format( filename, line, column))
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 + "')")
def __call__(self, arg): start = time.clock() build_cmd = arg[0] self.build_cmd_output_file.truncate() cmd = "cd " + self.build_cmd_dir + " && " + 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 + "')")
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 + "')")
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 + "')")
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()")
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))
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))
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 + "')")
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))
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))
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))
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))
def __drop_all(self, args): YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_DropAllCompleted()")
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))
def __call__(self, include, args): YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeNavigation_GoToIncludeCompleted('" + str(include) + "')") logging.info("include filename = " + str(include))
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))
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 + "')")
def __drop_all(self, args): YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeIndexer_DropAllCompleted()")
def __drop_single_file(self, args): YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeIndexer_DropSingleFileCompleted()")
def __call__(self, include, args): YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeNavigation_GoToIncludeCompleted('" + str(include) + "')") logging.info("include filename = " + str(include))
def db_reset(self): function = "Y_SrcNav_ReInit()" YavideUtils.call_vim_remote_function(self.yavide_instance, function) logging.info("Resetting the db connection")
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))
def __drop_single_file(self, args): YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_DropSingleFileCompleted()")
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()")
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))
def __run_on_directory(self, args): YavideUtils.call_vim_remote_function( self.yavide_instance, "Y_SrcCodeIndexer_RunOnDirectoryCompleted()")
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 + "')")
def __run_on_directory(self, args): YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeIndexer_RunOnDirectoryCompleted()")