Exemplo n.º 1
0
        public static AbstractTooltipContent[] BuildToolTip(IEditorData Editor)
        {
            try
            {
                var ctxt = ResolverContextStack.Create(Editor);
                // In the case we've got a method or something, don't return its base type, only the reference to it
                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;
                var rr = DResolver.ResolveType(Editor, ctxt, DResolver.AstReparseOptions.AlsoParseBeyondCaret);

                if (rr.Length < 1)
                {
                    return(null);
                }

                var l = new List <AbstractTooltipContent>(rr.Length);
                foreach (var res in rr)
                {
                    l.Add(BuildTooltipContent(res));
                }

                return(l.ToArray());
            }
            catch { }
            return(null);
        }
Exemplo n.º 2
0
        public static AbstractType[] ResolveHoveredCode(out ResolutionContext ResolverContext, IEditorData edData)
        {
            ResolverContext = ResolutionContext.Create(edData, false);

            // Resolve the hovered piece of code
            return(AmbiguousType.TryDissolve(DResolver.ResolveType(edData, ctxt: ResolverContext)).ToArray());
        }
Exemplo n.º 3
0
        public static AbstractTooltipContent[] BuildToolTip(IEditorData Editor)
        {
            try
            {
                IStatement curStmt = null;
                var        rr      = DResolver.ResolveType(Editor,
                                                           new ResolverContext
                {
                    ScopedBlock     = DResolver.SearchBlockAt(Editor.SyntaxTree, Editor.CaretLocation, out curStmt),
                    ScopedStatement = curStmt,
                    ParseCache      = Editor.ParseCache,
                    ImportCache     = Editor.ImportCache
                }, true, true);

                if (rr.Length < 1)
                {
                    return(null);
                }

                var l = new List <AbstractTooltipContent>(rr.Length);

                foreach (var res in rr)
                {
                    var modRes = res as ModuleResult;
                    var memRes = res as MemberResult;
                    var typRes = res as TypeResult;

                    // Only show one description for items sharing descriptions
                    string description = "";

                    if (modRes != null)
                    {
                        description = modRes.ResolvedModule.Description;
                    }
                    else if (memRes != null)
                    {
                        description = memRes.ResolvedMember.Description;
                    }
                    else if (typRes != null)
                    {
                        description = typRes.ResolvedTypeDefinition.Description;
                    }

                    l.Add(new AbstractTooltipContent {
                        ResolveResult = res,
                        Title         = (res is ModuleResult ? (res as ModuleResult).ResolvedModule.FileName : res.ToString()),
                        Description   = description
                    });
                }

                return(l.ToArray());
            }
            catch { }
            return(null);
        }
Exemplo n.º 4
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolutionContext ResolverContext,
            MonoDevelop.Ide.Gui.Document doc = null)
        {
            var edData = CreateEditorData(doc);

            ResolverContext = ResolutionContext.Create(edData);

            // Resolve the hovered piece of code
            return(DResolver.ResolveType(edData, ResolverContext, DResolver.AstReparseOptions.AlsoParseBeyondCaret));
        }
Exemplo n.º 5
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolverContextStack ResolverContext,
            MonoDevelop.Ide.Gui.Document doc = null)
        {
            var edData = GetEditorData(doc);

            ResolverContext = ResolverContextStack.Create(edData);
            ResolverContext.ContextIndependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

            // Resolve the hovered piece of code
            return(DResolver.ResolveType(edData, ResolverContext, DResolver.AstReparseOptions.AlsoParseBeyondCaret | DResolver.AstReparseOptions.OnlyAssumeIdentifierList));
        }
Exemplo n.º 6
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolutionContext ResolverContext, out IEditorData edData,
            Document doc = null)
        {
            edData = CreateEditorData(doc);
            if (edData == null)
            {
                ResolverContext = null;
                return(null);
            }
            ResolverContext = ResolutionContext.Create(edData, false);

            // Resolve the hovered piece of code
            return(AmbiguousType.TryDissolve(DResolver.ResolveType(edData, ctxt: ResolverContext)).ToArray());
        }
