From 2aa9b7800065e189f73d6c627a2896a4052e90b7 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Wed, 12 Oct 2022 09:06:55 -0400 Subject: [PATCH 1/2] Try starting Omnisharp server without solution file With this change, ycmd will attempt to start the Omnisharp server with the current working directory when no solution file is found. The runtime check for solution file presence is not required and exception raising is defered to Omnisharp. --- ycmd/completers/cs/cs_completer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ycmd/completers/cs/cs_completer.py b/ycmd/completers/cs/cs_completer.py index bb7544987e..1133561880 100644 --- a/ycmd/completers/cs/cs_completer.py +++ b/ycmd/completers/cs/cs_completer.py @@ -381,7 +381,13 @@ def _GetSolutionFile( self, filepath ): # to be confirmed path_to_solutionfile = solutiondetection.FindSolutionPath( filepath ) if not path_to_solutionfile: - raise RuntimeError( 'Autodetection of solution file failed.' ) + path_to_solutionfile = os.getcwd() + LOGGER.info( 'Autodetection of solution file failed, ' + 'trying current directory ({0}).' + .format( path_to_solutionfile ) ) + else: + LOGGER.info( 'Loading solution file {0}' + .format( path_to_solutionfile ) ) self._solution_for_file[ filepath ] = path_to_solutionfile return self._solution_for_file[ filepath ] From fa3bdabaaf4d314371850f0c1cc7e2963ec7f892 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Tue, 1 Nov 2022 16:30:24 -0400 Subject: [PATCH 2/2] Change CS completer tests for Omnisharp server without solution - Change the test to ensure that the OmniSharp server starts with an empty solution file. - Remove the test that was testing that the case where OmniSharp server should not start when an unambiguous solution file is not found. --- ycmd/tests/cs/debug_info_test.py | 13 +++++++------ ycmd/tests/cs/get_completions_test.py | 21 --------------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/ycmd/tests/cs/debug_info_test.py b/ycmd/tests/cs/debug_info_test.py index 8f6258ffbd..7774bbcc52 100644 --- a/ycmd/tests/cs/debug_info_test.py +++ b/ycmd/tests/cs/debug_info_test.py @@ -95,7 +95,7 @@ def test_DebugInfo_ServerIsRunning( self, app ): @SharedYcmd - def test_DebugInfo_ServerIsNotRunning_NoSolution( self, app ): + def test_DebugInfo_ServerIsRunning_NoSolution( self, app ): request_data = BuildRequest( filetype = 'cs' ) assert_that( app.post_json( '/debug_info', request_data ).json, @@ -103,12 +103,13 @@ def test_DebugInfo_ServerIsNotRunning_NoSolution( self, app ): 'name': 'C#', 'servers': contains_exactly( has_entries( { 'name': 'OmniSharp', - 'is_running': False, + 'is_running': True, 'executable': instance_of( str ), - 'pid': None, - 'address': None, - 'port': None, - 'logfiles': empty() + 'pid': instance_of( int ), + 'address': instance_of( str ), + 'port': instance_of( int ), + 'logfiles': contains_exactly( instance_of( str ), + instance_of( str ) ) } ) ), 'items': empty() } ) ) diff --git a/ycmd/tests/cs/get_completions_test.py b/ycmd/tests/cs/get_completions_test.py index a992d96bda..9e3756b1d7 100644 --- a/ycmd/tests/cs/get_completions_test.py +++ b/ycmd/tests/cs/get_completions_test.py @@ -172,24 +172,3 @@ def test_GetCompletions_PathWithSpace( self, app ): ), 'errors': empty(), } ) ) - - - @SharedYcmd - def test_GetCompletions_DoesntStartWithAmbiguousMultipleSolutions( - self, app ): - filepath = PathToTestFile( 'testy-multiple-solutions', - 'solution-not-named-like-folder', - 'testy', 'Program.cs' ) - contents = ReadFile( filepath ) - event_data = BuildRequest( filepath = filepath, - filetype = 'cs', - contents = contents, - event_name = 'FileReadyToParse' ) - - assert_that( - calling( app.post_json ).with_args( '/event_notification', event_data ), - raises( AppError, 'Autodetection of solution file failed' ), - "The Omnisharp server started, despite us not being able to find a " - "suitable solution file to feed it. Did you fiddle with the solution " - "finding code in cs_completer.py? Hopefully you've enhanced it: you need " - "to update this test then :)" )