Nerzhul500 avatar Nerzhul500 committed 84c790d

Namespace highlighting and renaming fixed (VB and C#)
Added tests for VB

Comments (0)

Files changed (27)

ReSpeller.RSTests/CSharpHighlightingsTest.cs

       get { return @"Highlightings\CSharp"; }
     }
 
-    /// <summary>
-    /// 
-    /// </summary>
-    /// <param name="testName"></param>
-    [Test]
     [TestCase("Class.cs")]
     [TestCase("Field.cs")]
     [TestCase("Local.cs")]
     [TestCase("Namespace.cs")]
     [TestCase("Property.cs")]
     [TestCase("Comment.cs")]
+    [TestCase("String.cs")]
     public void Test(string testName)
     {
       DoTestFiles(testName);

ReSpeller.RSTests/ReSpeller7.1.RSTests.csproj

     <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="TypoQuickFixTest.cs" />
+    <Compile Include="VBasicHighlightingsTest.cs" />
     <Compile Include="XmlHighlightingsTest.cs" />
     <Compile Include="CSharpHighlightingsTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

ReSpeller.RSTests/TypoQuickFixTest.cs

+using JetBrains.ReSharper.Feature.Services.Bulbs;
+using JetBrains.ReSharper.Intentions.CSharp.QuickFixes.Tests;
+using JetBrains.ReSharper.Intentions.Extensibility;
+using NUnit.Framework;
+
+namespace ReSpeller.RSTests
+{
+#warning Replace 'IQuickFix' with your quick-fix name
+  [TestFixture]
+  public class TypoQuickFixTestTest : CSharpQuickFixTestBase<IQuickFix>
+  {
+    protected override string RelativeTestDataPath
+    {
+      get { return @"Path\To\Test\File"; }
+    }
+
+    [Test]
+    public void Test()
+    {
+      DoTestFiles("test01.cs");
+    }
+  }
+}

ReSpeller.RSTests/VBasicHighlightingsTest.cs

+using JetBrains.Application.Settings;
+using JetBrains.ReSharper.Daemon;
+using JetBrains.ReSharper.Daemon.CSharp;
+using JetBrains.ReSharper.DaemonTests.VB;
+using NUnit.Framework;
+using ReSpeller.Highlightings;
+
+namespace ReSpeller.RSTests
+{
+  [TestFixture]
+  public class VBasicHighlightingsTest : VBHighlightingTestBase
+  {
+    protected override bool HighlightingPredicate(IHighlighting highlighting, IContextBoundSettingsStore settingsstore)
+    {
+      return highlighting is StringLiteralTypoHighlighting 
+             || highlighting is IdentifierTypoHighlighting
+             || highlighting is CommentTypoHighlighting;
+    }
+
+    protected override string RelativeTestDataPath
+    {
+      get { return @"Highlightings\VBasic"; }
+    }
+
+    [TestCase("Module.vb")]
+    [TestCase("Field.vb")]
+    [TestCase("Local.vb")]
+    [TestCase("Method.vb")]
+    [TestCase("Namespace.vb")]
+    [TestCase("Property.vb")]
+    [TestCase("Comment.vb")]
+    [TestCase("String.vb")]
+    public void Test(string testName)
+    {
+      DoTestFiles(testName);
+    }
+  }
+}

ReSpeller.RSTests/test/data/Highlightings/CSharp/String.cs

+class MyClass
+{
+
+  public void MyMethod()
+  {
+    string s1 = "it's wrongword and MySuperWrongword123 string";
+    string s2 = @"verbatim wrongword string";
+    string s3 = "string with \"wrongword escaped\" symbols"; 
+  }
+}

ReSpeller.RSTests/test/data/Highlightings/CSharp/String.cs.gold

+class MyClass
+{
+
+  public void MyMethod()
+  {
+    string s1 = "it's |wrongword|(0) and MySuper|Wrongword|(1)123 string";
+    string s2 = @"verbatim |wrongword|(2) string";
+    string s3 = "string with \"|wrongword|(3) escaped\" symbols"; 
+  }
+}
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in string: "wrongword"
+(1): ReSharper Suggestion: Typo in string: "Wrongword"
+(2): ReSharper Suggestion: Typo in string: "wrongword"
+(3): ReSharper Suggestion: Typo in string: "wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Comment.vb

+' wrongword comment with myWrongword123
+
+''' <summary>
+''' wrongword comment with myWrongword123
+''' </summary>
+''' <wrongword>asf</wrongword>
+Module MyModule 
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Comment.vb.gold

+' |wrongword|(0) comment with my|Wrongword|(1)123
+
+''' <summary>
+''' |wrongword|(2) comment with my|Wrongword|(3)123
+''' </summary>
+''' <|wrongword|(4)>asf</|wrongword|(5)>
+Module MyModule 
+End Module
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in comment: "wrongword"
+(1): ReSharper Suggestion: Typo in comment: "Wrongword"
+(2): ReSharper Suggestion: Typo in comment: "wrongword"
+(3): ReSharper Suggestion: Typo in comment: "Wrongword"
+(4): ReSharper Suggestion: Typo in comment: "wrongword"
+(5): ReSharper Suggestion: Typo in comment: "wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Field.vb

+Module TestModule
+
+    Private myWrongwordField As String
+
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Field.vb.gold

+Module TestModule
+
+    Private _wrongwordField As String
+
+End Module
+
+---------------------------------------------------------

ReSpeller.RSTests/test/data/Highlightings/VBasic/Local.vb

+Module MyModule
+
+    Sub TestMethod()
+        Dim wrongword As String = "qwe"
+    End Sub
+
+    Function MyFunc() As String
+        Dim superWrongwordInt = 2
+    End Function
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Local.vb.gold

+Module MyModule
+
+    Sub TestMethod()
+        Dim |wrongword|(0) As String = "qwe"
+    End Sub
+
+    Function MyFunc() As String
+        Dim super|Wrongword|Int = 2
+    End Function
+End Module
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in identifier: "wrongword"
+(1): ReSharper Suggestion: Typo in identifier: "Wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Method.vb

+Module MyModule
+
+    Sub MyWrongwordMethod()
+        
+    End Sub
+
+    Function GetWrongword123() As String
+        Return ""
+    End Function
+
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Method.vb.gold

+Module MyModule
+
+    Sub My|Wrongword|(0)Method()
+        
+    End Sub
+
+    Function Get|Wrongword|(1)123() As String
+        Return ""
+    End Function
+
+End Module
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in identifier: "Wrongword"
+(1): ReSharper Suggestion: Typo in identifier: "Wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Module.vb

+Module MyWrongwordModule	
+
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Module.vb.gold

+Module My|Wrongword|(0)Module	
+
+End Module
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in identifier: "Wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Namespace.vb

+Namespace MyWrongword123
+End Namespace
+
+Namespace GoodNS
+End Namespace
+
+Namespace GoodNS.MyWrongwordNS
+End Namespace
+

ReSpeller.RSTests/test/data/Highlightings/VBasic/Namespace.vb.gold

+Namespace My|Wrongword|(0)123
+End Namespace
+
+Namespace GoodNS
+End Namespace
+
+Namespace GoodNS.My|Wrongword|(1)NS
+End Namespace
+
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in identifier: "Wrongword"
+(1): ReSharper Suggestion: Typo in identifier: "Wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/Property.vb

+Module MyModule
+    
+	Private _field As String
+
+    Public Property MyWrongword123Prop() As String
+        Get
+            Return _s
+        End Get
+        Set(ByVal value As String)
+            _s = value
+        End Set
+    End Property
+    
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/Property.vb.gold

+Module MyModule
+    
+	Private _field As String
+
+    Public Property My|Wrongword|(0)123Prop() As String
+        Get
+            Return _s
+        End Get
+        Set(ByVal value As String)
+            _s = value
+        End Set
+    End Property
+    
+End Module
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in identifier: "Wrongword"

ReSpeller.RSTests/test/data/Highlightings/VBasic/String.vb

+Module MyModule
+
+    Sub TestMethod()
+        Dim s As String = "it's wrongword and MySuperWrongword123 string"
+    End Sub
+
+End Module

ReSpeller.RSTests/test/data/Highlightings/VBasic/String.vb.gold

+Module MyModule
+
+    Sub TestMethod()
+        Dim s As String = "it's |wrongword|(0) and MySuper|Wrongword|(1)123 string"
+    End Sub
+
+End Module
+
+---------------------------------------------------------
+(0): ReSharper Suggestion: Typo in string: "wrongword"
+(1): ReSharper Suggestion: Typo in string: "Wrongword"

ReSpeller/Analyzers/AnalyzerHelper.cs

     }
 
     public static void GenerateIdentifierHighlightings(IHighlightingConsumer consumer, List<TextPart> innerNameParts, DocumentRange elementRange, string prefix,
-                                                       string suffix, IDeclaredElement declaredElement,
+                                                       string suffix, IDeclaration declaration,
                                                        bool isNamespace, ITreeNode treeNode)
     {
       var checker = Shell.Instance.GetComponent<ISpellChecker>();
           if (!checker.CheckWordSpelling(p.Text))
           {
             DocumentRange partRange = RangeUtils.GetPartRange(elementRange, p, prefix.Length, suffix.Length);
-            consumer.AddHighlighting(new IdentifierTypoHighlighting(treeNode, declaredElement, p, isNamespace),
+            consumer.AddHighlighting(new IdentifierTypoHighlighting(treeNode, declaration, p, isNamespace),
                                      partRange, treeNode.GetContainingFile());
           }
         }
 
     public static List<TextPart> DecomposeNamespace(ITreeNode treeNode, INamespaceDeclaration namespaceDeclaration, out string prefix, out string suffix)
     {
+      return DoDecomposeName(treeNode, namespaceDeclaration.DeclaredElement, namespaceDeclaration.DeclaredName, out prefix, out suffix);
+    }
+
+    public static List<TextPart> DecomposeFullNamespace(ITreeNode treeNode, INamespaceDeclaration namespaceDeclaration, out string prefix, out string suffix)
+    {
       return DoDecomposeName(treeNode, namespaceDeclaration.DeclaredElement, namespaceDeclaration.QualifiedName, out prefix, out suffix);
     }
 
       INamingPolicyProvider namingPolicyProvider = psiServices.Naming.Policy
         .GetPolicyProvider(psiLanguageType, psiSourceFile);
 
-      //string shortName = declaredElement.ShortName;
+      //string shortName = declaration.ShortName;
 
       Name name = namingManager.Parsing.Parse(fullName, policy.NamingRule, namingPolicyProvider);
       var sb = new StringBuilder(fullName.Length);

ReSpeller/Analyzers/IdentifierTypoAnalyzer.cs

 using JetBrains.ReSharper.Daemon.Stages;
 using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
 using JetBrains.ReSharper.Psi;
-using JetBrains.ReSharper.Psi.CSharp.Tree;
 using JetBrains.ReSharper.Psi.Tree;
+using JetBrains.ReSharper.Psi.VB;
+using JetBrains.ReSharper.Psi.VB.Tree;
 using ReSpeller.Highlightings;
 using ReSpeller.SpellEngine;
+using IAccessorDeclaration = JetBrains.ReSharper.Psi.CSharp.Tree.IAccessorDeclaration;
 
 namespace ReSpeller.Analyzers
 {
 
     protected override void Run(IIdentifier element, ElementProblemAnalyzerData analyzerData, IHighlightingConsumer consumer)
     {
-      var declaration = element.Parent as IDeclaration;
+      var containingNode = element.GetContainingNode<INamespaceDeclaration>();
+      IDeclaration declaration = null;
+      
+      if (element.Language.Is<VBLanguage>() && element.Parent is IQualifiedNamespaceName)
+      {
+        //var namespaceName = element.Parent.Parent as INamespaceDeclaration;
+        //namespaceName.
+        
+        declaration = element.Parent.Parent as IDeclaration; // handle VB namespace
+      }
+      else
+      {
+        declaration = element.Parent as IDeclaration;        
+      }
       var treeNode = element as ITreeNode; 
       if (declaration is IAccessorDeclaration)
         return; // property getter or setter -> ignore
       if (isNamespace)
       {
         // fix identifier range if it is a namespace, e.g. ConsoleApplication.Namespace
-        elementRange = elementRange.ExtendLeft(namespaceDeclaration.QualifiedName.Length - element.Name.Length);
+        elementRange = elementRange.ExtendLeft(namespaceDeclaration.DeclaredName.Length - element.Name.Length);
       }
           
-      AnalyzerHelper.GenerateIdentifierHighlightings(consumer, innerNameParts, elementRange, prefix, suffix, declaredElement, isNamespace, treeNode);
+      AnalyzerHelper.GenerateIdentifierHighlightings(consumer, innerNameParts, elementRange, prefix, suffix, declaration, isNamespace, treeNode);
     }
 
     #endregion

ReSpeller/Bulbs/AdvancedTypoRenameBulbItem.cs

 
 namespace ReSpeller.Bulbs
 {
-  class AdvancedTypoRenameBulbItem : IBulbItem
+  internal class AdvancedTypoRenameBulbItem : IBulbItem
   {
     private readonly IDeclaredElement myElement;
-    private readonly AsyncValue<List<string>> mySuggestedNames; 
+    private readonly AsyncValue<List<string>> mySuggestedNames;
 
     public AdvancedTypoRenameBulbItem(IDeclaredElement element, AsyncValue<List<string>> suggestedNames)
     {
     {
       var service = solution.GetComponent<RenameRefactoringService>();
       IRefactoringWorkflow workflow;
-        List<string> suggests = mySuggestedNames.Value;
-        if (myElement is INamespace)
+      List<string> suggests = mySuggestedNames.Value;
+      if (myElement is INamespace)
       {
         workflow = new RenameNamespaceWorkflowDecorator("NamespaceTypoRename", suggests);
       }
       }
       else
       {
-        workflow = new TypoRenameWorkflow(suggests, Shell.Instance.Locks, 
-                                          SearchDomainFactory.Instance, 
-                                          RenameRefactoringService.Instance, 
-                                          solution, 
+        workflow = new TypoRenameWorkflow(suggests, Shell.Instance.Locks,
+                                          SearchDomainFactory.Instance,
+                                          RenameRefactoringService.Instance,
+                                          solution,
                                           "TypoRename");
       }
-      Lifetimes.Using(lifetime => 
-        RefactoringActionUtil.ExecuteRefactoring(
-                    JetBrains.ActionManagement.ShellComponentsEx.ActionManager(Shell.Instance.Components)
-                      .DataContexts.CreateOnSelection(lifetime, DataRules.AddRule("DoTypoRenameWorkflow", 
-                      JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION, solution)), workflow));
-     }
+      Lifetimes.Using(lifetime =>
+                      RefactoringActionUtil.ExecuteRefactoring(
+                        JetBrains.ActionManagement.ShellComponentsEx.ActionManager(Shell.Instance.Components)
+                                 .DataContexts.CreateOnSelection(lifetime, DataRules.AddRule("DoTypoRenameWorkflow",
+                                                                                             JetBrains.ProjectModel
+                                                                                                      .DataContext
+                                                                                                      .DataConstants
+                                                                                                      .SOLUTION,
+                                                                                             solution)), workflow));
+    }
 
     public string Text
     {
       get { return string.Format("Typo in \"{0}\". Rename to ...", myElement.ShortName); }
     }
   }
-}
+}

ReSpeller/Highlightings/IdentifierTypoHighlighting.cs

 using JetBrains.ReSharper.Daemon;
-using JetBrains.ReSharper.Feature.Services.Tips;
-using JetBrains.ReSharper.Psi;
 using JetBrains.ReSharper.Psi.Tree;
 using ReSpeller.SpellEngine;
 
     internal const string SeverityId = "IdentifierTypo";
     private const string ToolTipFormatString = "Typo in identifier: \"{0}\"";
     private readonly ITreeNode myTreeNode;
-    private readonly IDeclaredElement myElement;
+    private readonly IDeclaration myDeclaration;
     private readonly bool myIsNamespace;
     private readonly TextPart myWrongPart;
 
-    public IdentifierTypoHighlighting(ITreeNode treeNode, IDeclaredElement element, TextPart wrongPart, bool isNamespace)
+    public IdentifierTypoHighlighting(ITreeNode treeNode, IDeclaration declaration, TextPart wrongPart, bool isNamespace)
     {
       myTreeNode = treeNode;
-      myElement = element;
+      myDeclaration = declaration;
       myWrongPart = wrongPart;
       myIsNamespace = isNamespace;
     }
       get { return myIsNamespace; }
     }
 
