Commits

Anonymous committed 88e31e5

Use solution level settings
Live SpellCheckerConfig

  • Participants
  • Parent commits 30778d8
  • Branches resharper8

Comments (0)

Files changed (25)

File ReSpeller.8.0/ReSpeller.8.0.csproj

       <DependentUpon>ReSpellerSettingsControl.xaml</DependentUpon>
       <Link>Settings\ReSpellerSettingsControl.xaml.cs</Link>
     </Compile>
+    <Compile Include="..\ReSpeller\Settings\SettingsSpellCheckerConfig.cs">
+      <Link>Settings\SettingsSpellCheckerConfig.cs</Link>
+    </Compile>
     <Compile Include="..\ReSpeller\Settings\Upgrade\UserDictionariesUpgrader.cs">
       <Link>Settings\Upgrade\UserDictionariesUpgrader.cs</Link>
     </Compile>

File ReSpeller.BasicTests/ReSpeller8.x.BasicTests.csproj

 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\JetBrains.ReSharper.SDK.Tests.8.1.555\build\JetBrains.ReSharper.SDK.Tests.Props" Condition="Exists('..\packages\JetBrains.ReSharper.SDK.Tests.8.1.555\build\JetBrains.ReSharper.SDK.Tests.Props')" />
+  <Import Project="..\packages\JetBrains.ReSharper.SDK.8.1.555\build\JetBrains.ReSharper.SDK.Props" Condition="Exists('..\packages\JetBrains.ReSharper.SDK.8.1.555\build\JetBrains.ReSharper.SDK.Props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="nunit.framework">
-      <HintPath>..\packages\NUnit.2.6.1\lib\nunit.framework.dll</HintPath>
-    </Reference>
     <Reference Include="Rhino.Mocks">
       <HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
     </Reference>
   <ItemGroup />
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
+  <Import Project="..\packages\JetBrains.ReSharper.SDK.8.1.555\build\JetBrains.ReSharper.SDK.Targets" Condition="Exists('..\packages\JetBrains.ReSharper.SDK.8.1.555\build\JetBrains.ReSharper.SDK.Targets')" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

File ReSpeller.BasicTests/SpellEngine/Dictionaries/UserInternalDictionaryTest.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
+using NUnit.Framework;
 using ReSpeller.SpellEngine.Dictionaries;
 using Rhino.Mocks;
 
     {
       myDictionaryEngine = MockRepository.GenerateMock<IDictionaryEngine>();
       myUserStorage = MockRepository.GenerateMock<IDictionaryStorage>();
+      myUserStorage.Expect(_ => _.GetContent()).Return(new string[0]);
       myInternalStorage = MockRepository.GenerateMock<IDictionaryStorage>();
+      myInternalStorage.Expect(_ => _.GetContent()).Return(new string[0]);
       myLanguage = "en_US";
       myUserInternalDictionary = new UserInternalDictionary(myDictionaryEngine, myLanguage, myUserStorage, myInternalStorage);
     }

File ReSpeller.BasicTests/packages.config

 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="NUnit" version="2.6.1" targetFramework="net40" />
+  <package id="JetBrains.ReSharper.SDK" version="8.1.555" targetFramework="net40" />
+  <package id="JetBrains.ReSharper.SDK.Tests" version="8.1.555" targetFramework="net40" />
   <package id="RhinoMocks" version="3.6.1" targetFramework="net40" />
 </packages>

File ReSpeller.RSTests/CSharpHighlightingsTest.cs

 using JetBrains.ReSharper.Daemon;
 using JetBrains.ReSharper.Daemon.CSharp;
 using JetBrains.Application.Settings;
-using JetBrains.ReSharper.Feature.Services.Tips;
-using JetBrains.ReSharper.Psi;
-using JetBrains.ReSharper.Psi.Naming;
 using NUnit.Framework;
 using ReSpeller.Highlightings;
 

