From 93fa3ad7e7716e9ca70f783c24465b47519fb950 Mon Sep 17 00:00:00 2001 From: nop Date: Tue, 3 Dec 2013 17:34:10 +0100 Subject: [PATCH] Small stylistic changes --- python/ycm/completers/cs/cs_completer.py | 36 +++++++++---------- .../ycm/server/tests/get_completions_test.py | 6 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 92638d3f..9e2147bc 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -117,31 +117,31 @@ class CsharpCompleter( Completer ): self._logger.info( 'startup' ) self._omnisharp_port = utils.GetUnusedLocalhostPort() - solutionfiles, folder = _FindSolutionFiles( request_data[ 'filepath' ] ) + solution_files, folder = _FindSolutionFiles( request_data[ 'filepath' ] ) - if len( solutionfiles ) == 0: + if len( solution_files ) == 0: raise RuntimeError( 'Error starting OmniSharp server: no solutionfile found' ) - elif len( solutionfiles ) == 1: - solutionfile = solutionfiles[ 0 ] + elif len( solution_files ) == 1: + solutionfile = solution_files[ 0 ] else: # multiple solutions found : if there is one whose name is the same # as the folder containing the file we edit, use this one # (e.g. if we have bla/Project.sln and we are editing # bla/Project/Folder/File.cs, use bla/Project.sln) - filepath = _SplitPath( request_data[ 'filepath' ] ) - solutionpath = _SplitPath( folder ) + filepath_components = _PathComponents( request_data[ 'filepath' ] ) + solutionpath = _PathComponents( folder ) foldername = '' - if len( filepath ) > len( solutionpath ): - foldername = filepath[ len( solutionpath ) ] - solutionfilecandidates = [ solutionfile for solutionfile in solutionfiles + if len( filepath_components ) > len( solutionpath ): + foldername = filepath_components[ len( solutionpath ) ] + solution_file_candidates = [ solutionfile for solutionfile in solution_files if _GetFilenameWithoutExtension( solutionfile ) == foldername ] - if len( solutionfilecandidates ) == 1: - solutionfile = solutionfilecandidates[ 0 ] + if len( solution_file_candidates ) == 1: + solutionfile = solution_file_candidates[ 0 ] else: raise RuntimeError( 'Found multiple solution files instead of one!\n{0}'.format( - solutionfiles ) ) + solution_files ) ) omnisharp = os.path.join( os.path.abspath( os.path.dirname( __file__ ) ), @@ -245,18 +245,18 @@ def _FindSolutionFiles( filepath ): solutionfiles = glob.glob1( folder, '*.sln' ) return solutionfiles, folder -def _SplitPath( path ): - result = [] +def _PathComponents( path ): + path_components = [] while True: path, folder = os.path.split( path ) if folder: - result.append( folder ) + path_components.append( folder ) else: if path: - result.append( path ) + path_components.append( path ) break - result.reverse() - return result + path_components.reverse() + return path_components def _GetFilenameWithoutExtension( path ): return os.path.splitext( os.path.basename ( path ) )[ 0 ] diff --git a/python/ycm/server/tests/get_completions_test.py b/python/ycm/server/tests/get_completions_test.py index 14fd5e54..d62740c3 100644 --- a/python/ycm/server/tests/get_completions_test.py +++ b/python/ycm/server/tests/get_completions_test.py @@ -138,16 +138,16 @@ def GetCompletions_CsCompleter_DoesntStartWithAmbiguousMultipleSolutions_test(): contents = contents, event_name = 'FileReadyToParse' ) - exceptioncaught = False + exception_caught = False try: app.post_json( '/event_notification', event_data ) except AppError as e: if 'Found multiple solution files' in str(e): - exceptioncaught = True + exception_caught = True # the test passes if we caught an exception when trying to start it, # so raise one if it managed to start - if exceptioncaught == False: + if not exception_caught: # Now for some cleanup: wait for the server to start then shut it down while True: result = app.post_json( '/run_completer_command',