public StringSpellCheckQuickFix(StringSpellCheckHighlighting highlighting)
 {
     this._highlighting = highlighting;
 }
Exemple #2
0
        public static void SpellCheck(
            IDocument document, ITokenNode token, ISpellChecker spellChecker,
            ISolution solution, IHighlightingConsumer highlightingConsumer,
            IContextBoundSettingsStore settingsStore, StringSettings settings)
        {
            if (spellChecker == null)
            {
                return;
            }

            string buffer    = unescape(token.GetText());
            ILexer wordLexer = new WordLexer(buffer);

            wordLexer.Start();
            while (wordLexer.TokenType != null)
            {
                string tokenText = wordLexer.GetCurrTokenText();
                if (SpellCheckUtil.ShouldSpellCheck(tokenText, settings.CompiledWordsToIgnore) &&
                    !spellChecker.TestWord(tokenText, true))
                {
                    IClassMemberDeclaration containingElement =
                        token.GetContainingNode <IClassMemberDeclaration>(false);
                    if (containingElement == null ||
                        !IdentifierResolver.IsIdentifier(containingElement, solution, tokenText))
                    {
                        CamelHumpLexer camelHumpLexer = new CamelHumpLexer(buffer, wordLexer.TokenStart, wordLexer.TokenEnd);
                        foreach (LexerToken humpToken in camelHumpLexer)
                        {
                            if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, settings.CompiledWordsToIgnore) &&
                                !spellChecker.TestWord(humpToken.Value, true))
                            {
                                //int start = token.GetTreeStartOffset().Offset + wordLexer.TokenStart;
                                //int end = start + tokenText.Length;

                                //TextRange range = new TextRange(start, end);
                                //DocumentRange documentRange = new DocumentRange(document, range);

                                DocumentRange documentRange =
                                    token.GetContainingFile().TranslateRangeForHighlighting(token.GetTreeTextRange());
                                documentRange = documentRange.ExtendLeft(-wordLexer.TokenStart);
                                documentRange = documentRange.ExtendRight(-1 * (documentRange.GetText().Length - tokenText.Length));

                                TextRange textRange = new TextRange(humpToken.Start - wordLexer.TokenStart,
                                                                    humpToken.End - wordLexer.TokenStart);

                                string word = documentRange.GetText();

                                var highlighting = new StringSpellCheckHighlighting(word, documentRange,
                                                                                    humpToken.Value, textRange,
                                                                                    solution, spellChecker, settingsStore);

                                var file = token.GetContainingFile();

                                highlightingConsumer.AddHighlighting(highlighting, documentRange, file);

                                break;
                            }
                        }
                    }
                }

                wordLexer.Advance();
            }
        }