def _GetFlagsFromExtraConfOrDatabase(self, filename, client_data): # Load the flags from the extra conf file if one is found and is not global. module = extra_conf_store.ModuleForSourceFile(filename) if module and not extra_conf_store.IsGlobalExtraConfModule(module): try: return _CallExtraConfFlagsForFile(module, filename, client_data) except IgnoreExtraConf: pass # Load the flags from the compilation database if any. database = self.LoadCompilationDatabase(filename) if database: return self._GetFlagsFromCompilationDatabase(database, filename) # Load the flags from the global extra conf if set. if module: try: return _CallExtraConfFlagsForFile(module, filename, client_data) except IgnoreExtraConf: pass # No compilation database and no extra conf found. Warn the user if not # already warned. if not self.no_extra_conf_file_warning_posted: self.no_extra_conf_file_warning_posted = True raise NoExtraConfDetected return EMPTY_FLAGS
def ExtraConfStore_ModuleForSourceFile_WinVarEnv_test(app): filename = PathToTestFile('extra_conf', 'project', 'some_file') module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(PROJECT_EXTRA_CONF)) assert_that(module, has_property('is_global_ycm_extra_conf')) assert_that(module.is_global_ycm_extra_conf, equal_to(False)) assert_that(extra_conf_store.IsGlobalExtraConfModule(module), equal_to(False))
def ExtraConfStore_ModuleForSourceFile_GlobalExtraConf_UnixEnvVar_test(app): filename = PathToTestFile('extra_conf', 'some_file') module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(GLOBAL_EXTRA_CONF)) assert_that(module, has_property('is_global_ycm_extra_conf')) assert_that(module.is_global_ycm_extra_conf, equal_to(True)) assert_that(extra_conf_store.IsGlobalExtraConfModule(module), equal_to(True))
def Load_DoNotReloadExtraConf_ForceEqualsTrue_test(app): with patch('ycmd.extra_conf_store._ShouldLoad', return_value=True): module = extra_conf_store.Load(PROJECT_EXTRA_CONF) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(PROJECT_EXTRA_CONF)) assert_that(module, has_property('is_global_ycm_extra_conf')) assert_that(module.is_global_ycm_extra_conf, equal_to(False)) assert_that(extra_conf_store.IsGlobalExtraConfModule(module), equal_to(False)) assert_that(extra_conf_store.Load(PROJECT_EXTRA_CONF, force=True), same_instance(module))
def test_ExtraConfStore_ModuleForSourceFile_SupportSymlink(self, app): with TemporarySymlink(PathToTestFile('extra_conf', 'project'), PathToTestFile('extra_conf', 'symlink')): filename = PathToTestFile('extra_conf', 'project', 'some_file') module = extra_conf_store.ModuleForSourceFile(filename) assert_that(inspect.ismodule(module)) assert_that(inspect.getfile(module), equal_to(PROJECT_EXTRA_CONF)) assert_that(module, has_property('is_global_ycm_extra_conf')) assert_that(module.is_global_ycm_extra_conf, equal_to(False)) assert_that(extra_conf_store.IsGlobalExtraConfModule(module), equal_to(False))
def _SendFlagsFromExtraConf(self, request_data): """Reads the flags from the extra conf of the given request and sends them to Clangd as an entry of a compilation database using the 'compilationDatabaseChanges' configuration.""" filepath = request_data['filepath'] with self._server_info_mutex: # Replicate the logic from flags.py _GetFlagsFromCompilationDatabase: # - if there's a local extra conf, use it # - otherwise if there's no database, try and use a global extra conf module = extra_conf_store.ModuleForSourceFile(filepath) if not module: # No extra conf and no global extra conf. Just let clangd handle it. return if (extra_conf_store.IsGlobalExtraConfModule(module) and CompilationDatabaseExists(filepath)): # No local extra conf, database exists: use database (i.e. clangd) return # Use our module (either local extra conf or global extra conf when no # database is found) settings = self.GetSettings(module, request_data) if 'flags' not in settings: # No flags returned. Let Clangd find the flags. return if (settings.get('do_cache', True) and filepath in self._compilation_commands): # Flags for this file have already been sent to Clangd. return flags = BuildCompilationCommand(settings['flags'], filepath) self.GetConnection().SendNotification( lsp.DidChangeConfiguration({ 'compilationDatabaseChanges': { filepath: { 'compilationCommand': flags, 'workingDirectory': settings.get('include_paths_relative_to_dir', self._project_directory) } } })) self._compilation_commands[filepath] = flags