-    public IDeclaredElement Element
+    public IDeclaration Declaration
     {
-      get { return myElement; }
+      get { return myDeclaration; }
     }
 
     public TextPart WrongPart

ReSpeller/QuickFixes/TypoQuickFix.cs

 using System.Collections.Generic;
-using System.Windows.Controls;
 using JetBrains.Annotations;
 using JetBrains.Application;
 using JetBrains.ReSharper.Daemon;
 using JetBrains.ReSharper.Feature.Services.Bulbs;
 using JetBrains.ReSharper.Intentions.Extensibility;
 using JetBrains.ReSharper.Intentions.Extensibility.Menu;
+using JetBrains.ReSharper.Psi.Tree;
 using JetBrains.Util;
 using ReSpeller.Analyzers;
 using ReSpeller.Bulbs;
     public TypoQuickFix([NotNull] IdentifierTypoHighlighting highlighting)
     {
       myHighlighting = highlighting;
-      string prefix;
-      string suffix;
-      AsyncValue<List<string>> suggests = new AsyncValue<List<string>>(() =>
-                                                             {
-                                                               List<TextPart> decomposedName =
-                                                                 AnalyzerHelper.DecomposeName(highlighting.TreeNode,
-                                                                                              highlighting.Element,
-                                                                                              out prefix, out suffix);
-                                                               return mySuggestionGenerator.Generate(decomposedName,
-                                                                                                     prefix, suffix);
-                                                             });
+      var suggests = new AsyncValue<List<string>>(() =>
+                      {
+                        string prefix;
+                        string suffix;
+                        List<TextPart> decomposedName = highlighting.Declaration is INamespaceDeclaration 
+                          ? AnalyzerHelper.DecomposeFullNamespace(highlighting.TreeNode, highlighting.Declaration as INamespaceDeclaration, out prefix, out suffix) 
+                          : AnalyzerHelper.DecomposeName(highlighting.TreeNode, highlighting.Declaration.DeclaredElement, out prefix, out suffix);
+                        return mySuggestionGenerator.Generate(decomposedName, prefix, suffix);
+                      });
 
-      myBulbItems.Add(new AdvancedTypoRenameBulbItem(highlighting.Element, suggests));
+      myBulbItems.Add(new AdvancedTypoRenameBulbItem(highlighting.Declaration.DeclaredElement, suggests));
       string word = highlighting.WrongPart.Text;
       myBulbItems.Add(new AddToDictionaryBulbItem(word));
       myBulbItems.Add(new EditAddToDictionaryBulb(word));
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.