Example #1
0
        private IEnumerable <BulbMenuItem> GetRunMethodItems(ISolution solution, UnityRunMarkerHighlighting runMarker)
        {
            var backendUnityHost   = solution.GetComponent <BackendUnityHost>();
            var notificationsModel = solution.GetComponent <NotificationsModel>();

            var methodFqn = DeclaredElementPresenter.Format(runMarker.Method.PresentationLanguage,
                                                            DeclaredElementPresenter.QUALIFIED_NAME_PRESENTER, runMarker.Method).Text;

            var iconId = RunMarkersThemedIcons.RunThis.Id;

            yield return(new BulbMenuItem(new ExecutableItem(() =>
            {
                var model = backendUnityHost.BackendUnityModel.Value;
                if (model == null)
                {
                    var notification = new NotificationModel("No connection to Unity", "Make sure Unity is running.",
                                                             true, RdNotificationEntryType.WARN, new List <NotificationHyperlink>());
                    notificationsModel.Notification(notification);
                    return;
                }

                var data = new RunMethodData(
                    runMarker.Project.GetOutputFilePath(runMarker.TargetFrameworkId).NameWithoutExtension,
                    runMarker.Method.GetContainingType().GetClrName().FullName,
                    runMarker.Method.ShortName);
                model.RunMethodInUnity.Start(data);
            }),
                                          new RichText($"Run '{methodFqn}'"),
                                          iconId,
                                          BulbMenuAnchors.PermanentBackgroundItems));
        }
Example #2
0
        protected virtual string GetTitle(IDeclaredElement declaredElement)
        {
            string kind = DeclaredElementPresenter.Format(PresentationUtil.GetPresentationLanguage(declaredElement), DeclaredElementPresenter.KIND_PRESENTER, declaredElement);
            string name = DeclaredElementPresenter.Format(PresentationUtil.GetPresentationLanguage(declaredElement), DeclaredElementPresenter.NAME_PRESENTER, declaredElement);

            return(string.Format("Declarations of {1} '{0}'", name, kind));
        }
        public QuickDocTitleAndText GetHtml(PsiLanguageType presentationLanguage)
        {
            var element = myEnvoy.GetValidDeclaredElement();

            if (element == null)
            {
                return(QuickDocTitleAndText.Empty);
            }

            // Present in the standard fashion
            var details = GetDetails(element);

#if WAVE07
            var text = XmlDocHtmlPresenter.Run(details, element.Module,
                                               element, presentationLanguage, XmlDocHtmlUtil.NavigationStyle.All,
                                               XmlDocHtmlUtil.CrefManager, myTheming);
#else
            var text = XmlDocHtmlPresenter.Run(details, element.Module,
                                               element, presentationLanguage, XmlDocHtmlUtil.NavigationStyle.All,
                                               XmlDocHtmlUtil.ProcessCRef, myTheming);
#endif
            var title = DeclaredElementPresenter.Format(presentationLanguage,
                                                        DeclaredElementPresenter.FULL_NESTED_NAME_PRESENTER, element);

            return(new QuickDocTitleAndText(text, title));
        }
Example #4
0
            private string GetText(IMethodDeclaration methodDeclaration, MethodSignature signature)
            {
                var language        = methodDeclaration.Language;
                var declaredElement = methodDeclaration.DeclaredElement;

                Assertion.AssertNotNull(declaredElement, "declaredElement != null");
                var methodName = DeclaredElementPresenter.Format(language, DeclaredElementPresenter.NAME_PRESENTER,
                                                                 declaredElement);

                switch (myMatch)
                {
                case MethodSignatureMatch.IncorrectStaticModifier:
                {
                    var staticTerm = PresentationHelper.GetHelper(language).GetStaticTerm();
                    return(signature.IsStatic == true ? $"Make '{methodName}' {staticTerm}" : $"Remove '{staticTerm}' modifier");
                }

                case MethodSignatureMatch.IncorrectParameters:
                    return($"Change parameters to '({signature.Parameters.GetParameterList()})'");

                case MethodSignatureMatch.IncorrectReturnType:
                    return($"Change return type to '{signature.GetReturnTypeName()}'");

                case MethodSignatureMatch.IncorrectTypeParameters:
                    return("Remove type parameters");

                // NoMatch, and any combination of flags
                default:
                    return($"Change signature to '{signature.FormatSignature(methodName.Text)}'");
                }
            }
Example #5
0
        private static string GetFullyQualifiedUnityName(IClrDeclaredElement element)
        {
            var moduleName = element.Module.Name;

            if (moduleName.StartsWith("UnityEngine") || moduleName.StartsWith("UnityEditor"))
            {
                return(DeclaredElementPresenter.Format(KnownLanguage.ANY, MSDN_STYLE, element));
            }
            return(string.Empty);
        }
        protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType,
                                         DeclaredElementPresenterStyle presenter, IReference reference)
        {
            if (declaredElement == null)
            {
                return("null");
            }

            // Output the element like it is in the QuickDoc - element name + type
            return(DeclaredElementPresenter.Format(JavaScriptLanguage.Instance, XmlDocPresenterUtil.MemberPresentationStyle,
                                                   declaredElement, EmptySubstitution.INSTANCE));
        }
