def EventNotification_OnFileReadyToParse_UseGlobalConfig_test( global_config_exists, app): # No working directory is given. response = app.post_json('/event_notification', BuildRequest(filepath=PathToTestFile('..'), event_name='FileReadyToParse', filetype='javascript'), expect_errors=True) print('event response: {0}'.format(pformat(response.json))) assert_that(response.status_code, equal_to(requests.codes.ok)) assert_that(response.json, empty()) debug_info = app.post_json('/debug_info', BuildRequest(filetype='javascript')).json assert_that( debug_info['completer']['servers'][0]['extras'], contains_exactly( has_entries({ 'key': 'configuration file', 'value': os.path.join(os.path.expanduser('~'), '.tern-config') }), has_entries({ 'key': 'working directory', 'value': utils.GetCurrentDirectory() }))) # Restart the server with a working directory. app.post_json( '/run_completer_command', BuildRequest(filepath=PathToTestFile('..'), command_arguments=['RestartServer'], filetype='javascript', working_dir=PathToTestFile())) debug_info = app.post_json('/debug_info', BuildRequest(filetype='javascript')).json assert_that( debug_info['completer']['servers'][0]['extras'], contains_exactly( has_entries({ 'key': 'configuration file', 'value': os.path.join(os.path.expanduser('~'), '.tern-config') }), has_entries({ 'key': 'working directory', 'value': PathToTestFile() })))
def _SetServerProjectFileAndWorkingDirectory(self, request_data): filepath = request_data['filepath'] self._server_project_file, is_project = FindTernProjectFile(filepath) working_dir = request_data.get('working_dir', utils.GetCurrentDirectory()) if not self._server_project_file: LOGGER.warning('No .tern-project file detected: %s', filepath) self._server_working_dir = working_dir else: LOGGER.info('Detected Tern configuration file at: %s', self._server_project_file) self._server_working_dir = (os.path.dirname( self._server_project_file) if is_project else working_dir) LOGGER.info('Tern paths are relative to: %s', self._server_working_dir)
def SendCompletionRequest(self, force_semantic=False): request_data = BuildRequestData() request_data['force_semantic'] = force_semantic if (not self.NativeFiletypeCompletionAvailable() and self.CurrentFiletypeCompletionEnabled()): wrapped_request_data = RequestWrap(request_data) if self._omnicomp.ShouldUseNow(wrapped_request_data): self._latest_completion_request = OmniCompletionRequest( self._omnicomp, wrapped_request_data) self._latest_completion_request.Start() return request_data['working_dir'] = utils.GetCurrentDirectory() self._AddExtraConfDataIfNeeded(request_data) self._latest_completion_request = CompletionRequest(request_data) self._latest_completion_request.Start()
def _WarnIfMissingTernProject(self): # The Tern server will operate without a .tern-project file. However, it # does not operate optimally, and will likely lead to issues reported that # JavaScript completion is not working properly. So we raise a warning if we # aren't able to detect some semblance of manual Tern configuration. # We do this check after the server has started because the server does # have nonzero use without a project file, however limited. We only do this # check once, though because the server can only handle one project at a # time. This doesn't catch opening a file which is not part of the project # or any of those things, but we can only do so much. We'd like to enhance # ycmd to handle this better, but that is a FIXME for now. if self._ServerIsRunning() and self._do_tern_project_check: self._do_tern_project_check = False current_dir = utils.GetCurrentDirectory() (tern_project, is_project) = FindTernProjectFile(current_dir) if not tern_project: _logger.warning('No .tern-project file detected: ' + current_dir) raise RuntimeError( 'Warning: Unable to detect a .tern-project file ' 'in the hierarchy before ' + current_dir + ' and no global .tern-config file was found. ' 'This is required for accurate JavaScript ' 'completion. Please see the User Guide for ' 'details.') else: _logger.info('Detected Tern configuration file at: ' + tern_project) # Paths are relative to the project file if it exists, otherwise they # are relative to the working directory of Tern server (which is the # same as the working directory of ycmd). self._server_paths_relative_to = (os.path.dirname(tern_project) if is_project else current_dir) _logger.info('Tern paths are relative to: ' + self._server_paths_relative_to)
def GetCurrentDirectory_Py3NoCurrentDirectory_test(): with patch('os.getcwd', side_effect=FileNotFoundError): # noqa eq_(utils.GetCurrentDirectory(), tempfile.gettempdir())
def GetCurrentDirectory_Py2NoCurrentDirectory_test(): with patch('os.getcwdu', side_effect=OSError): eq_(utils.GetCurrentDirectory(), tempfile.gettempdir())
def GetTagFiles(): tag_files = vim.eval('tagfiles()') return [ os.path.join(utils.GetCurrentDirectory(), tag_file) for tag_file in tag_files ]
def test_GetCurrentDirectory_Py3NoCurrentDirectory(self): with patch('os.getcwd', side_effect=FileNotFoundError): # noqa assert_that(utils.GetCurrentDirectory(), equal_to(tempfile.gettempdir()))
def EventNotification_OnFileReadyToParse_NoProjectFile_test(app, *args): # We raise an error if we can't detect a .tern-project file. # We only do this on the first OnFileReadyToParse event after a # server startup. response = app.post_json('/event_notification', BuildRequest(filepath=PathToTestFile('..'), event_name='FileReadyToParse', filetype='javascript'), expect_errors=True) print('event response: {0}'.format(pformat(response.json))) eq_(response.status_code, requests.codes.internal_server_error) assert_that( response.json, ErrorMatcher( RuntimeError, 'Warning: Unable to detect a .tern-project file ' 'in the hierarchy before ' + PathToTestFile('..') + ' and no global .tern-config file was found. ' 'This is required for accurate JavaScript ' 'completion. Please see the User Guide for ' 'details.')) debug_info = app.post_json('/debug_info', BuildRequest(filetype='javascript')).json assert_that( debug_info['completer']['servers'][0]['extras'], contains( has_entries({ 'key': 'configuration file', 'value': none() }), has_entries({ 'key': 'working directory', 'value': utils.GetCurrentDirectory() }))) # Check that a subsequent call does *not* raise the error. response = app.post_json('/event_notification', BuildRequest(event_name='FileReadyToParse', filetype='javascript'), expect_errors=True) print('event response: {0}'.format(pformat(response.json))) eq_(response.status_code, requests.codes.ok) assert_that(response.json, empty()) # Restart the server and check that it raises it again. app.post_json( '/run_completer_command', BuildRequest(filepath=PathToTestFile('..'), command_arguments=['RestartServer'], filetype='javascript')) response = app.post_json('/event_notification', BuildRequest(filepath=PathToTestFile('..'), event_name='FileReadyToParse', filetype='javascript'), expect_errors=True) print('event response: {0}'.format(pformat(response.json))) eq_(response.status_code, requests.codes.internal_server_error) assert_that( response.json, ErrorMatcher( RuntimeError, 'Warning: Unable to detect a .tern-project file ' 'in the hierarchy before ' + PathToTestFile('..') + ' and no global .tern-config file was found. ' 'This is required for accurate JavaScript ' 'completion. Please see the User Guide for ' 'details.')) # Finally, restart the server in a folder containing a .tern-project file. We # expect no error in that case. app.post_json( '/run_completer_command', BuildRequest(filepath=PathToTestFile(), command_arguments=['RestartServer'], filetype='javascript')) response = app.post_json('/event_notification', BuildRequest(filepath=PathToTestFile(), event_name='FileReadyToParse', filetype='javascript'), expect_errors=True) print('event response: {0}'.format(pformat(response.json))) eq_(response.status_code, requests.codes.ok) assert_that(response.json, empty()) debug_info = app.post_json('/debug_info', BuildRequest(filetype='javascript')).json assert_that( debug_info['completer']['servers'][0]['extras'], contains( has_entries({ 'key': 'configuration file', 'value': PathToTestFile('.tern-project') }), has_entries({ 'key': 'working directory', 'value': PathToTestFile() })))
def GetTagFiles(): tag_files = vim.eval( 'tagfiles()' ) return [ ( os.path.join( utils.GetCurrentDirectory(), tag_file ) if not os.path.isabs( tag_file ) else tag_file ) for tag_file in tag_files ]