コード例 #1
0
ファイル: ResXProcess.cs プロジェクト: ranganathsb/AgentSmith
        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));
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
0
        public void CheckMemberSpelling(
            IDeclaration declaration,
            IHighlightingConsumer highlightingConsumer,
            bool spellCheck)
        {
            if (this._identifierSpellChecker == null || !spellCheck)
            {
                return;
            }

            if (declaration is IIndexerDeclaration ||
                declaration is IDestructorDeclaration ||
                declaration is IAccessorDeclaration ||
                declaration is IConstructorDeclaration ||
                (declaration.DeclaredName.Contains(".") && !(declaration is INamespaceDeclaration)))
            {
                return;
            }

            /*if (ComplexMatchEvaluator.IsMatch(declaration, _settings.IdentifiersToSpellCheck,
             *      _settings.IdentifiersNotToSpellCheck, true) == null)
             * {
             *  return null;
             * }*/

            HashSet <string> localNames = getLocalNames(declaration);

            CamelHumpLexer lexer =
                new CamelHumpLexer(declaration.DeclaredName, 0, declaration.DeclaredName.Length);

            foreach (LexerToken token in lexer)
            {
                string val      = token.Value;
                string lowerVal = val.ToLower();
                //val.Length > MAX_LENGTH_TO_SKIP &&
                if (
                    !IsAbbreviation(val) &&
                    SpellCheckUtil.ShouldSpellCheck(val, _identifierSettings.CompiledWordsToIgnore) &&
                    !localNames.Contains(lowerVal) &&
                    !this._identifierSpellChecker.TestWord(val, false))
                {
                    bool found = false;
                    foreach (string entry in localNames)
                    {
                        if (entry.StartsWith(lowerVal))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        var highlighting = new IdentifierSpellCheckHighlighting(
                            declaration, token, _solution, this._identifierSpellChecker, _settingsStore);

                        var file  = declaration.GetContainingFile();
                        var range = declaration.GetNameDocumentRange();
                        highlightingConsumer.AddHighlighting(highlighting, range, file);
                    }
                }
            }
        }
コード例 #4
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();
            }
        }