Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix g:ycm_roslyn_binary_path being ignored #1721

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

dkaszews
Copy link

@dkaszews dkaszews commented Dec 9, 2023

Fixes the g:ycm_roslyn_binary_path only being used in prechecks, and the actual server always being started from the ycmd/third_party directory.

Also fixes the :YcmDebugInfo printing the directory containing default OmniSharp executable (and not the executable file itself); now prints full command with arguments used to start the server.


This change is Reviewable

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally, this looks good.
I did leave one comment.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 0 of 2 LGTMs obtained (waiting on @dkaszews)


ycmd/tests/cs/debug_info_test.py line 207 at r1 (raw file):

  def _RoslynFromUserOption_popen_mock(*args, **kwargs):

This will fail flake8 check.

( *args, **kwargs ) - mind the "floating" parentheses.

Also, I'm too hungry to take a closer look now, but...

if this helper function needs to be a member of the test class, I would prefer to see self, *args, **kwargs.
If it needs not be a member of the test class, let's move it above the test class.

Copy link
Author

@dkaszews dkaszews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (waiting on @bstaletic)


ycmd/tests/cs/debug_info_test.py line 207 at r1 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

This will fail flake8 check.

( *args, **kwargs ) - mind the "floating" parentheses.

Also, I'm too hungry to take a closer look now, but...

if this helper function needs to be a member of the test class, I would prefer to see self, *args, **kwargs.
If it needs not be a member of the test class, let's move it above the test class.

It doesn't need to be member of test class, but I would like to keep it next to the test case as it has same hardcoded value, basically a multiline lambda. Maybe @staticmethod then?

I also just had a stupid idea to check out tommorow. We only care about value here and the forward to real Popen is just to keep rest of test of failing. Just throw some custom exception that will only be caught in test and end it early. Should save a lot of time by not actually starting the server and waiting on it.

Copy link
Author

@dkaszews dkaszews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Reviewable status: 0 of 2 LGTMs obtained (waiting on @bstaletic)

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if CI has come to its senses.

Reviewable status: 0 of 2 LGTMs obtained (waiting on @dkaszews)


ycmd/tests/cs/debug_info_test.py line 207 at r1 (raw file):

Previously, dkaszews (Dominik Kaszewski) wrote…

It doesn't need to be member of test class, but I would like to keep it next to the test case as it has same hardcoded value, basically a multiline lambda. Maybe @staticmethod then?

I also just had a stupid idea to check out tommorow. We only care about value here and the forward to real Popen is just to keep rest of test of failing. Just throw some custom exception that will only be caught in test and end it early. Should save a lot of time by not actually starting the server and waiting on it.

@staticmethod sounds good to me.

@bstaletic
Copy link
Collaborator

Also, we have merged the unicode/regex update, so you should rebase.

Copy link
Author

@dkaszews dkaszews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and rebased

Reviewable status: 0 of 2 LGTMs obtained (waiting on @bstaletic)


ycmd/tests/cs/debug_info_test.py line 207 at r1 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

@staticmethod sounds good to me.

Done, the exception idea unfortunatelly did not work, as it was caught by production code I don't have time to investigate.

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @dkaszews)

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)

@dkaszews
Copy link
Author

Apparently @patch does not work with @staticmethod before Python 3.10 and CI uses 3.8. Wouldn't be an issue if stupid Python had multiline lambdas. Will have to look at alternative solutions.

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just drop @staticmethod and add a self as the first argument, which it would have anyway. Then just add a comment about it too.

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)

@dkaszews
Copy link
Author

That did not work either, was getting errors that instance method was called without self. Found alternative of patching inside test with local function.

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)


ycmd/tests/cs/debug_info_test.py line 212 at r5 (raw file):

    # `@patch` does not play nice with functions defined at class scope
    def _popen_mock( *args, **kwargs ):
      assert_that( args[ 0 ][ 1 ], equal_to( 'my_roslyn.exe' ) )

given that we're using args[0] directly, why not:

def _popen_mock( cmdline, *args, **kwargs ):
    # use cmdline

Copy link
Author

@dkaszews dkaszews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied suggestion

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @puremourning)


