コード例 #1
0
        public static Action ProcessContext(
            [NotNull] Lifetime lifetime,
            [NotNull] HighlightingProlongedLifetime prolongedLifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView
            )
        {
            var psiView = psiDocumentRangeView.View <JsonLanguage>();

            foreach (var file in psiView.SortedSourceFiles)
            {
                if (!file.IsAsmDef())
                {
                    return(null);
                }
            }

            var declaredElement = FindDeclaredElement(psiView, out var literalExpressionUnderCaret);

            if (declaredElement == null)
            {
                return(null);
            }

            var highlighter = new AsmDefUsagesContextHighlighter(declaredElement, literalExpressionUnderCaret);

            return(highlighter.GetDataProcessAction(prolongedLifetime, psiDocumentRangeView));
        }
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
        {
            var view = psiDocumentRangeView.View <CSharpLanguage>();
            var node = view.GetSelectedTreeNode <IFunctionDeclaration>();

            if (node == null)
            {
                return;
            }

            var solution      = psiDocumentRangeView.Solution;
            var settingsStore = psiDocumentRangeView.GetSettingsStore();

            if (settingsStore.GetValue((UnitySettings key) => key.PerformanceHighlightingMode) !=
                PerformanceHighlightingMode.CurrentMethod)
            {
                return;
            }

            var contextProvider = solution.GetComponent <PerformanceCriticalContextProvider>();
            var swea            = solution.GetComponent <SolutionAnalysisService>();
            var declaredElement = node.DeclaredElement;

            if (contextProvider.IsMarkedSweaDependent(declaredElement, swea))
            {
                consumer.ConsumeHighlighting(new UnityPerformanceContextHighlightInfo(node.GetDocumentRange()));
            }
        }
コード例 #3
0
        public static Action ProcessContext(
            [NotNull] Lifetime lifetime, [NotNull] HighlightingProlongedLifetime prolongedLifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView,
            [NotNull] ShaderLabUsageContextHighlighterAvailability contextHighlighterAvailability)
        {
            var psiView = psiDocumentRangeView.View <ShaderLabLanguage>();

            foreach (var file in psiView.SortedSourceFiles)
            {
                if (!contextHighlighterAvailability.IsAvailable(file))
                {
                    return(null);
                }
            }

            var declaredElement = FindDeclaredElement(psiView, out var declarationUnderCaret);

            if (declaredElement == null)
            {
                return(null);
            }

            var highlighter = new ShaderLabUsagesContextHighlighter(declaredElement, declarationUnderCaret);

            return(highlighter.GetDataProcessAction(prolongedLifetime, psiDocumentRangeView));
        }
 public static Action ProcessContext(
     [NotNull] HighlightingProlongedLifetime prolongedLifetime,
     [NotNull][ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))]
     IPsiDocumentRangeView psiDocumentRangeView,
     MessageTemplateParser messageTemplate)
 {
     return(new TemplateFormatItemAndMatchingArgumentHighlighter(messageTemplate).GetDataProcessAction(
                prolongedLifetime,
                psiDocumentRangeView));
 }
コード例 #5
0
        public static Action ProcessDataContext(
            [NotNull] Lifetime lifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView,
            UnityHost host,
            UnityApi unityApi)
        {
            var unityName = GetUnityName(psiDocumentRangeView, unityApi);

            // This is called only if the process finished while the context is still valid
            return(() => { host.PerformModelAction(rd => rd.ExternalDocContext.Value = unityName); });
        }
コード例 #6
0
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView,
                                                     HighlightingsConsumer consumer)
        {
            var psiView  = psiDocumentRangeView.View <FSharpLanguage>();
            var document = psiDocumentRangeView.DocumentRangeFromMainDocument.Document;
            var token    = psiView.GetSelectedTreeNode <FSharpIdentifierToken>();

            if (token == null)
            {
                var wildPat = psiView.GetSelectedTreeNode <IWildPat>();
                if (wildPat != null)
                {
                    consumer.ConsumeHighlighting(HighlightingId, wildPat.GetDocumentRange());
                }

                return;
            }

            // todo: type parameters: t<$caret$type> or t<'$caret$ttype>

            var fsFile     = psiView.GetSelectedTreeNode <IFSharpFile>();
            var sourceFile = fsFile?.GetSourceFile();

            if (sourceFile == null)
            {
                return;
            }

            var symbol = fsFile.GetSymbol(token.GetTreeStartOffset().Offset);

            if (symbol == null)
            {
                return;
            }

            var checkResults =
                fsFile.CheckerService.TryGetStaleCheckResults(sourceFile, OpName)?.Value ??
                fsFile.GetParseAndCheckResults(true, OpName)?.Value.CheckResults;

            var ranges = new HashSet <DocumentRange>();

            AddUsagesRanges(symbol, ranges, checkResults, document, fsFile);

            if (symbol is FSharpMemberOrFunctionOrValue mfv && mfv.IsConstructor &&
                mfv.DeclaringEntity?.Value is FSharpEntity entity)
            {
                AddUsagesRanges(entity, ranges, checkResults, document, fsFile);
            }

            foreach (var range in ranges)
            {
                consumer.ConsumeHighlighting(HighlightingId, range);
            }
        }
        public static Action ProcessDataContext(
            Lifetime lifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))]
            IPsiDocumentRangeView psiDocumentRangeView,
            [NotNull] InvisibleBraceHintManager invisibleBraceHintManager,
            [NotNull] MatchingBraceSuggester matchingBraceSuggester,
            [NotNull] HighlightingProlongedLifetime prolongedLifetime)
        {
            var highlighter = new FSharpTypeParametersMatchingBracesContextHighlighter();

            return(highlighter.ProcessDataContextImpl(
                       lifetime, prolongedLifetime, psiDocumentRangeView, invisibleBraceHintManager, matchingBraceSuggester));
        }
