Small stylistic changes
This commit is contained in:
parent
f8aabab328
commit
93fa3ad7e7
@ -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 ]
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user