File ReSpeller.RSTests/SpellEngine/SpellCheckerTest.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using JetBrains.Application;
+using System.Collections.Generic;
+using JetBrains.ProjectModel;
 using ReSpeller.SpellEngine;
 
 namespace ReSpeller.RSTests.SpellEngine
 {
-  [ShellComponent]
+  [SolutionComponent]
   public class SpellCheckerStub : ISpellChecker, ISingleLanguageWordStorage
   {
     public bool CheckWordSpelling(string word)

File ReSpeller.RSTests/SpellEngine/SuggestionGeneratorStub.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using JetBrains.Application;
+using JetBrains.ProjectModel;
 using ReSpeller.SpellEngine;
 
 namespace ReSpeller.RSTests.SpellEngine
 {
-    [ShellComponent]
+    [SolutionComponent]
     public class SuggestionGeneratorStub : SuggestionGenerator
     {
         public SuggestionGeneratorStub(ISpellChecker checker) : base(checker)

File ReSpeller/Analyzers/AnalyzerHelper.cs

       }      
     }
 
-    public static void GenerateIdentifierHighlightings(IHighlightingConsumer consumer, List<TextPart> innerNameParts, DocumentRange elementRange, string prefix,
-                                                       string suffix, IDeclaration declaration,
-                                                       bool isNamespace, ITreeNode treeNode, IDeclaredElement declaredElement)
+    public static void GenerateIdentifierHighlightings(ISpellChecker checker, IHighlightingConsumer consumer, List<TextPart> innerNameParts, DocumentRange elementRange, string prefix, string suffix, IDeclaration declaration, bool isNamespace, ITreeNode treeNode, IDeclaredElement declaredElement)
     {
       var partsForSuggest = innerNameParts;
       if (isNamespace)
         partsForSuggest = DecomposeFullNamespace(treeNode, declaration as INamespaceDeclaration,
           out prefix, out suffix);
       }
-      var checker = Shell.Instance.GetComponent<ISpellChecker>();
-      
+
       foreach (TextPart p in innerNameParts)
       {
         if (p.Type == TextPartType.Word && p.Text.Length > 2)

File ReSpeller/Analyzers/CommentTypoAnalyzer.cs

   [ElementProblemAnalyzer(new[] { typeof(IComment) })]
   public class CommentTypoAnalyzer : ElementProblemAnalyzer<IComment>
   {
-    private readonly ISpellChecker myChecker = Shell.Instance.GetComponent<ISpellChecker>();
+    private readonly ISpellChecker myChecker;
+
+    public CommentTypoAnalyzer(ISpellChecker spellChecker)
+    {
+      myChecker = spellChecker;
+    }
 
     protected override void Run(IComment element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
     {

File ReSpeller/Analyzers/IdentifierTypoAnalyzer.cs

   [ElementProblemAnalyzer(new[] {typeof (IIdentifier)}, HighlightingTypes = new[] {typeof(IdentifierTypoHighlighting)})]
   public class IdentifierTypoAnalyzer : ElementProblemAnalyzer<IIdentifier>
   {
-    #region IElementProblemAnalyzer Members
+    private readonly ISpellChecker mySpellChecker;
+
+    public IdentifierTypoAnalyzer(ISpellChecker spellChecker)
+    {
+      mySpellChecker = spellChecker;
+    }
 
     protected override void Run(IIdentifier element, ElementProblemAnalyzerData analyzerData, IHighlightingConsumer consumer)
     {
         // fix identifier range if it is a namespace, e.g. ConsoleApplication.Namespace
         elementRange = elementRange.ExtendLeft(namespaceDeclaration.DeclaredName.Length - element.Name.Length);
       }
-          
-      AnalyzerHelper.GenerateIdentifierHighlightings(consumer, innerNameParts, elementRange, prefix, suffix, declaration, isNamespace, treeNode, declaredElement);
+
+      AnalyzerHelper.GenerateIdentifierHighlightings(mySpellChecker, consumer, innerNameParts, elementRange, prefix, suffix, declaration, isNamespace, treeNode, declaredElement);
     }
-
-    #endregion
   }
 }

File ReSpeller/Analyzers/StringLiteralTypoAnalyzer.cs

-using JetBrains.Application;
 using JetBrains.DocumentModel;
 using JetBrains.ReSharper.Daemon.Stages;
 using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
   [ElementProblemAnalyzer(new[] { typeof(ILiteralExpression) })]
   public class StringLiteralTypoAnalyzer : ElementProblemAnalyzer<ILiteralExpression>
   {
-    private readonly ISpellChecker myChecker = Shell.Instance.GetComponent<ISpellChecker>();
+    private readonly ISpellChecker myChecker;
 
+    public StringLiteralTypoAnalyzer(ISpellChecker spellChecker)
+    {
+      myChecker = spellChecker;
+    }
 
     protected override void Run(ILiteralExpression element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
     {

File ReSpeller/Analyzers/XmlTypoAnalysis.cs

-using System.Collections.Generic;
-using JetBrains.Application;
 using JetBrains.DocumentModel;
 using JetBrains.ReSharper.Daemon.Stages;
 using JetBrains.ReSharper.Daemon.Xml.Stages;
 using JetBrains.ReSharper.Psi.Xml.Impl.Tree;
 using JetBrains.ReSharper.Psi.Xml.Tree;
 using JetBrains.ReSharper.Psi.Xml.XmlDocComments;
-using System.Linq;
 using ReSpeller.Highlightings;
 using ReSpeller.SpellEngine;
 
 {
   internal class XmlTypoAnalysis : XmlAnalysis
   {
-    private readonly ISpellChecker myChecker = Shell.Instance.GetComponent<ISpellChecker>();
+    private readonly ISpellChecker myChecker;
+
+    public XmlTypoAnalysis(ISpellChecker spellChecker)
+    {
+      myChecker = spellChecker;
+    }
 
     public override bool InteriorShouldBeProcessed(ITreeNode element)
     {
         string suffix;
         var nameDocRange = declaration.GetNameDocumentRange();
 
-        List<TextPart> decomposedName = AnalyzerHelper.DecomposeName(element, declaredElement, declaredName,
-          out prefix, out suffix);
-        AnalyzerHelper.GenerateIdentifierHighlightings(highlightings, decomposedName, nameDocRange, prefix,
+        var decomposedName = AnalyzerHelper.DecomposeName(element, declaredElement, declaredName, out prefix, out suffix);
+        AnalyzerHelper.GenerateIdentifierHighlightings(myChecker, highlightings, decomposedName, nameDocRange, prefix,
           suffix, declaration, false, declarationNameElement, declaredElement);
       }
       else if (element is IXmlAttributeValue)

File ReSpeller/Analyzers/XmlTypoAnalysisProvider.cs

 using JetBrains.ReSharper.Daemon.Xml.Stages;
 using JetBrains.ReSharper.Daemon.Xml.Stages.Analysis;
 using JetBrains.ReSharper.Psi.Xml.Tree;
+using ReSpeller.SpellEngine;
 
 namespace ReSpeller.Analyzers
 {
   [XmlAnalysisProvider]
   internal class XmlTypoAnalysisProvider : IXmlAnalysisProvider
   {
-    #region IXmlAnalysisProvider Members
+    private readonly ISpellChecker mySpellChecker;
 
-    public IEnumerable<XmlAnalysis> GetAnalyses(IXmlFile file, IDaemonProcess process,
-                                                IContextBoundSettingsStore settingsStore)
+    public XmlTypoAnalysisProvider(ISpellChecker spellChecker)
+    {
+      mySpellChecker = spellChecker;
+    }
+
+    public IEnumerable<XmlAnalysis> GetAnalyses(IXmlFile file, IDaemonProcess process, IContextBoundSettingsStore settingsStore)
     {
       return new XmlAnalysis[]
-               {
-                 new XmlTypoAnalysis()
-               };
+      {
+        new XmlTypoAnalysis(mySpellChecker)
+      };
     }
-
-    #endregion
   }
 }

File ReSpeller/Bulbs/AddToDictionaryBulbItem.cs

 
     public void Execute(ISolution solution, ITextControl textControl)
     {
-      var languageWordStorage = Shell.Instance.GetComponent<ISingleLanguageWordStorage>();
+      var languageWordStorage = solution.GetComponent<ISingleLanguageWordStorage>();
       languageWordStorage.AddWordToUserDict(myNewWord);
       Daemon.GetInstance(solution).Invalidate();
     }

File ReSpeller/Highlightings/TextRangeTypoHighlighting.cs

   {
     private readonly DocumentRange myRange;
 
-
     protected TextRangeTypoHighlighting(DocumentRange range)
     {
       myRange = range;

File ReSpeller/QuickFixes/TypoQuickFix.cs

 using System.Collections.Generic;
 using JetBrains.Annotations;
 using JetBrains.Application;
+using JetBrains.ProjectModel;
 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.Bulbs;
 using ReSpeller.Highlightings;
   [QuickFix]
   internal class TypoQuickFix : IQuickFix
   {
-    private readonly ISpellChecker myChecker = Shell.Instance.GetComponent<ISpellChecker>();
-    private readonly SuggestionGenerator mySuggestionGenerator = Shell.Instance.GetComponent<SuggestionGenerator>();
     private readonly IHighlighting myHighlighting;
     private readonly List<IBulbAction> myBulbItems = new List<IBulbAction>();
 
     public TypoQuickFix([NotNull] IdentifierTypoHighlighting highlighting)
     {
       myHighlighting = highlighting;
-      var suggests = new AsyncValue<List<string>>(() => mySuggestionGenerator.Generate(highlighting.InnerNameParts, highlighting.Prefix, highlighting.Suffix));
+      var suggestionGenerator = highlighting.Declaration.GetSolution().GetComponent<SuggestionGenerator>();
+      var suggests = new AsyncValue<List<string>>(() => suggestionGenerator.Generate(highlighting.InnerNameParts, highlighting.Prefix, highlighting.Suffix));
 
       myBulbItems.Add(new AdvancedTypoRenameBulbItem(highlighting.DeclaredElement, suggests));
       string word = highlighting.WrongPart.Text;
     public TypoQuickFix([NotNull] TextRangeTypoHighlighting highlighting)
     {
       myHighlighting = highlighting;
+      var solution = Shell.Instance.GetComponent<SolutionsManager>().Solution;
+      Assertion.AssertNotNull(solution, "solution == null");
+      var spellChecker = solution.GetComponent<ISpellChecker>();
       var highlightingRange = highlighting.Range;
       string word = highlighting.Text;
-      var suggests = new AsyncValue<List<string>>(() => myChecker.Suggestions(word));
+      var suggests = new AsyncValue<List<string>>(() => spellChecker.Suggestions(word));
       myBulbItems.Add(new TextRangeTypoReplaceBulbItem(highlightingRange, suggests));
       myBulbItems.Add(new AddToDictionaryBulbItem(word));
       myBulbItems.Add(new EditAddToDictionaryBulb(word));

File ReSpeller/ReSpeller8.x.csproj

     <Compile Include="Img\ThemedIcons.Img.Generated.cs">
       <DependentUpon>icon.png</DependentUpon>
     </Compile>
+    <Compile Include="Settings\SettingsSpellCheckerConfig.cs" />
     <Compile Include="Settings\Upgrade\UserDictionariesUpgrader.cs" />
     <Compile Include="SpellEngine\Dictionaries\SettingsDictionaryStorage.cs" />
     <Compile Include="Util\AsyncValue.cs" />

File ReSpeller/Settings/ReSpellerSettingsControl.xaml.cs

-using System.Collections.Generic;
-using System.Globalization;
+using System.Globalization;
 using System.Linq;
-using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
-using JetBrains.Application;
 using JetBrains.Application.Settings.Store;
 using JetBrains.DataFlow;
-using JetBrains.UI.Avalon;
 using JetBrains.UI.CrossFramework;
 using JetBrains.UI.Options;
 using JetBrains.UI.Options.OptionPages;
 
     public bool OnOk()
     {
-      var spellChecker = Shell.Instance.GetComponent<ISpellChecker>();
-      spellChecker.UpdateConfig();
       return true;
     }
 

File ReSpeller/Settings/SettingsSpellCheckerConfig.cs

+using JetBrains.Application.Settings;
+using JetBrains.DataFlow;
+using ReSpeller.SpellEngine;
+
+namespace ReSpeller.Settings
+{
+  public class SettingsSpellCheckerConfig : ISpellCheckerConfig
+  {
+    private readonly IProperty<bool> mySplitInPairsProperty;
+    private readonly IProperty<int> myMinWordLengthProperty;
+
+    public SettingsSpellCheckerConfig(Lifetime lifetime, IContextBoundSettingsStoreLive storeLive)
+    {
+      mySplitInPairsProperty = storeLive.GetValueProperty(lifetime, (ReSpellerSettings settings) => settings.SplitInPairs);
+      myMinWordLengthProperty = storeLive.GetValueProperty(lifetime, (ReSpellerSettings settings) => settings.MinWordLength);
+    }
+
+    public bool SplitInPairs { get { return mySplitInPairsProperty.Value; } }
+    public int MinWordLength { get { return myMinWordLengthProperty.Value; } }
+  }
+}

File ReSpeller/SpellEngine/ConfigurableWordChecker.cs

 
     private readonly List<ILanguageDictionary> myDictionaries;
 
-    public ConfigurableWordChecker(List<ILanguageDictionary> dictionaries)
+    public ConfigurableWordChecker(List<ILanguageDictionary> dictionaries, ISpellCheckerConfig config)
     {
       myDictionaries = dictionaries;
-      Config = new SpellCheckerConfig();
+      Config = config;
     }
 
-    public SpellCheckerConfig Config { get; set; }
+    public ISpellCheckerConfig Config { get; private set; }
 
     public bool Check(string word)
     {

File ReSpeller/SpellEngine/ISpellChecker.cs

   {
     bool CheckWordSpelling(string word);
     List<string> Suggestions(string word);
-    void UpdateConfig();
   }
 }

File ReSpeller/SpellEngine/SpellChecker.cs

 using System;
 using System.Collections.Generic;
-using JetBrains.Application;
 using JetBrains.Application.Components;
 using JetBrains.Application.Settings;
 using JetBrains.DataFlow;
+using JetBrains.ProjectModel;
+using JetBrains.ProjectModel.DataContext;
 using ReSpeller.Settings;
 using ReSpeller.SpellEngine.Dictionaries;
 
 namespace ReSpeller.SpellEngine
 {
-  [ShellComponent(ProgramConfigurations.ALL & ~ProgramConfigurations.TEST)]
+  [SolutionComponent(ProgramConfigurations.ALL & ~ProgramConfigurations.TEST)]
   public sealed class SpellChecker : IDisposable, ISpellChecker, ISingleLanguageWordStorage
   {
     private readonly IContextBoundSettingsStoreLive myStore;
     private readonly ConfigurableWordChecker myWordChecker;
     private readonly IWordSuggestor myWordSuggester;
 
-    public SpellChecker(Lifetime lifetime, ISettingsStore store)
+    public SpellChecker(Lifetime lifetime, ISolution solution, ISettingsStore store)
     {
-      myStore = store.BindToContextLive(lifetime, ContextRange.ApplicationWide);
+      myStore = store.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
       var factory = new HunspellDictionaryFactory(lifetime, myStore);
       myDictionary = factory.CreateDictionary(CurrentLanguage);
-      myWordChecker = new ConfigurableWordChecker(new List<ILanguageDictionary> {myDictionary});
+      myWordChecker = new ConfigurableWordChecker(new List<ILanguageDictionary> {myDictionary}, new SettingsSpellCheckerConfig(lifetime, myStore));
       myWordSuggester = new SingleDictionarySuggestor(myDictionary);
     }
 
         myDictionary.AddToInternalDict(word);
       }
     }
-
-    public void UpdateConfig()
-    {
-      var settings = myStore.GetKey<ReSpellerSettings>(SettingsOptimization.DoMeSlowly);
-      myWordChecker.Config.MinWordLength = settings.MinWordLength;
-      myWordChecker.Config.SplitInPairs = settings.SplitInPairs;
-    }
   }
 }

File ReSpeller/SpellEngine/SpellCheckerConfig.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+namespace ReSpeller.SpellEngine
+{
+  public interface ISpellCheckerConfig
+  {
+    bool SplitInPairs { get; }
+    int MinWordLength { get; }
+  }
 
-namespace ReSpeller.SpellEngine
-{
-  public class SpellCheckerConfig
+  public class SpellCheckerConfig : ISpellCheckerConfig
   {
     public bool SplitInPairs { get; set; }
     public int MinWordLength { get; set; }

File ReSpeller/SpellEngine/SuggestionGenerator.cs

 using System.Linq;
 using JetBrains.Application;
 using JetBrains.Application.Components;
+using JetBrains.ProjectModel;
 
 namespace ReSpeller.SpellEngine
 {
-  [ShellComponent(ProgramConfigurations.ALL & ~ProgramConfigurations.TEST)]
+  [SolutionComponent(ProgramConfigurations.ALL & ~ProgramConfigurations.TEST)]
   public class SuggestionGenerator
   {
     private readonly ISpellChecker myChecker;

File ReSpeller8.x.sln

 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 2013
-VisualStudioVersion = 12.0.21005.1
+VisualStudioVersion = 12.0.30110.0
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReSpeller8.x", "ReSpeller\ReSpeller8.x.csproj", "{8A970A1E-B676-49F2-8731-7A2500EC0E3B}"
 EndProject
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
-		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Debug|x86.ActiveCfg = Debug|Any CPU
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{3D36848B-18A0-4403-8D35-5EF99FD528A3}.Release|Any CPU.Build.0 = Release|Any CPU