コード例 #1
0
        private void CheckWordSpelling(
            IClassMemberDeclaration decl,
            Range wordRange,
            IHighlightingConsumer
            highlightingConsumer,
            DocumentRange range,
            IFile file)
        {
            // If we dont have a spell checker then go no further
            if (this._xmlDocumentationSpellChecker == null)
            {
                return;
            }

            // First check the whole word range.
            if (!SpellCheckUtil.ShouldSpellCheck(wordRange.Word, _xmlDocumentationSettings.CompiledWordsToIgnore) ||
                this._xmlDocumentationSpellChecker.TestWord(wordRange.Word, true))
            {
                return;
            }

            // We are checking this word and the whole range doesn't spell anything so try breaking the word into bits.
            CamelHumpLexer camelHumpLexer = new CamelHumpLexer(wordRange.Word, 0, wordRange.Word.Length);

            foreach (LexerToken humpToken in camelHumpLexer)
            {
                if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, _xmlDocumentationSettings.CompiledWordsToIgnore) &&
                    !this._xmlDocumentationSpellChecker.TestWord(humpToken.Value, true))
                {
                    var highlighting = new WordIsNotInDictionaryHighlight(wordRange.Word, range,
                                                                          humpToken, _solution, this._xmlDocumentationSpellChecker, _settingsStore);

                    highlightingConsumer.AddHighlighting(highlighting, range, file);

                    break;
                }
            }
        }
コード例 #2
0
        public static void SpellCheck(IDocument document, ITokenNode token, ISpellChecker spellChecker,
                                      ISolution solution, DefaultHighlightingConsumer consumer, 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 = document.GetText(range);
                                string word = documentRange.GetText();
                                consumer.AddHighlighting(
                                    new StringSpellCheckHighlighting(
                                        word,
                                        documentRange,
                                        humpToken.Value,
                                        textRange,
                                        solution,
                                        spellChecker,
                                        settingsStore),
                                    documentRange);
                                break;
                            }
                        }
                    }
                }
                wordLexer.Advance();
            }
        }