{"action":"created","issue":{"url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/125","repository_url":"https://api.github.com/repos/JetBrains/resharper-unity","labels_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/125/comments","events_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/125/events","html_url":"https://github.com/JetBrains/resharper-unity/issues/125","id":215704289,"node_id":"MDU6SXNzdWUyMTU3MDQyODk=","number":125,"title":"Preprocessor defines","user":{"login":"citizenmatt","id":222659,"node_id":"MDQ6VXNlcjIyMjY1OQ==","avatar_url":"https://avatars1.githubusercontent.com/u/222659?v=4","gravatar_id":"","url":"https://api.github.com/users/citizenmatt","html_url":"https://github.com/citizenmatt","followers_url":"https://api.github.com/users/citizenmatt/followers","following_url":"https://api.github.com/users/citizenmatt/following{/other_user}","gists_url":"https://api.github.com/users/citizenmatt/gists{/gist_id}","starred_url":"https://api.github.com/users/citizenmatt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citizenmatt/subscriptions","organizations_url":"https://api.github.com/users/citizenmatt/orgs","repos_url":"https://api.github.com/users/citizenmatt/repos","events_url":"https://api.github.com/users/citizenmatt/events{/privacy}","received_events_url":"https://api.github.com/users/citizenmatt/received_events","type":"User","site_admin":false},"labels":[{"id":565709233,"node_id":"MDU6TGFiZWw1NjU3MDkyMzM=","url":"https://api.github.com/repos/JetBrains/resharper-unity/labels/discussion","name":"discussion","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-03-21T11:19:16Z","updated_at":"2018-09-11T23:06:28Z","closed_at":null,"author_association":"MEMBER","body":"ReSharper/Rider will parse source code based on the current \"context\", which is usually the current project configuration - e.g. Debug or Release. As part of that, various preprocessor symbols can be defined - `DEBUG` and `TRACE` are common. Unity will also add symbols such as `UNITY_5_3_OR_NEWER`, `ENABLE_SPRITES` and `UNITY_EDITOR`.\r\n\r\nThese symbols can be used to switch compilation, for example:\r\n\r\n```csharp\r\n   var a = 23;\r\n#if UNITY_EDITOR\r\n   a = a * 3;\r\n#else\r\n   a = a * 6;\r\n#endif\r\n```\r\n\r\nReSharper/Rider will only parse the branch of the `#if` statement that is active for the current context. It doesn't parse the inactive branch. This is for several reasons. For example, there is no guarantee that the inactive branch(es) are correct - people use preprocessor symbols as a means of commenting out.\r\n\r\nBut it's also because the amount of work required to parse for all combinations is unfeasible in an interactive application - one sample Unity project I have here has 66 symbols, the combination required to get full coverage here is huge. \r\n\r\nAnd indeed, even if we did parse all combinations, running inspections and refactoring would now be greatly complicated - values can be initialised more than once, but not at all on another branch. There might be a chance of a null reference on one branch, but the variable might be unused on another. Understanding all of these combinations, merging the results and presenting useful information to the user is a significant problem.\r\n\r\nSo ReSharper/Rider will only run analysis, inspections, refactorings and so on, based on the current context. Switching context (such as changing from Debug to Release) will change the active pre-processor symbol set and re-run analysis. Essentially, ReSharper/Rider provide help for the current compile target only.\r\n\r\nBut this means that various refactorings and inspections can miss code in inactive branches (e.g. renaming a variable used in an inactive branch, find usages of a method that's also used in an inactive branch).\r\n\r\n**This issue is NOT tracking a fix to this problem.**\r\n\r\nThis is a fundamental constraint on the way ReSharper can and does work, and is a non-trivial problem to solve. Instead this issue has two purposes - firstly to serve as an explanation why ReSharper/Rider behave like this. Secondly, to better understand how Unity uses preprocessor symbols, in case there is a more targeted approach ReSharper/Rider could take given a specific use case.\r\n\r\nSo the question is: how do Unity developers use preprocessor symbols? Are all of the 66 symbols in my test project used independently, or is there actually a more constrained set of contexts? Say, targeting multiple platforms (how many?) that each have a set of capabilities, which require, e.g. `ENABLE_AUDIO` on one, but not on another? Are there other uses of `#if`? \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/comments/420455823","html_url":"https://github.com/JetBrains/resharper-unity/issues/125#issuecomment-420455823","issue_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/125","id":420455823,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDQ1NTgyMw==","user":{"login":"ctide","id":53454,"node_id":"MDQ6VXNlcjUzNDU0","avatar_url":"https://avatars2.githubusercontent.com/u/53454?v=4","gravatar_id":"","url":"https://api.github.com/users/ctide","html_url":"https://github.com/ctide","followers_url":"https://api.github.com/users/ctide/followers","following_url":"https://api.github.com/users/ctide/following{/other_user}","gists_url":"https://api.github.com/users/ctide/gists{/gist_id}","starred_url":"https://api.github.com/users/ctide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctide/subscriptions","organizations_url":"https://api.github.com/users/ctide/orgs","repos_url":"https://api.github.com/users/ctide/repos","events_url":"https://api.github.com/users/ctide/events{/privacy}","received_events_url":"https://api.github.com/users/ctide/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T23:06:28Z","updated_at":"2018-09-11T23:06:28Z","author_association":"NONE","body":"The issue #3 reported in the previous comment:\r\n\r\n```\r\nnotice that rider moved the { and the code is now invalid and no longer compiles.\r\n```\r\n\r\nIs a deal breaker for us, too. We were really hoping to standardize on a set of ReSharper rules and just let code cleanup manage all of our code guidelines for us, but it unfortunately breaks our code at the moment."}}
{"actor":{"display_login":"ctide"}}