Example #7
0
        private string FormatTypeElement(string format)
        {
            // uses DeclaredElementPresenter to format type element, which is standard way to present code elements
            var style = new DeclaredElementPresenterStyle(NameStyle.SHORT)
            {
                ShowTypeParameters = TypeParameterStyle.FULL
            };
            string typeElementText = DeclaredElementPresenter.Format(PresentationUtil.GetPresentationLanguage(TypeElement),
                                                                     style, TypeElement);

            return(string.Format(format, typeElementText));
        }
        public override RichText GetDisplayText()
        {
            var declaredElement = DeclaredElementPointer.FindDeclaredElement();

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

            var elementRichText = DeclaredElementMenuItemFormatter.FormatText(declaredElement, declaredElement.PresentationLanguage, out _);
            var grayTextStyle   = TextStyle.FromForeColor(SystemColors.GrayText);
            var containerText   = DeclaredElementPresenter.Format(declaredElement.PresentationLanguage,
                                                                  DeclaredElementMenuItemFormatter.ContainerPresentationStyle, declaredElement, EmptySubstitution.INSTANCE).Text;

            var richText = new RichText(containerText, grayTextStyle);

            return(elementRichText + " " + richText + ", " + base.GetDisplayText());
        }
Example #9
0
        private static string GetMessage(ITreeNode element, int complexity, int threshold)
        {
            var          type = "Element";
            IDeclaration declaration;

            GetBestTreeNode(element, out declaration);
            if (declaration?.DeclaredElement != null)
            {
                var declaredElement = declaration.DeclaredElement;
                var declarationType = DeclaredElementPresenter.Format(declaration.Language,
                                                                      DeclaredElementPresenter.KIND_PRESENTER, declaredElement);
                var declaredElementName = DeclaredElementPresenter.Format(declaration.Language,
                                                                          DeclaredElementPresenter.NAME_PRESENTER, declaredElement);

                type = $"{declarationType.Capitalize()} '{declaredElementName}'";
            }

            return($"{type} has cyclomatic complexity of {complexity} ({GetPercentage(complexity, threshold)}% of threshold)");
        }
Example #10
0
        public IncorrectMethodSignatureQuickFix(InvalidStaticModifierWarning warning)
            : this(warning.MethodDeclaration, warning.ExpectedMethodSignature,
                   MethodSignatureMatch.IncorrectStaticModifier)
        {
            var language   = myMethodDeclaration.Language;
            var staticTerm = PresentationHelper.GetHelper(language).GetStaticTerm();

            if (myExpectedMethodSignature.IsStatic == true)
            {
                var declaredElement = myMethodDeclaration.DeclaredElement;
                Assertion.AssertNotNull(declaredElement, "declaredElement != null");
                var methodName = DeclaredElementPresenter.Format(language, DeclaredElementPresenter.NAME_PRESENTER,
                                                                 declaredElement);
                Text = $"Make '{methodName}' {staticTerm}";
            }
            else
            {
                Text = $"Remove '{staticTerm}' modifier";
            }
        }
        public IHighlighting Run(IReference reference)
        {
            var resolveResult = reference.Resolve();

            if (resolveResult.Result.Candidates.Count > 1)
            {
                var candidates = resolveResult.Result.Candidates;
                var result     = new List <string>();
                foreach (var candidate in candidates)
                {
                    result.Add(Environment.NewLine + "  " + DeclaredElementPresenter.Format(ShaderLabLanguage.Instance,
                                                                                            ShaderLabDeclaredElementPresenterStyles.CANDIDATE_PRESENTER, candidate));
                }
                result.Sort();
                var message = result.AggregateString("");
                var range   = reference.GetDocumentRange();
                return(new MultipleResolveCandidatesError(range, message, reference));
            }

            return(null);
        }
Example #12
0
        private RichTextBlock GetDescription(CSharpCodeCompletionContext context, IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration.DeclaredElement == null)
            {
                return(null);
            }

            var presenter               = context.BasicContext.Solution.GetComponent <IDeclaredElementDescriptionPresenter>();
            var richTextBlock           = new RichTextBlock(new RichTextBlockParameters(1));
            var psiLanguageType         = methodDeclaration.Language;
            var declaredElementInstance = new DeclaredElementInstance(methodDeclaration.DeclaredElement);

            richTextBlock.Add(DeclaredElementPresenter.Format(psiLanguageType, ourPresenter, declaredElementInstance)
                              .Capitalize());
            var description = presenter.GetDeclaredElementDescription(methodDeclaration.DeclaredElement,
                                                                      DeclaredElementDescriptionStyle.SUMMARY_STYLE, psiLanguageType);

            if (!RichTextBlock.IsNullOrEmpty(description))
            {
                richTextBlock.AddLines(description);
            }

            return(richTextBlock);
        }
Example #13
0
        public static JetBrains.UI.RichText.RichText ProcessCRef(string crefValue, PsiLanguageType languageType, IPsiModule psiModule, DeclaredElementPresenterStyle presenterStyle)
        {
            var element = psiModule == null ? null : XMLDocUtil.ResolveId(psiModule.GetPsiServices(), crefValue, psiModule, true);

            return(element == null || !element.IsValid() ? new JetBrains.UI.RichText.RichText(XmlDocPresenterUtil.ProcessCref(crefValue), XmlDocRichTextPresenterEx.ourCRefStyle) : DeclaredElementPresenter.Format(languageType, presenterStyle, element));
        }