Exemplo n.º 7
0
        public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            DModule ast = null;

            if (!_modules.TryGetValue(filename, out ast))
            {
                throw new COMException("module not found", 1);
            }

            _tipStart = new CodeLocation(startIndex + 1, startLine);
            _tipEnd   = new CodeLocation(endIndex + 1, endLine);
            _tipText  = "";

            _setupEditorData();
            _editorData.CaretLocation = _tipEnd;
            _editorData.SyntaxTree    = ast as DModule;
            _editorData.ModuleCode    = _sources[filename];
            // codeOffset+1 because otherwise it does not work on the first character
            _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 2;

            var ctxt = ResolutionContext.Create(_editorData);
            var rr   = DResolver.ResolveType(_editorData, ctxt);

            _tipText = "";
            if (rr != null && rr.Length > 0)
            {
                var res = rr[rr.Length - 1];
                var n   = DResolver.GetResultMember(res);

                _tipStart = n.Location;
                _tipEnd   = n.EndLocation;
                INode node = n.NodeRoot;
                if (node is DModule)
                {
                    _tipText = (node as DModule).FileName;
                }
            }
        }
Exemplo n.º 8
0
        public void BuildCompletionData(IEditorData Editor,
                                        string EnteredText,
                                        out string lastResultPath)
        {
            lastResultPath = null;

            IStatement curStmt  = null;
            var        curBlock = DResolver.SearchBlockAt(Editor.SyntaxTree, Editor.CaretLocation, out curStmt);

            if (curBlock == null)
            {
                return;
            }

            IEnumerable <INode> listedItems = null;

            // Usually shows variable members
            #region DotCompletion
            if (EnteredText == ".")
            {
                alreadyAddedModuleNameParts.Clear();

                var resolveResults = DResolver.ResolveType(
                    Editor,
                    new ResolverContext
                {
                    ScopedBlock     = curBlock,
                    ParseCache      = Editor.ParseCache,
                    ImportCache     = Editor.ImportCache,
                    ScopedStatement = curStmt
                }
                    );

                if (resolveResults == null)                 //TODO: Add after-space list creation when an unbound . (Dot) was entered which means to access the global scope
                {
                    return;
                }

                /*
                 * Note: When having entered a module name stub only (e.g. "std." or "core.") it's needed to show all packages that belong to that root namespace
                 */

                foreach (var rr in resolveResults)
                {
                    lastResultPath = ResolveResult.GetResolveResultString(rr);
                    BuildCompletionData(rr, curBlock);
                }
            }
            #endregion

            else if (EnteredText == null || EnteredText == " " || EnteredText.Length < 1 || IsIdentifierChar(EnteredText[0]))
            {
                // 1) Get current context the caret is at.
                ParserTrackerVariables trackVars = null;

                var parsedBlock = DResolver.FindCurrentCaretContext(
                    Editor.ModuleCode,
                    curBlock,
                    Editor.CaretOffset,
                    Editor.CaretLocation,
                    out trackVars);

                bool CaretAfterLastParsedObject = false;

                if (trackVars != null && trackVars.LastParsedObject != null)
                {
                    if (trackVars.LastParsedObject is IExpression)
                    {
                        CaretAfterLastParsedObject = Editor.CaretLocation > (trackVars.LastParsedObject as IExpression).EndLocation;
                    }
                    else if (trackVars.LastParsedObject is INode)
                    {
                        CaretAfterLastParsedObject = Editor.CaretLocation > (trackVars.LastParsedObject as INode).EndLocation;
                    }
                }

                // 2) If in declaration and if node identifier is expected, do not show any data
                if (trackVars == null ||
                    (trackVars.LastParsedObject is INode &&
                     !CaretAfterLastParsedObject &&
                     trackVars.ExpectingIdentifier) ||
                    (trackVars.LastParsedObject is TokenExpression &&
                     !CaretAfterLastParsedObject &&
                     DTokens.BasicTypes[(trackVars.LastParsedObject as TokenExpression).Token] &&
                     !string.IsNullOrEmpty(EnteredText) &&
                     IsIdentifierChar(EnteredText[0]))
                    )
                {
                    return;
                }

                var visibleMembers = DResolver.MemberTypes.All;

                if (trackVars.LastParsedObject is ImportStatement && !CaretAfterLastParsedObject)
                {
                    visibleMembers = DResolver.MemberTypes.Imports;
                }
                else if (trackVars.LastParsedObject is NewExpression && (trackVars.IsParsingInitializer || !CaretAfterLastParsedObject))
                {
                    visibleMembers = DResolver.MemberTypes.Imports | DResolver.MemberTypes.Types;
                }
                else if (EnteredText == " ")
                {
                    return;
                }
                // In class bodies, do not show variables
                else if (!(parsedBlock is BlockStatement) && !trackVars.IsParsingInitializer)
                {
                    visibleMembers = DResolver.MemberTypes.Imports | DResolver.MemberTypes.Types | DResolver.MemberTypes.Keywords;
                }

                // In a method, parse from the method's start until the actual caret position to get an updated insight
                if (visibleMembers.HasFlag(DResolver.MemberTypes.Variables) && curBlock is DMethod)
                {
                    if (parsedBlock is BlockStatement)
                    {
                        var blockStmt = parsedBlock as BlockStatement;

                        // Insert the updated locals insight.
                        // Do not take the caret location anymore because of the limited parsing of our code.
                        var scopedStmt = blockStmt.SearchStatementDeeply(blockStmt.EndLocation /*Editor.CaretLocation*/);

                        var decls = BlockStatement.GetItemHierarchy(scopedStmt, Editor.CaretLocation);

                        foreach (var n in decls)
                        {
                            CompletionDataGenerator.Add(n);
                        }
                    }
                }

                if (visibleMembers != DResolver.MemberTypes.Imports)                 // Do not pass the curStmt because we already inserted all updated locals a few lines before!
                {
                    listedItems = DResolver.EnumAllAvailableMembers(curBlock, null /*, curStmt*/, Editor.CaretLocation, Editor.ParseCache, visibleMembers);
                }

                //TODO: Split the keywords into such that are allowed within block statements and non-block statements
                // Insert typable keywords
                if (visibleMembers.HasFlag(DResolver.MemberTypes.Keywords))
                {
                    foreach (var kv in DTokens.Keywords)
                    {
                        CompletionDataGenerator.Add(kv.Key);
                    }
                }

                #region Add module name stubs of importable modules
                if (visibleMembers.HasFlag(DResolver.MemberTypes.Imports))
                {
                    var nameStubs    = new Dictionary <string, string>();
                    var availModules = new List <IAbstractSyntaxTree>();
                    foreach (var mod in Editor.ParseCache)
                    {
                        if (string.IsNullOrEmpty(mod.ModuleName))
                        {
                            continue;
                        }

                        var parts = mod.ModuleName.Split('.');

                        if (!nameStubs.ContainsKey(parts[0]) && !availModules.Contains(mod))
                        {
                            if (parts[0] == mod.ModuleName)
                            {
                                availModules.Add(mod);
                            }
                            else
                            {
                                nameStubs.Add(parts[0], GetModulePath(mod.FileName, parts.Length, 1));
                            }
                        }
                    }

                    foreach (var kv in nameStubs)
                    {
                        CompletionDataGenerator.Add(kv.Key, PathOverride: kv.Value);
                    }

                    foreach (var mod in availModules)
                    {
                        CompletionDataGenerator.Add(mod.ModuleName, mod);
                    }
                }
                #endregion
            }

            // Add all found items to the referenced list
            if (listedItems != null)
            {
                foreach (var i in listedItems)
                {
                    if (CanItemBeShownGenerally(i) /* && dm.IsStatic*/)
                    {
                        CompletionDataGenerator.Add(i);
                    }
                }
            }
        }