コード例 #8
0
 protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
 {
     if (myDeclarationUnderCaret != null)
     {
         HighlightDeclaration(myDeclarationUnderCaret, consumer);
     }
     else
     {
         var psiView = psiDocumentRangeView.View <ShaderLabLanguage>(PsiLanguageCategories.Dominant);
         HighlightDeclarationsInFile(myDeclaredElement, psiView, consumer);
     }
     HighlightReferencesInFile(myDeclaredElement, psiDocumentRangeView, consumer);
 }
コード例 #9
0
        public static Action ProcessDataContext(
            [NotNull] Lifetime lifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))]
            IPsiDocumentRangeView psiDocumentRangeView,
            [NotNull] InvisibleBraceHintManager invisibleBraceHintManager,
            [NotNull] MatchingBraceSuggester matchingBraceSuggester,
            [NotNull] MatchingBraceConsumerFactory consumerFactory,
            [NotNull] HighlightingProlongedLifetime prolongedLifetime)
        {
            var highlighter = new ShaderLabMatchingBraceContextHighlighter();

            return(highlighter.ProcessDataContextImpl(lifetime, prolongedLifetime, psiDocumentRangeView,
                                                      invisibleBraceHintManager, matchingBraceSuggester, consumerFactory));
        }
        protected override void CollectHighlightings(
            IPsiDocumentRangeView psiDocumentRangeView,
            HighlightingsConsumer consumer)
        {
            var psiView          = psiDocumentRangeView.View <CSharpLanguage>();
            var selectedArgument = psiView.GetSelectedTreeNode <ICSharpArgument>();

            if (selectedArgument == null)
            {
                return;
            }

            var invocationExpressions = psiView.ContainingNodes <IInvocationExpression>();

            foreach (var invocationExpression in invocationExpressions)
            {
                var templateArgument = invocationExpression.GetTemplateArgument();
                if (templateArgument == null)
                {
                    continue;
                }

                if (templateArgument.IndexOf() > selectedArgument.IndexOf())
                {
                    continue;
                }

                var templateString = templateArgument.TryGetTemplateText();
                if (templateString == null)
                {
                    continue;
                }

                var messageTemplate = _messageTemplate.Parse(templateString);
                if (selectedArgument == templateArgument)
                {
                    HighlightByNamedPlaceholder(
                        consumer,
                        psiView,
                        templateArgument,
                        messageTemplate,
                        invocationExpression.ArgumentList.Arguments);
                }
                else
                {
                    HighlightByArgument(consumer, selectedArgument, templateArgument, messageTemplate);
                }
            }
        }
コード例 #11
0
        protected override void CollectHighlightings(
            IPsiDocumentRangeView psiDocumentRangeView,
            HighlightingsConsumer consumer)
        {
            var psiView          = psiDocumentRangeView.View <CSharpLanguage>();
            var selectedArgument = psiView.GetSelectedTreeNode <ICSharpArgument>();

            if (selectedArgument == null)
            {
                return;
            }

            var invocationExpression = psiView.GetSelectedTreeNode <IInvocationExpression>();
            var templateArgument     = invocationExpression?.GetTemplateArgument();

            if (templateArgument == null)
            {
                return;
            }

            if (templateArgument.IndexOf() > selectedArgument.IndexOf())
            {
                return;
            }

            var templateString = StringLiteralAltererUtil.TryCreateStringLiteralByExpression(templateArgument.Value)
                                 ?.Expression.GetUnquotedText();

            if (templateString == null)
            {
                return;
            }

            var messageTemplate = _messageTemplate.Parse(templateString);

            if (selectedArgument == templateArgument)
            {
                HighlightByNamedPlaceholder(
                    consumer,
                    psiView,
                    templateArgument,
                    messageTemplate,
                    invocationExpression.ArgumentList.Arguments);
            }
            else
            {
                HighlightByArgument(consumer, selectedArgument, templateArgument, messageTemplate);
            }
        }
        public override Action GetDataProcessAction(
            HighlightingProlongedLifetime prolongedLifetime,
            IPsiDocumentRangeView psiDocumentRangeView)
        {
            var consumer = new HighlightingsConsumer();

            CollectHighlightings(psiDocumentRangeView, consumer);
            return(() =>
            {
                foreach (var highlightInfo in consumer.HighlightInfos)
                {
                    CaretDependentFeaturesUtil.HighlightForLifetime(prolongedLifetime.Lifetime, highlightInfo);
                }
            });
        }
コード例 #13
0
        public static Action ProcessContext(
            [NotNull] Lifetime lifetime, [NotNull] HighlightingProlongedLifetime prolongedLifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView)
        {
            var isEnabled = GetSettingValue(psiDocumentRangeView, HighlightingSettingsAccessor.ContextExitsHighlightingEnabled);

            if (!isEnabled)
            {
                return(null);
            }

            var highlighter = new PerformanceCriticalCodeContextHighlighter();

            return(highlighter.GetDataProcessAction(prolongedLifetime, psiDocumentRangeView));
        }
コード例 #14
0
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
        {
            var settingsStore = psiDocumentRangeView.GetSettingsStore();

            if (!settingsStore.GetValue((UnitySettings key) => key.EnablePerformanceCriticalCodeHighlighting))
            {
                return;
            }

            if (settingsStore.GetValue((UnitySettings key) => key.PerformanceHighlightingMode) != PerformanceHighlightingMode.CurrentMethod)
            {
                return;
            }

            var view = psiDocumentRangeView.View <CSharpLanguage>();
            var node = view.GetSelectedTreeNode <IFunctionDeclaration>();

            if (node != null)
            {
                var declaredElement = node.DeclaredElement;
                if (declaredElement == null)
                {
                    return;
                }

                var solution           = psiDocumentRangeView.Solution;
                var swa                = solution.GetComponent <SolutionAnalysisService>();
                var callGraphExtension = solution.GetComponent <CallGraphSwaExtensionProvider>();
                var callGraphAnalyzer  = solution.GetComponent <PerformanceCriticalCodeCallGraphMarksProvider>();
                var elementIdProvider  = solution.GetComponent <IElementIdProvider>();
                var usageChecker       = swa.UsageChecker;
                if (usageChecker == null)
                {
                    return;
                }
                var elementId = elementIdProvider.GetElementId(declaredElement);
                if (!elementId.HasValue)
                {
                    return;
                }

                if (callGraphExtension.IsMarkedByCallGraphRootMarksProvider(callGraphAnalyzer.Id, false, elementId.Value))
                {
                    consumer.ConsumeHighlighting(new UnityPerformanceContextHighlightInfo(node.GetDocumentRange()));
                }
            }
        }
コード例 #15
0
        public static Action ProcessContext(
            Lifetime lifetime, [NotNull] HighlightingProlongedLifetime prolongedLifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))]
            IPsiDocumentRangeView psiDocumentRangeView,
            [NotNull] UsagesContextHighlighterAvailabilityComponent contextHighlighterAvailability)
        {
            var psiView = psiDocumentRangeView.View <FSharpLanguage>();

            foreach (var psiSourceFile in psiView.SortedSourceFiles)
            {
                if (!contextHighlighterAvailability.IsAvailable(psiSourceFile))
                {
                    return(null);
                }
            }

            return(new FSharpUsagesContextHighlighter().GetDataProcessAction(prolongedLifetime, psiDocumentRangeView));
        }
コード例 #16
0
        public static Action ProcessDataContext(
            [NotNull] Lifetime lifetime,
            [NotNull, ContextKey(typeof(ContextHighlighterPsiFileView.ContextKey))] IPsiDocumentRangeView psiDocumentRangeView,
            SolutionModel solutionModel,
            UnityApi unityApi)
        {
            var solution = solutionModel.TryGetCurrentSolution();

            if (solution == null)
            {
                return(null);
            }

            var unityName = GetUnityName(psiDocumentRangeView, unityApi);

            // This is called only if the process finished while the context is still valid
            return(() =>
            {
                solution.CustomData.Data["UNITY_ExternalDocContext"] = unityName;
            });
        }
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
        {
            var view = psiDocumentRangeView.View <CSharpLanguage>();
            var node = view.GetSelectedTreeNode <IFunctionDeclaration>();

            if (node == null)
            {
                return;
            }

            var solution = psiDocumentRangeView.Solution;
            var swa      = solution.GetComponent <SolutionAnalysisService>();

            if (!UnityCallGraphUtil.IsSweaCompleted(swa))
            {
                return;
            }

            var contextProvider = solution.GetComponent <PerformanceCriticalContextProvider>();
            var settingsStore   = psiDocumentRangeView.GetSettingsStore();

            if (contextProvider.IsContextAvailable == false)
            {
                return;
            }

            if (settingsStore.GetValue((UnitySettings key) => key.PerformanceHighlightingMode) !=
                PerformanceHighlightingMode.CurrentMethod)
            {
                return;
            }

            var kind = UnityCallGraphUtil.GetProcessKindForGraph(swa);

            if (contextProvider.HasContext(node, kind))
            {
                consumer.ConsumeHighlighting(new UnityPerformanceContextHighlightInfo(node.GetDocumentRange()));
            }
        }
コード例 #18
0
        private static string GetUnityName(IPsiDocumentRangeView psiDocumentRangeView, UnityApi unityApi)
        {
            var psiView = psiDocumentRangeView.View <CSharpLanguage>();

            if (psiView.ContainingNodes.All(n => !n.IsFromUnityProject()))
            {
                return(string.Empty);
            }

            if (!(FindDeclaredElement(psiView) is IClrDeclaredElement element))
            {
                return(string.Empty);
            }

            var unityName = GetUnityEventFunctionName(element, unityApi);

            if (unityName != null)
            {
                return(unityName);
            }

            return(GetFullyQualifiedUnityName(element));
        }
コード例 #19
0
        private void HighlightReferencesInFile(IDeclaredElement declaredElement,
                                               IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
        {
            var searchDomain  = SearchDomainFactory.Instance.CreateSearchDomain(psiDocumentRangeView.SortedSourceFiles);
            var elements      = new[] { new DeclaredElementInstance(declaredElement) };
            var searchRequest = new SearchSingleFileDeclaredElementRequest(elements, elements, searchDomain);

            foreach (var occurrence in searchRequest.Search(NullProgressIndicator.Create()))
            {
                if (!(occurrence is ReferenceOccurrence referenceOccurrence))
                {
                    continue;
                }

                var primaryReference = referenceOccurrence.PrimaryReference;
                if (primaryReference == null)
                {
                    continue;
                }

                var documentRange = primaryReference.GetDocumentRange();
                consumer.ConsumeHighlighting(HIGHLIGHTING_ID, documentRange);
            }
        }
コード例 #20
0
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView,
                                                     HighlightingsConsumer consumer)
        {
            var psiView = psiDocumentRangeView.View <FSharpLanguage>();
            var fsFile  = psiView.GetSelectedTreeNode <IFSharpFile>();

            if (fsFile == null)
            {
                return;
            }

            var document = psiDocumentRangeView.DocumentRangeFromMainDocument.Document;
            var token    = psiView.GetSelectedTreeNode <FSharpIdentifierToken>();

            if (token == null)
            {
                return;
            }

            // todo: type parameters: t<$caret$type> or t<'$caret$ttype>
            // todo: namespaces, use R# search?

            var offset = token.GetTreeStartOffset().Offset;
            var symbol = fsFile.GetSymbolDeclaration(offset) ?? fsFile.GetSymbolUse(offset);

            if (symbol == null)
            {
                return;
            }

            var sourceFile = fsFile.GetSourceFile();

            if (sourceFile == null)
            {
                return;
            }

            var checkResults =
                fsFile.CheckerService.TryGetStaleCheckResults(sourceFile)?.Value ??
                fsFile.GetParseAndCheckResults(true)?.Value.CheckResults;

            var symbolUsages = checkResults?.GetUsesOfSymbolInFile(symbol).RunAsTask();

            foreach (var symbolUse in symbolUsages ?? EmptyArray <FSharpSymbolUse> .Instance)
            {
                var treeOffset = document.GetTreeEndOffset(symbolUse.RangeAlternate);
                var usageToken = fsFile.FindTokenAt(treeOffset - 1) as FSharpIdentifierToken;
                if (usageToken == null)
                {
                    continue;
                }

                var tokenType = usageToken.GetTokenType();
                if ((tokenType == FSharpTokenType.GREATER || tokenType == FSharpTokenType.GREATER_RBRACK) &&
                    !(symbol is FSharpMemberOrFunctionOrValue mfv &&
                      mfv.CompiledName.Equals("op_GreaterThan", StringComparison.Ordinal)))
                {
                    continue; // found usage of generic symbol with specified type parameter
                }
                consumer.ConsumeHighlighting(HighlightingId, usageToken.GetDocumentRange());
            }
        }