{"action":"created","issue":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1848","labels_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1848/labels{/name}","comments_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1848/comments","events_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1848/events","html_url":"https://github.com/Valloric/YouCompleteMe/pull/1848","id":123583222,"number":1848,"title":"[READY] Raise warnings on FileReadyToParse for completers not supporting diagnostics","user":{"login":"puremourning","id":10584846,"avatar_url":"https://avatars.githubusercontent.com/u/10584846?v=3","gravatar_id":"","url":"https://api.github.com/users/puremourning","html_url":"https://github.com/puremourning","followers_url":"https://api.github.com/users/puremourning/followers","following_url":"https://api.github.com/users/puremourning/following{/other_user}","gists_url":"https://api.github.com/users/puremourning/gists{/gist_id}","starred_url":"https://api.github.com/users/puremourning/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puremourning/subscriptions","organizations_url":"https://api.github.com/users/puremourning/orgs","repos_url":"https://api.github.com/users/puremourning/repos","events_url":"https://api.github.com/users/puremourning/events{/privacy}","received_events_url":"https://api.github.com/users/puremourning/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-23T00:59:32Z","updated_at":"2015-12-24T17:40:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/pulls/1848","html_url":"https://github.com/Valloric/YouCompleteMe/pull/1848","diff_url":"https://github.com/Valloric/YouCompleteMe/pull/1848.diff","patch_url":"https://github.com/Valloric/YouCompleteMe/pull/1848.patch"},"body":"Fixes #1829 \r\n\r\n## Background\r\n\r\nDetailed analysis is available on [the issue](https://github.com/Valloric/YouCompleteMe/issues/1829). But principally: if the filetype being edited is not a filetype suporting YCM native diagnostics, then warnings, errors, etc. (including the \"unknown extra conf\" warning/prompt) are not displayed after the \"FileReadyToParse\" `event_notification`\r\n\r\n## Resolution\r\n\r\nThe approach is: for filetypes which do not support diagnostics, rather than ignoring all `FileReadyToParse` event responses, simply call the `Response` method, which raises the appropriate error or handles the \"confirm extra-conf\" behaviour. Any other data returned by the completer (such as diagnostics!), are simply ignored.\r\n\r\n## Manual Testing\r\n\r\nTested with tern completer which raises an error if the `.tern-project` file is not found.\r\nTested with a modified tern completer with the following `OnFileReadyToParse`:\r\n\r\n```python\r\n  def OnFileReadyToParse( self, request_data ):\r\n    self._WarnIfMissingTernProject()\r\n\r\n    module = extra_conf_store.ModuleForSourceFile( request_data[ 'filepath' ] )\r\n    if not module:\r\n      if not self._raised_extra_conf_warning:\r\n        self._raised_extra_conf_warning = True\r\n        raise NoExtraConfDetected\r\n      return\r\n\r\n    # use module!\r\n```\r\n\r\nResults all as expected:\r\n\r\n- with no `.tern-config`: tern config warning (once)\r\n- with `.tern-config`, but no `.ycm_extra_conf`: no extra conf warning (once)\r\n- with `.tern-config` and `.ycm_extra_conf`: confirmation prompt (once)\r\n\r\n## Automated Testing\r\n\r\nThis was a marathon. Or a mockathon, I suppose.\r\n\r\nBriefly:\r\n\r\n- I wrote a `event_notification_test.py` which tests these new `YouCompleteMe` object behaviours, via a complex series of mocking\r\n- I had to refactor the `postcomplete_tests.py` to prevent it from leaving `MagicMock` instances all over the place because this lead to the above test failing (apparently) randomly\r\n- In order to debug the above shenanigans I updated `run_tests.py` to allow passing arguments to nosetests, like we do in `ycmd`\r\n\r\nThere are more comments in the code and on the various commit messages, explaining what's going on.\r\n\r\nWith regard to style, there is quite a lot of:\r\n\r\n```python\r\n\r\n@contextlib.contextmanager\r\ndef something():\r\n  with patch(this):\r\n    with patch(that):\r\n      with patch(the_other):\r\n        yield\r\n\r\n@patch( foo )\r\ndef do_a_test( foo ):\r\n  with something():\r\n    do_a_thing() \r\n    assert foo.called()\r\n```\r\n\r\nThe reason for this relative ugliness is that there is a lot of boilerplate mocking code. Because of a number of foibles of `mock` and the versions of python we support, I found this to be the least hacky way of ensuring that everything was cleaned up and was relatively sane to read and maintain.\r\n\r\nExplanation for the `with`-ception that is going on:\r\n\r\n- @patch is my preferred method, but it is more difficult to comment well and doesn't work when used with `@contextlib.contextmanager`, so you have to use `with`\r\n- multiple managers in a single `with` statement is not supported in Python 2.6\r\n- `contextlib.nested` is deprecated and buggy (apparently)\n\n<!-- Reviewable:start -->\n[<img src=\"https://reviewable.io/review_button.png\" height=40 alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/valloric/youcompleteme/1848)\n<!-- Reviewable:end -->\n"},"comment":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/comments/167140619","html_url":"https://github.com/Valloric/YouCompleteMe/pull/1848#issuecomment-167140619","issue_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1848","id":167140619,"user":{"login":"vheon","id":90633,"avatar_url":"https://avatars.githubusercontent.com/u/90633?v=3","gravatar_id":"","url":"https://api.github.com/users/vheon","html_url":"https://github.com/vheon","followers_url":"https://api.github.com/users/vheon/followers","following_url":"https://api.github.com/users/vheon/following{/other_user}","gists_url":"https://api.github.com/users/vheon/gists{/gist_id}","starred_url":"https://api.github.com/users/vheon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vheon/subscriptions","organizations_url":"https://api.github.com/users/vheon/orgs","repos_url":"https://api.github.com/users/vheon/repos","events_url":"https://api.github.com/users/vheon/events{/privacy}","received_events_url":"https://api.github.com/users/vheon/received_events","type":"User","site_admin":false},"created_at":"2015-12-24T17:40:17Z","updated_at":"2015-12-24T17:40:17Z","body":"I've found just a typo in a comment. Other than that <img class=\"emoji\" title=\":lgtm:\" alt=\":lgtm:\" align=\"absmiddle\" src=\"https://reviewable.io/lgtm.png\" height=\"20\" width=\"61\"/> \n\n---\n\nReviewed 2 of 5 files at r1, 3 of 3 files at r2.\nReview status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.\n\n---\n\n*[python/ycm/tests/event_notification_test.py, line 49 \\[r2\\]](https://reviewable.io:443/reviews/valloric/youcompleteme/1848#-K6K2QGgF_synIXE0-Rj:-K6K2QGhCt1SqzlirQ45:255056475) ([raw file](https://github.com/valloric/youcompleteme/blob/2063ae8b9122b3879ccb412d8d0602c723ab7c44/python/ycm/tests/event_notification_test.py#L49)):*\ntypo `wby`\n\n---\n\n\n*Comments from the [review on Reviewable.io](https://reviewable.io:443/reviews/valloric/youcompleteme/1848#-:-K6K3lTI75eBSLq3ZkDa:1647928894)*\n<!-- Sent from Reviewable.io -->\n"}}