Exemplo n.º 9
0
        static ResolveResult[] HandleIdDeclaration(IdentifierDeclaration typeId,
                                                   ResolverContext lastResCtxt,
                                                   IAbstractSyntaxTree SyntaxTree,
                                                   CodeScanResult csr,
                                                   Dictionary <string, ResolveResult> compDict)
        {
            var typeString = typeId.ToString();

            bool WasAlreadyResolved = false;

            ResolveResult[] allCurrentResults = null;
            ResolveResult   rr = null;

            /*
             * string,wstring,dstring are highlighted by the editor's syntax definition automatically..
             * Anyway, allow to resolve e.g. "object.string"
             */
            if (typeString == "" || typeString == "string" || typeString == "wstring" || typeString == "dstring")
            {
                return(null);
            }

            lastResCtxt.ScopedBlock = DResolver.SearchBlockAt(SyntaxTree, typeId.Location, out lastResCtxt.ScopedStatement);
            if (typeString == "th" && typeId.Location.Line == 114)
            {
            }
            if (!(WasAlreadyResolved = compDict.TryGetValue(typeString, out rr)))
            {
                allCurrentResults = DResolver.ResolveType(typeId, lastResCtxt);

                if (allCurrentResults != null && allCurrentResults.Length > 0)
                {
                    rr = allCurrentResults[0];
                }
            }

            if (rr == null)
            {
                if (typeId is IdentifierDeclaration)
                {
                    csr.UnresolvedIdentifiers.Add(typeId as IdentifierDeclaration);
                }
            }
            else
            {
                /*
                 * Note: It is of course possible to highlight more than one type in one type declaration!
                 * So, we scan down the result hierarchy for TypeResults and highlight all of them later.
                 */
                var curRes = rr;

                /*
                 * Note: Since we want to use results multiple times,
                 * we at least have to 'update' their type declarations
                 * to ensure that the second, third, fourth etc. occurence of this result
                 * are also highlit (and won't(!) cause an Already-Added-Exception of our finalDict-Array)
                 */
                var curTypeDeclBase = typeId as ITypeDeclaration;

                while (curRes != null)
                {
                    if (curRes is MemberResult)
                    {
                        var mr = curRes as MemberResult;

                        // If curRes is an alias or a template parameter, highlight it
                        if (mr.ResolvedMember is TemplateParameterNode ||
                            (mr.ResolvedMember is DVariable &&
                             (mr.ResolvedMember as DVariable).IsAlias))
                        {
                            try
                            {
                                csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);
                            }
                            catch { }

                            // See performance reasons
                            //if (curRes != rr && !WasAlreadyResolved && !) compDict.Add(curTypeDeclBase.ToString(), curRes);
                        }
                    }

                    else if (curRes is TypeResult)
                    {
                        // Yeah, in quite all cases we do identify a class via its name ;-)
                        if (curTypeDeclBase is IdentifierDeclaration &&
                            !(curTypeDeclBase is DTokenDeclaration) &&
                            !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration))
                        {
                            csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);

                            // See performance reasons
                            //if (curRes != rr && !WasAlreadyResolved) compDict.Add(curTypeDeclBase.ToString(), curRes);
                        }
                    }

                    else if (curRes is ModuleResult)
                    {
                        if (curTypeDeclBase is IdentifierDeclaration &&
                            !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration))
                        {
                            csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);
                        }
                    }

                    curRes          = curRes.ResultBase;
                    curTypeDeclBase = curTypeDeclBase.InnerDeclaration;
                }
            }
            return(allCurrentResults);
        }