Beispiel #1
0
        protected override string Process(EditorData editorData, bool moduleOnly)
        {
            var sr = DResolver.GetScopedCodeObject(editorData);
            var rr = sr != null?LooseResolution.ResolveTypeLoosely(editorData, sr, out _, true) : null;

            var refs = new StringBuilder();

            if (rr != null)
            {
                var n = ExpressionTypeEvaluation.GetResultMember(rr);

                if (n != null)
                {
                    var ctxt = ResolutionContext.Create(editorData, true);
                    if (moduleOnly || n.ContainsAnyAttribute(DTokens.Private) || (n is DVariable variable && variable.IsLocal))
                    {
                        GetReferencesInModule(editorData.SyntaxTree, refs, n, ctxt);
                    }
                    else
                    {
                        foreach (var rootPackage in editorData.ParseCache.EnumRootPackagesSurroundingModule(editorData.SyntaxTree))
                        {
                            foreach (var module in rootPackage)
                            {
                                GetReferencesInModule(module, refs, n, ctxt);
                            }
                        }
                    }
                }

                //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null);
            }
        static DNode GetResultMember(AbstractType abstractType)
        {
            var nodeSymbolToFind = ExpressionTypeEvaluation.GetResultMember(abstractType);

            // Slightly hacky: To keep highlighting the id of e.g. a NewExpression, take the ctor's parent node (i.e. the class node)
            if (nodeSymbolToFind is DMethod dm && dm.SpecialType == DMethod.MethodType.Constructor)
            {
                nodeSymbolToFind = ((abstractType as DSymbol).Base as DSymbol)?.Definition;
            }

            return(nodeSymbolToFind);
        }
Beispiel #3
0
        protected override Tuple <CodeLocation, CodeLocation, string> Process(EditorData editorData, CodeLocation tipEnd)
        {
            var tipStart = editorData.CaretLocation;

            editorData.CaretOffset  += 2;
            editorData.CaretLocation = tipEnd;

            var sr = DResolver.GetScopedCodeObject(editorData);
            var rr = sr != null?LooseResolution.ResolveTypeLoosely(editorData, sr, out _, true) : null;

            var definitionSourceFilename = new StringBuilder();

            if (rr != null)
            {
                if (rr is AliasedType at)
                {
                    // jump to original definition if it is not renamed or the caret is on the import
                    var isRenamed = (at.Definition as ImportSymbolAlias)?.ImportBinding?.Alias != null;
                    if (!isRenamed || at.Definition.Location == sr.Location)
                    {
                        rr = at.Base;
                    }
                }
                DNode n = null;
                foreach (var t in AmbiguousType.TryDissolve(rr))
                {
                    n = ExpressionTypeEvaluation.GetResultMember(t);
                    if (n != null)
                    {
                        break;
                    }
                }

                if (n != null)
                {
                    if (definitionSourceFilename.Length > 0)
                    {
                        definitionSourceFilename.Append("\n");
                    }
                    bool decl = false;
                    if (n is DMethod method)
                    {
                        decl = method.Body == null;
                    }
                    else if (n.ContainsAnyAttribute(DTokens.Extern))
                    {
                        decl = true;
                    }
                    if (decl)
                    {
                        definitionSourceFilename.Append("EXTERN:");
                    }

                    tipStart = n.Location;
                    tipEnd   = n.EndLocation;
                    if (n.NodeRoot is DModule module)
                    {
                        definitionSourceFilename.Append(module.FileName);
                    }
                }
            }

            return(Tuple.Create(tipStart, tipEnd, definitionSourceFilename.ToString()));
        }