Exemple #1
0
        public CodeEditor.Installation[] PathCallback()
        {
            var res = RiderPathLocator.GetAllRiderPaths()
                      .Select(riderInfo => new CodeEditor.Installation
            {
                Path = riderInfo.Path,
                Name = riderInfo.Presentation
            })
                      .ToList();

            var editorPath = RiderScriptEditor.CurrentEditor;

            if (RiderScriptEditor.IsRiderInstallation(editorPath) &&
                !res.Any(a => a.Path == editorPath) &&
                FileSystemUtil.EditorPathExists(editorPath))
            {
                // External editor manually set from custom location
                var info         = new RiderPathLocator.RiderInfo(editorPath, false);
                var installation = new CodeEditor.Installation
                {
                    Path = info.Path,
                    Name = info.Presentation
                };
                res.Add(installation);
            }

            return(res.ToArray());
        }
 private static void ShowWarningOnUnexpectedScriptEditor(string path)
 {
     // Show warning, when Unity was started from Rider, but external editor is different https://github.com/JetBrains/resharper-unity/issues/1127
     try
     {
         var args = Environment.GetCommandLineArgs();
         var commandlineParser = new CommandLineParser(args);
         if (commandlineParser.Options.ContainsKey("-riderPath"))
         {
             var originRiderPath = commandlineParser.Options["-riderPath"];
             var originRealPath  = GetEditorRealPath(originRiderPath);
             var originVersion   = RiderPathLocator.GetBuildNumber(originRealPath);
             var version         = RiderPathLocator.GetBuildNumber(path);
             if (originVersion != null && originVersion != version)
             {
                 Debug.LogWarning("Unity was started by a version of Rider that is not the current default external editor. Advanced integration features cannot be enabled.");
                 Debug.Log($"Unity was started by Rider {originVersion}, but external editor is set to: {path}");
             }
         }
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Exemple #3
0
 public CodeEditor.Installation[] PathCallback()
 {
     return(RiderPathLocator.GetAllRiderPaths()
            .Select(riderInfo => new CodeEditor.Installation
     {
         Path = riderInfo.Path,
         Name = riderInfo.Presentation
     })
            .ToArray());
 }
Exemple #4
0
        public void Invalidate(string editorInstallationPath)
        {
            currentEditorVersion = RiderPathLocator.GetBuildNumber(editorInstallationPath);
            if (!Version.TryParse(currentEditorVersion, out var version))
            {
                shouldLoadEditorPlugin = false;
            }

            shouldLoadEditorPlugin = version >= new Version("191.7141.156");
        }
Exemple #5
0
        public static bool ShouldLoadEditorPlugin(string path)
        {
            var ver = RiderPathLocator.GetBuildNumber(path);

            if (!Version.TryParse(ver, out var version))
            {
                return(false);
            }

            return(version >= new Version("191.7141.156"));
        }
        public void Invalidate(string editorInstallationPath)
        {
            editorBuildNumber = RiderPathLocator.GetBuildNumber(editorInstallationPath);
            productInfo       = RiderPathLocator.GetBuildVersion(editorInstallationPath);
            if (editorBuildNumber == null)
            {
                shouldLoadEditorPlugin = false;
            }

            shouldLoadEditorPlugin = editorBuildNumber >= new Version("191.7141.156");
        }
    public void Invalidate(string editorInstallationPath)
    {
      var riderBuildNumber = RiderPathLocator.GetBuildNumber(editorInstallationPath);
      editorBuildNumber = riderBuildNumber.ToSerializableVersion();
      productInfo = RiderPathLocator.GetBuildVersion(editorInstallationPath);
      if (riderBuildNumber == null)
        shouldLoadEditorPlugin = false;

      shouldLoadEditorPlugin = riderBuildNumber >= new Version("191.7141.156");

      if (RiderPathUtil.IsRiderDevEditor(editorInstallationPath))
      {
        shouldLoadEditorPlugin = true;
        editorBuildNumber = new SerializableVersion(new Version("999.999.999.999"));
      }
    }
Exemple #8
0
    public void Invalidate(string editorInstallationPath, bool shouldInvalidatePrevEditorBuildNumber = false)
    {
      var riderBuildNumber = RiderPathLocator.GetBuildNumber(editorInstallationPath);
      editorBuildNumber = riderBuildNumber.ToSerializableVersion();
      if (shouldInvalidatePrevEditorBuildNumber)
        prevEditorBuildNumber = editorBuildNumber;
      productInfo = RiderPathLocator.GetBuildVersion(editorInstallationPath);
      if (riderBuildNumber == null) // if we fail to parse for some reason
        shouldLoadEditorPlugin = true;

      shouldLoadEditorPlugin = riderBuildNumber >= new Version("191.7141.156");

      if (RiderPathUtil.IsRiderDevEditor(editorInstallationPath))
      {
        shouldLoadEditorPlugin = true;
        editorBuildNumber = new SerializableVersion(new Version("999.999.999.999"));
      }
    }
        static RiderScriptEditor()
        {
            try
            {
                var projectGeneration = new ProjectGeneration.ProjectGeneration();
                var editor            = new RiderScriptEditor(new Discovery(), projectGeneration);
                CodeEditor.Register(editor);
                var path = GetEditorRealPath(CurrentEditor);

                if (IsRiderInstallation(path))
                {
                    RiderPathLocator.RiderInfo[] installations = null;

                    if (!RiderScriptEditorData.instance.initializedOnce)
                    {
                        installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        // is likely outdated
                        if (installations.Any() && installations.All(a => GetEditorRealPath(a.Path) != path))
                        {
                            if (RiderPathLocator.GetIsToolbox(path)) // is toolbox - update
                            {
                                var toolboxInstallations = installations.Where(a => a.IsToolbox).ToArray();
                                if (toolboxInstallations.Any())
                                {
                                    var newEditor = toolboxInstallations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                                else
                                {
                                    var newEditor = installations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                            }
                            else // is non toolbox - notify
                            {
                                var newEditorName = installations.Last().Presentation;
                                Debug.LogWarning($"Consider updating External Editor in Unity to Rider {newEditorName}.");
                            }
                        }

                        ShowWarningOnUnexpectedScriptEditor(path);
                        RiderScriptEditorData.instance.initializedOnce = true;
                    }

                    if (!FileSystemUtil.EditorPathExists(path)) // previously used rider was removed
                    {
                        if (installations == null)
                        {
                            installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        }
                        if (installations.Any())
                        {
                            var newEditor = installations.Last().Path;
                            CodeEditor.SetExternalScriptEditor(newEditor);
                            path = newEditor;
                        }
                    }
                    RiderScriptEditorData.instance.Init();

                    editor.CreateSolutionIfDoesntExist();
                    if (RiderScriptEditorData.instance.shouldLoadEditorPlugin)
                    {
                        editor.m_Initiliazer.Initialize(path);
                    }

                    InitProjectFilesWatcher();
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
        static RiderScriptEditor()
        {
            try
            {
                // todo: make ProjectGeneration lazy
                var projectGeneration = new ProjectGeneration.ProjectGeneration();
                var editor            = new RiderScriptEditor(new Discovery(), projectGeneration);
                CodeEditor.Register(editor);
                var path = GetEditorRealPath(CurrentEditor);

                if (IsRiderInstallation(path))
                {
                    RiderPathLocator.RiderInfo[] installations = null;

                    if (!RiderScriptEditorData.instance.initializedOnce)
                    {
                        installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        // is likely outdated
                        if (installations.Any() && installations.All(a => GetEditorRealPath(a.Path) != path))
                        {
                            if (RiderPathLocator.GetIsToolbox(path)) // is toolbox - update
                            {
                                var toolboxInstallations = installations.Where(a => a.IsToolbox).ToArray();
                                if (toolboxInstallations.Any())
                                {
                                    var newEditor = toolboxInstallations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                                else
                                {
                                    var newEditor = installations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                            }
                            else // is non toolbox - notify
                            {
                                var newEditorName = installations.Last().Presentation;
                                Debug.LogWarning($"Consider updating External Editor in Unity to Rider {newEditorName}.");
                            }
                        }

                        ShowWarningOnUnexpectedScriptEditor(path);
                        RiderScriptEditorData.instance.initializedOnce = true;
                    }

                    if (!FileSystemUtil.EditorPathExists(path)) // previously used rider was removed
                    {
                        if (installations == null)
                        {
                            installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        }
                        if (installations.Any())
                        {
                            var newEditor = installations.Last().Path;
                            CodeEditor.SetExternalScriptEditor(newEditor);
                            path = newEditor;
                        }
                    }

                    RiderScriptEditorData.instance.Init();

                    editor.CreateSolutionIfDoesntExist();
                    if (RiderScriptEditorData.instance.shouldLoadEditorPlugin)
                    {
                        editor.m_Initiliazer.Initialize(path);
                    }

                    RiderFileSystemWatcher.InitWatcher(
                        Directory.GetCurrentDirectory(), "*.*", (sender, args) =>
                    {
                        var extension = Path.GetExtension(args.Name);
                        if (extension == ".sln" || extension == ".csproj")
                        {
                            RiderScriptEditorData.instance.hasChanges = true;
                        }
                    });

                    RiderFileSystemWatcher.InitWatcher(
                        Path.Combine(Directory.GetCurrentDirectory(), "Library"),
                        "EditorOnlyScriptingUserSettings.json",
                        (sender, args) => { RiderScriptEditorData.instance.hasChanges = true; });

                    RiderFileSystemWatcher.InitWatcher(
                        Path.Combine(Directory.GetCurrentDirectory(), "Packages"),
                        "manifest.json", (sender, args) => { RiderScriptEditorData.instance.hasChanges = true; });

                    // can't switch to non-deprecated api, because UnityEditor.Build.BuildPipelineInterfaces.processors is internal
#pragma warning disable 618
                    EditorUserBuildSettings.activeBuildTargetChanged += () =>
#pragma warning restore 618
                    {
                        RiderScriptEditorData.instance.hasChanges = true;
                    };
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
        static RiderScriptEditor()
        {
            try
            {
                var projectGeneration = new ProjectGeneration();
                var editor            = new RiderScriptEditor(new Discovery(), projectGeneration);
                CodeEditor.Register(editor);
                var path = GetEditorRealPath(CodeEditor.CurrentEditorInstallation);

                if (IsRiderInstallation(path))
                {
                    if (!RiderScriptEditorData.instance.InitializedOnce)
                    {
                        var installations = editor.Installations;
                        // is toolbox and outdated - update
                        if (installations.Any() && RiderPathLocator.IsToolbox(path) && installations.All(a => a.Path != path))
                        {
                            var toolboxInstallations = installations.Where(a => a.Name.Contains("(JetBrains Toolbox)")).ToArray();
                            if (toolboxInstallations.Any())
                            {
                                var newEditor = toolboxInstallations.Last().Path;
                                CodeEditor.SetExternalScriptEditor(newEditor);
                                path = newEditor;
                            }
                            else
                            {
                                var newEditor = installations.Last().Path;
                                CodeEditor.SetExternalScriptEditor(newEditor);
                                path = newEditor;
                            }
                        }

                        // exists, is non toolbox and outdated - notify
                        if (installations.Any() && FileSystemUtil.EditorPathExists(path) && installations.All(a => a.Path != path))
                        {
                            var newEditorName = installations.Last().Name;
                            Debug.LogWarning($"Consider updating External Editor in Unity to Rider {newEditorName}.");
                        }

                        ShowWarningOnUnexpectedScriptEditor(path);
                        RiderScriptEditorData.instance.InitializedOnce = true;
                    }

                    if (!FileSystemUtil.EditorPathExists(path)) // previously used rider was removed
                    {
                        var installations = editor.Installations;
                        if (installations.Any())
                        {
                            var newEditor = installations.Last().Path;
                            CodeEditor.SetExternalScriptEditor(newEditor);
                            path = newEditor;
                        }
                    }
                    RiderScriptEditorData.instance.Init();

                    editor.CreateSolutionIfDoesntExist();
                    if (RiderScriptEditorData.instance.shouldLoadEditorPlugin)
                    {
                        editor.m_Initiliazer.Initialize(path);
                    }

                    InitProjectFilesWatcher();
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }