private IEnumerable <Range> GetWordsFromXmlComment(IDocCommentBlockNode docBlock)
        {
            if (docBlock != null)
            {
                XmlDocLexer lexer = new XmlDocLexer(docBlock);
                lexer.Start();
                int inCode = 0;
                while (lexer.TokenType != null)
                {
                    if (lexer.TokenType == lexer.XmlTokenType.TAG_START)
                    {
                        lexer.Advance();
                        if (lexer.TokenType == lexer.XmlTokenType.IDENTIFIER &&
                            (lexer.TokenText == "code" || lexer.TokenText == "c"))
                        {
                            inCode++;
                        }

                        while (lexer.TokenType != lexer.XmlTokenType.TAG_END &&
                               lexer.TokenType != lexer.XmlTokenType.TAG_END1 &&
                               lexer.TokenType != null)
                        {
                            lexer.Advance();
                        }

                        if (lexer.TokenType == lexer.XmlTokenType.TAG_END1)
                        {
                            inCode--;
                        }
                    }
                    if (lexer.TokenType == lexer.XmlTokenType.TAG_START1)
                    {
                        lexer.Advance();
                        if (lexer.TokenType == lexer.XmlTokenType.IDENTIFIER &&
                            (lexer.TokenText == "code" || lexer.TokenText == "c"))
                        {
                            inCode--;
                        }
                    }
                    if (lexer.TokenType == lexer.XmlTokenType.TEXT && inCode == 0)
                    {
                        ILexer wordLexer = new WordLexer(lexer.TokenText);
                        wordLexer.Start();
                        while (wordLexer.TokenType != null)
                        {
                            int start = lexer.CurrentNode.GetTreeStartOffset().Offset + lexer.TokenStart + wordLexer.TokenStart;
                            int end   = start + wordLexer.GetCurrTokenText().Length;
                            yield return(new Range(wordLexer.GetCurrTokenText(), new TreeTextRange(new TreeOffset(start), new TreeOffset(end))));

                            wordLexer.Advance();
                        }
                    }
                    lexer.Advance();
                }
            }
        }
예제 #2
0
        public void Execute(Action <DaemonStageResult> action)
        {
            IPsiModule module = _file.GetPsiModule();

            ResXSettings settings = _settingsStore.GetKey <ResXSettings>(SettingsOptimization.OptimizeDefault);

            IAttributesSet             moduleAttributes = _file.GetSolution().GetPsiServices().Symbols.GetModuleAttributes(module);
            string                     defaultResXDic   = "en-US";
            IList <IAttributeInstance> attributes       = moduleAttributes
                                                          .GetAttributeInstances(new ClrTypeName(typeof(NeutralResourcesLanguageAttribute).FullName), false);

            if (attributes != null &&
                attributes.Count > 0 &&
                attributes[0].PositionParameter(0).ConstantValue.Value != null)
            {
                defaultResXDic = attributes[0].PositionParameter(0).ConstantValue.Value.ToString();
            }

#if RESHARPER20173
            var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile);
#else
            var consumer = new DefaultHighlightingConsumer(this, _settingsStore);
#endif

            ISpellChecker checker = SpellCheckManager.GetSpellChecker(_settingsStore, _file, defaultResXDic);
            if (checker != null)
            {
                foreach (IXmlToken token in getStringsToCheck())
                {
                    WordLexer lexer = new WordLexer(token.GetText());
                    lexer.Start();
                    while (lexer.TokenType != null)
                    {
                        if (SpellCheckUtil.ShouldSpellCheck(lexer.TokenText, settings.CompiledWordsToIgnore) &&
                            !checker.TestWord(lexer.TokenText, false))
                        {
                            DocumentRange docRange  = token.GetDocumentRange();
                            TextRange     textRange = new TextRange(docRange.TextRange.StartOffset + lexer.TokenStart,
                                                                    docRange.TextRange.StartOffset + lexer.TokenEnd);
                            DocumentRange range = new DocumentRange(docRange.Document, textRange);

                            ResXSpellHighlighting highlighting =
                                new ResXSpellHighlighting(lexer.TokenText, _file, checker, range, _settingsStore);

                            consumer.AddHighlighting(highlighting, range);
                        }
                        lexer.Advance();
                    }
                }
            }

            action(new DaemonStageResult(consumer.Highlightings));
        }
        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();
            }
        }