Esempio n. 1
0
        public void NavigateStep9()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial4_WhatsNewReSharper2017.1");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "LocalFunctions.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "ReSharper20171.LocalFunctions",
                                                                 "Factorial", 1, null, 0);

            var methodDecl = (IMethodDeclaration)node?.Parent;

            node = methodDecl?.Body.Statements[0];
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.StartOffset + 5, CaretVisualPlacement.Generic);
        }
Esempio n. 2
0
        public void NavigateStep9()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial3_WhatsNewReSharper2016.3");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "CodeGeneration.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "ReSharper20163.GenerateConstructorCheckForNull",
                                                                 null, 0, null, 0);
            var classDecl = (IClassDeclaration)node?.Parent;

            node = classDecl?.Body.LastChild?.PrevSibling?.PrevSibling?.PrevSibling;
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document = range.Document;
            var text     = $"{Environment.NewLine}\t\t";

            document.InsertText(range.TextRange.EndOffset, text);

            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.EndOffset + text.Length, CaretVisualPlacement.Generic);
        }
Esempio n. 3
0
        public void NavigateStep12()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial1_EssentialShortcuts");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "Essentials.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "Tutorial1_EssentialShortcuts.MyCircle", null, 0,
                                                                 null, 0);
            var classDecl = (IClassDeclaration)node?.Parent;

            node = classDecl?.Body.FirstChild;
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document = range.Document;
            var text     = $"{Environment.NewLine}\t\t";

            document.InsertText(range.TextRange.EndOffset, text);

            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.EndOffset + text.Length, CaretVisualPlacement.DontScrollIfVisible);
        }
Esempio n. 4
0
        public void NavigateStep29()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial3_WhatsNewReSharper2016.3");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "JoinLines.cs");

            Debug.Assert(file != null, "file != null");
            var namespaceDecl =
                file.NamespaceDeclarations.FirstOrDefault(
                    namespaceDeclaration => namespaceDeclaration.ShortName == "ReSharper20163");

            Debug.Assert(namespaceDecl != null, "namespaceDecl != null");
            var typeDecl =
                namespaceDecl.TypeDeclarations.FirstOrDefault(
                    declaration => declaration.CLRName == "ReSharper20163.JoinLines");

            var range = typeDecl.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }

            Debug.Assert(typeDecl != null, "typeDecl != null");
            var methodDecl = (IPropertyDeclaration)typeDecl.MemberDeclarations.FirstOrDefault(memberDeclaration =>
                                                                                              memberDeclaration.DeclaredName == "MyProperty");

            Debug.Assert(methodDecl != null, "methodDecl != null");
            Debug.Assert(methodDecl.FirstChild != null, "methodDecl.FirstChild != null");
            var startPos = methodDecl.FirstChild.GetNavigationRange().StartOffset.Offset;

            Debug.Assert(methodDecl.LastChild != null, "methodDecl.LastChild != null");
            var endPos = methodDecl.LastChild.GetNavigationRange().EndOffset.Offset;

            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            if (textControl == null)
            {
                return;
            }
            textControl.Caret.MoveTo(range.TextRange.EndOffset, CaretVisualPlacement.DontScrollIfVisible);
            var selection = new[]
            {
                new TextControlPosRange(textControl.Coords.FromDocOffset(startPos),
                                        textControl.Coords.FromDocOffset(endPos))
            };

            textControl.Selection.SetRanges(selection);
        }
Esempio n. 5
0
        public void Navigate(TutStep.TutorialStep step)
        {
            if (step.NavNode == null)
            {
                return;
            }

            if (step.NavNode.RunMethod != null)
            {
                RunCustomNavigation(step.NavNode.RunMethod);
                return;
            }

            if (step.NavNode.TypeName == null && step.NavNode.MethodName == null && step.NavNode.TextToFind == null)
            {
                return;
            }

            _shellLocks.ExecuteOrQueueReadLock(_lifetime, "Navigate", () =>
            {
                _psiFiles.CommitAllDocumentsAsync(() =>
                {
                    var project = PsiNavigationHelper.GetProjectByName(_solution, step.NavNode.ProjectName);

                    var file = PsiNavigationHelper.GetCSharpFile(project, step.NavNode.FileName);

                    var node = PsiNavigationHelper.GetTreeNodeForStep(file, step.NavNode.TypeName,
                                                                      step.NavNode.MethodName,
                                                                      step.NavNode.MethodNameOccurrence, step.NavNode.TextToFind, step.NavNode.TextToFindOccurrence);

                    if (node == null)
                    {
                        MessageBox.ShowExclamation("OOPS! Someone has changed the code in an unexpected way. " +
                                                   "That wasn't you, right?;) Anyway, now it would be better to restart tutorial.");
                    }
                    else
                    {
                        PsiNavigationHelper.NavigateToNode(_documentManager, _editorManager, node, true);
                    }
                });
            });
        }
Esempio n. 6
0
        public void NavigateStep3()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial1_EssentialShortcuts");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "Essentials.cs");
            var node    = file?.FirstChild;
            var range   = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.StartOffset, CaretVisualPlacement.DontScrollIfVisible);
        }
Esempio n. 7
0
        public void NavigateStep27()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial3_WhatsNewReSharper2016.3");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "InterpolatedStringsImprovement.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "ReSharper20163.InterpolatedStringsImprovement",
                                                                 null, 0, "=", 1);
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.EndOffset + 1, CaretVisualPlacement.DontScrollIfVisible);
        }
Esempio n. 8
0
        public void NavigateStep20()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial3_WhatsNewReSharper2016.3");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "LanguageInjections.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "ReSharper20163.LanguageInjections", null, 0,
                                                                 "private", 6);
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            textControl?.Caret.MoveTo(range.TextRange.StartOffset - 9, CaretVisualPlacement.DontScrollIfVisible);
        }
Esempio n. 9
0
        public void NavigateStep25()
        {
            var project = PsiNavigationHelper.GetProjectByName(Solution, "Tutorial3_WhatsNewReSharper2016.3");
            var file    = PsiNavigationHelper.GetCSharpFile(project, "MatchSimilarConstructs.cs");
            var node    = PsiNavigationHelper.GetTreeNodeForStep(file, "ReSharper20163.MatchSimilarConstructs", null, 0,
                                                                 "Second", 1);
            var range = node.GetDocumentRange();

            if (!range.IsValid())
            {
                return;
            }
            var document    = range.Document;
            var projectFile = DocumentManager.TryGetProjectFile(document);

            if (projectFile == null)
            {
                return;
            }

            var startPos    = range.TextRange.StartOffset - 5;
            var endPos      = range.TextRange.EndOffset;
            var textControl = EditorManager.OpenProjectFile(projectFile, true);

            if (textControl == null)
            {
                return;
            }
            textControl.Caret.MoveTo(range.TextRange.StartOffset - 5, CaretVisualPlacement.DontScrollIfVisible);
            var selection = new[]
            {
                new TextControlPosRange(textControl.Coords.FromDocOffset(startPos),
                                        textControl.Coords.FromDocOffset(endPos))
            };

            textControl.Selection.SetRanges(selection);
        }