ycmd/tests/cs/debug_info_test.py line 212 at r5 (raw file):

Previously, puremourning (Ben Jackson) wrote…

given that we're using args[0] directly, why not:

def _popen_mock( cmdline, *args, **kwargs ):
    # use cmdline

Fair point, done. I omitted *args because all other arguments are named-only.

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)

@dkaszews
Copy link
Author

Any clue why this fails only on older Windows?

@puremourning
Copy link
Member

I have re-run them. Let's see if it was CI flake.

@puremourning
Copy link
Member

puremourning commented Dec 21, 2023

Nope, looks like the test really does just fail on windows:

======================================================================
ERROR: test_GetCompleter_RoslynFromUserOption (ycmd.tests.cs.debug_info_test.DebugInfoTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\unittest\mock.py", line 1325, in patched
    return func(*newargs, **newkeywargs)
  File "D:\a\ycmd\ycmd\ycmd\tests\cs\__init__.py", line 70, in Wrapper
    test( test_case_instance, app, *args, **kwargs )
  File "D:\a\ycmd\ycmd\ycmd\tests\cs\debug_info_test.py", line 219, in test_GetCompleter_RoslynFromUserOption
    with WrapOmniSharpServer( app, filepath ):
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "D:\a\ycmd\ycmd\ycmd\tests\cs\__init__.py", line 108, in WrapOmniSharpServer
    GetDiagnostics( app, filepath )
  File "D:\a\ycmd\ycmd\ycmd\tests\cs\__init__.py", line 99, in GetDiagnostics
    return app.post_json( '/event_notification', event_data ).json
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\webtest\utils.py", line 34, in wrapper
    return self._gen_request(method, url, **kw)
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\webtest\app.py", line 749, in _gen_request
    return self.do_request(req, status=status,
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\webtest\app.py", line 646, in do_request
    self._check_status(status, res)
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\webtest\app.py", line 675, in _check_status
    raise AppError(
webtest.app.AppError: Bad response: 500 Internal Server Error (not 200 OK or 3xx redirect for http://localhost/event_notification)
b'{"exception":{"TYPE":"AssertionError"},"message":"\\nExpected: \'my_roslyn.exe\'\\n     but: was \'-p\'\\n","traceback":"Traceback (most recent call last):\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\third_party\\\\bottle\\\\bottle.py\\", line 876, in _handle\\n    return route.call(**args)\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\third_party\\\\bottle\\\\bottle.py\\", line 1756, in wrapper\\n    rv = callback(*a, **ka)\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\handlers.py\\", line 65, in EventNotification\\n    response_data = getattr( _server_state.GetFiletypeCompleter( filetypes ),\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\completers\\\\cs\\\\cs_completer.py\\", line 262, in OnFileReadyToParse\\n    solutioncompleter._StartServer()\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\completers\\\\cs\\\\cs_completer.py\\", line 421, in _StartServer\\n    return self._StartServerNoLock()\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\completers\\\\cs\\\\cs_completer.py\\", line 466, in _StartServerNoLock\\n    self._omnisharp_phandle = utils.SafePopen(\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\utils.py\\", line 370, in SafePopen\\n    return subprocess.Popen( args, **kwargs )\\n  File \\"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.8.10\\\\x64\\\\lib\\\\unittest\\\\mock.py\\", line 1081, in __call__\\n    return self._mock_call(*args, **kwargs)\\n  File \\"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.8.10\\\\x64\\\\lib\\\\unittest\\\\mock.py\\", line 1085, in _mock_call\\n    return self._execute_mock_call(*args, **kwargs)\\n  File \\"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.8.10\\\\x64\\\\lib\\\\unittest\\\\mock.py\\", line 1155, in _execute_mock_call\\n    return self._mock_wraps(*args, **kwargs)\\n  File \\"D:\\\\a\\\\ycmd\\\\ycmd\\\\ycmd\\\\tests\\\\cs\\\\debug_info_test.py\\", line 212, in _popen_mock\\n    assert_that( cmdline[ 1 ], equal_to( \'my_roslyn.exe\' ) )\\n  File \\"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.8.10\\\\x64\\\\lib\\\\site-packages\\\\hamcrest\\\\core\\\\assert_that.py\\", line 58, in assert_that\\n    _assert_match(actual=actual_or_assertion, matcher=matcher, reason=reason)\\n  File \\"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.8.10\\\\x64\\\\lib\\\\site-packages\\\\hamcrest\\\\core\\\\assert_that.py\\", line 73, in _assert_match\\n    raise AssertionError(description)\\nAssertionError: \\nExpected: \'my_roslyn.exe\'\\n     but: was \'-p\'\\n\\n"}'

nExpected: 'my_roslyn.exe'\n but: was '-p'\n\n"}'

@dkaszews
Copy link
Author

Could not get through the callstack myself, but now it just looks like it fails because on Windows it runs with my_roslyn.exe ... instead of mono my_roslyn.exe .... Easy enough fix, that's why I asked on gitter whether this test will run on Windows 🤷

@puremourning
Copy link
Member

yeah, it's a bit cryptic the way the failure is reported!

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Merging #1721 (e318b5e) into master (f4cfdb8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1721   +/-   ##
=======================================
  Coverage   95.45%   95.45%           
=======================================
  Files          83       83           
  Lines        8136     8143    +7     
  Branches      163      163           
=======================================
+ Hits         7766     7773    +7     
  Misses        320      320           
  Partials       50       50           

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: 0 of 2 LGTMs obtained (and 2 stale) (waiting on @dkaszews)


ycmd/tests/cs/debug_info_test.py line 212 at r7 (raw file):

    # `@patch` does not play nice with functions defined at class scope
    def _popen_mock( cmdline, **kwargs ):
      i = cmdline[ 0 ].endswith( 'mono' )

not a fan of this. I would rather:

exe_idx = 1 if cmdline[ 0 ].endswith( 'mono' ) else 0

Because that says what it is doing, rather than assuming you implicitly know that, and that the True will turn into 1 when used as an index... which is weird.

Copy link
Author

@dkaszews dkaszews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (and 2 stale) (waiting on @puremourning)


ycmd/tests/cs/debug_info_test.py line 212 at r7 (raw file):

Previously, puremourning (Ben Jackson) wrote…

not a fan of this. I would rather:

exe_idx = 1 if cmdline[ 0 ].endswith( 'mono' ) else 0

Because that says what it is doing, rather than assuming you implicitly know that, and that the True will turn into 1 when used as an index... which is weird.

Done.

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Let's squash.

Reviewed 1 of 1 files at r9.
Reviewable status: 1 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)


-- commits line 28 at r9:
let's squash the commits now, LGTM.

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)

@dkaszews
Copy link
Author

@puremourning Do you need me to squash manually? I'm AFK so might be a bit hard.

The codecov fails seem to be because I rewrote bits of code to be shorter so the line percentage went down 🙄

@puremourning
Copy link
Member

@Mergifyio squash

Fix g:ycm_roslyn_binary_path being ignored

* Add test

* Clean test

* Fix formatting

* Fix UT

* Fix UT for Python 3.8

* Make popen mock args more readable

* Fix UT on Windows

* Explicit index

* Explicit index name
Copy link
Contributor

mergify bot commented Dec 24, 2023

squash

✅ Pull request squashed successfully

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@dkaszews Thanks for the pull request!

Reviewed 1 of 1 files at r4.
Reviewable status: 1 of 2 LGTMs obtained (and 1 stale) (waiting on @dkaszews)

@puremourning puremourning added the Ship It! Manual override to merge a PR by maintainer label Dec 27, 2023
Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 2 of 2 LGTMs obtained (waiting on @dkaszews)

Copy link
Contributor

mergify bot commented Dec 27, 2023

Thanks for sending a PR!

@mergify mergify bot merged commit 80a034d into ycm-core:master Dec 27, 2023
18 checks passed
Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: :shipit: complete! 2 of 2 LGTMs obtained (waiting on @dkaszews)

Copy link
Contributor

mergify bot commented Dec 27, 2023

Thanks for sending a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ship It! Manual override to merge a PR by maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants