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()));
            }
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
 }
        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);
                }
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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()));
                }
            }
        }
        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));
        }
        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()));
            }
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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());
            }
        }