{"action":"created","issue":{"url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/475","repository_url":"https://api.github.com/repos/JetBrains/resharper-unity","labels_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/475/labels{/name}","comments_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/475/comments","events_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/475/events","html_url":"https://github.com/JetBrains/resharper-unity/issues/475","id":308305277,"number":475,"title":"Opening files in \"packages\" in Unity 2018.1","user":{"login":"SugoiDev","id":7355630,"avatar_url":"https://avatars0.githubusercontent.com/u/7355630?v=4","gravatar_id":"","url":"https://api.github.com/users/SugoiDev","html_url":"https://github.com/SugoiDev","followers_url":"https://api.github.com/users/SugoiDev/followers","following_url":"https://api.github.com/users/SugoiDev/following{/other_user}","gists_url":"https://api.github.com/users/SugoiDev/gists{/gist_id}","starred_url":"https://api.github.com/users/SugoiDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SugoiDev/subscriptions","organizations_url":"https://api.github.com/users/SugoiDev/orgs","repos_url":"https://api.github.com/users/SugoiDev/repos","events_url":"https://api.github.com/users/SugoiDev/events{/privacy}","received_events_url":"https://api.github.com/users/SugoiDev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-24T22:43:06Z","updated_at":"2018-03-25T00:32:42Z","closed_at":null,"author_association":"NONE","body":"2018.1 is finally using packages.\r\n\r\nThe packages folder is a sibling of the Assets folder, and any packages there will be compiled and have a csproj created for them.\r\n\r\nThey'll be added to the sln as if they were in the Assets folder itself.\r\n\r\nI use a console enhancement that allows me to override the opening of an asset when double clicking the console entry.\r\n\r\nI can extract the path of the file to open, as well as a line number.\r\n\r\nThe problem is that the [OnOpenAssetHandler.OnOpenedAsset](https://github.com/JetBrains/resharper-unity/blob/c98a0814456d6f1a8038c26c8da6770eb1ac14bc/unity/JetBrains.Rider.Unity.Editor/EditorPlugin/OnOpenAssetHandler.cs#L30) only accepts an instanceID with line number.\r\n\r\nSince files in packages are not under the Assets folder, they don't have the concept of instanceID, neither are UnityObjects (so we can't do the checks for assetObject.GetType().ToString() against \"UnityEditor.MonoScript\", for example).\r\n\r\n---\r\n\r\nA way to solve this, is to provide a public method similar to `PluginEntryPoint.CallRider`, but with a signature of `string fileName, int lineNumber`\r\n\r\nThis involves refactoring the `OnOpenAssetHandler.OnOpenedAsset` to separate the Unity part of the part that does the raw actual opening/activation of Rider.\r\n"},"comment":{"url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/comments/375935660","html_url":"https://github.com/JetBrains/resharper-unity/issues/475#issuecomment-375935660","issue_url":"https://api.github.com/repos/JetBrains/resharper-unity/issues/475","id":375935660,"user":{"login":"SugoiDev","id":7355630,"avatar_url":"https://avatars0.githubusercontent.com/u/7355630?v=4","gravatar_id":"","url":"https://api.github.com/users/SugoiDev","html_url":"https://github.com/SugoiDev","followers_url":"https://api.github.com/users/SugoiDev/followers","following_url":"https://api.github.com/users/SugoiDev/following{/other_user}","gists_url":"https://api.github.com/users/SugoiDev/gists{/gist_id}","starred_url":"https://api.github.com/users/SugoiDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SugoiDev/subscriptions","organizations_url":"https://api.github.com/users/SugoiDev/orgs","repos_url":"https://api.github.com/users/SugoiDev/repos","events_url":"https://api.github.com/users/SugoiDev/events{/privacy}","received_events_url":"https://api.github.com/users/SugoiDev/received_events","type":"User","site_admin":false},"created_at":"2018-03-25T00:32:42Z","updated_at":"2018-03-25T00:32:42Z","author_association":"NONE","body":"I'm working on an example project, for a issue with Rider not recognizing C#7 in package items.\r\nWill post soon and comment back here.\r\n\r\n---\r\n\r\nIn the meantime,\r\n\r\n>Do you have any links that describe about the .csproj generation\r\n\r\nFrom what I gathered, it uses the same hooks as the normal generation.\r\nThey are even processed and have \"latest\" as LangVersion, and 4.7 for framework version.\r\n\r\n\r\n>What kind of log message are you double clicking?\r\n\r\nLog messages coming from scripts in a package.\r\n\r\n>Also, I’m not too sure what you mean with the refactoring of OnOpenedAsset - could you elaborate please? \r\n\r\nOf course.\r\nCurrently, it begins with this:\r\n```\r\npublic bool OnOpenedAsset(int instanceID, int line)\r\n{\r\n  UnityEngine.Object assetObject = EditorUtility.InstanceIDToObject(instanceID);\r\n  string fullPath = Path.GetFullPath(AssetDatabase.GetAssetPath(assetObject));\r\n  if (!(assetObject.GetType().ToString() == \"UnityEditor.MonoScript\") && !(assetObject.GetType().ToString() == \"UnityEngine.Shader\") && (!(assetObject.GetType().ToString() == \"UnityEngine.TextAsset\") || !EditorSettings.externalVersionControl.Contains(Path.GetExtension(fullPath).Substring(1))))\r\n    return false;\r\n```\r\n\r\nThis is the \"Unity\" part. It deals with `EditorUtility` and `AssetDatabase`. \r\nIn the end, it wants to extract `fullPath` from the given instanceID. Also, since we have a UnityEngine.Object, we can also check its type and make sure the Rider can open that.\r\n\r\nThe rest of the method is generic and would work perfectly as long as it was fed a `string fullPath` and a `in line`.\r\n\r\nSo this \"second half\" of the method could be its own method. Maybe an overload, like `OnOpenedAsset(string fullPath, int line)`\r\n\r\nThen, the current `OnOpenedAsset(int instanceID, int line)` could be simplified to this:\r\n\r\n```\r\npublic bool OnOpenedAsset(int instanceID, int line)\r\n{\r\n  //the Unity part, like above\r\n  \r\n  return OnOpenedAsset(fullPath, line);\r\n}\r\n```\r\n\r\nTo complete this and get it working on the user side, we would would need to add a `public static bool OnOpenedAsset(string fullPath, int line)` (and maybe  `public static bool OnOpenedAsset(int instanceID, int line)`, for completion sake), to `PluginEntryPoint`.\r\n\r\n---\r\n\r\nWith those changes, the user can call either overload of `PluginEntryPoint.OnOpenedAsset()` and have the plugin handle opening the asset properly.\r\n\r\nHaving this would allow us to pass the `fullPath` directly, without depending on the `AssetDatabase`, and this would give us a way of opening a package item via a console that allows us to override how it opens something when double clicking a console log entry.\r\n\r\n---\r\n\r\nIn the future, the plugin could optionally override the double click handling on the normal Unity console and provide this feature out-of-the-box: double clicking log entries coming from package items will open the package item in Rider, as normal.\r\n"}}
{"actor":{"display_login":"SugoiDev"}}