Пример #1
0
        public void GetTip(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _tipStart = new CodeLocation(startIndex + 1, startLine);
            _tipEnd   = new CodeLocation(startIndex + 2, startLine);
            _tipText.Clear();

            _setupEditorData();
            _editorData.CaretLocation = _tipStart;
            _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) + 1;

            DResolver.NodeResolutionAttempt attempt;
            var types = DResolver.ResolveTypeLoosely(_editorData, out attempt);

            _tipText.Clear();

            if (types != null)
            {
                if (types.DeclarationOrExpressionBase != null)
                {
                    _tipStart = types.DeclarationOrExpressionBase.Location;
                    _tipEnd   = types.DeclarationOrExpressionBase.EndLocation;
                }

                DNode dn = null;

                foreach (var t in AmbiguousType.TryDissolve(types))
                {
                    _tipText.Append(NodeToolTipContentGen.Instance.GenTooltipSignature(t)).Append("\a");
                    if (t is DSymbol)
                    {
                        dn = (t as DSymbol).Definition;
                    }
                }

                while (_tipText.Length > 0 && _tipText[_tipText.Length - 1] == '\a')
                {
                    _tipText.Length--;
                }

                if (dn != null)
                {
                    VDServerCompletionDataGenerator.GenerateNodeTooltipBody(dn, _tipText);
                }

                while (_tipText.Length > 0 && _tipText[_tipText.Length - 1] == '\a')
                {
                    _tipText.Length--;
                }
            }
        }
Пример #2
0
        public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

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

            _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;

            ISyntaxRegion sr;

            DResolver.NodeResolutionAttempt attempt;
            var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt, out sr);

            _tipText.Clear();
            if (rr != null)
            {
                var n = DResolver.GetResultMember(rr, true);

                if (n == null)
                {
                    return;
                }

                bool decl = false;
                var  mthd = n as DMethod;
                if (mthd != null)
                {
                    decl = mthd.Body == null;
                }
                else if (n.ContainsAttribute(DTokens.Extern))
                {
                    decl = true;
                }
                if (decl)
                {
                    _tipText.Append("EXTERN:");
                }

                _tipStart = n.Location;
                _tipEnd   = n.EndLocation;
                INode node = n.NodeRoot;
                if (node is DModule)
                {
                    _tipText.Append((node as DModule).FileName);
                }
            }
        }
Пример #3
0
        public void GetReferences(string filename, string tok, uint line, uint idx, string expr)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _setupEditorData();
            CodeLocation loc = new CodeLocation((int)idx + 1, (int)line);

            _editorData.CaretLocation = loc;
            _editorData.SyntaxTree    = ast as DModule;
            _editorData.ModuleCode    = _sources[filename];
            _editorData.CaretOffset   = getCodeOffset(_editorData.ModuleCode, loc);

            _references = null;

            ISyntaxRegion sr;

            DResolver.NodeResolutionAttempt attempt;
            var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt, out sr);

            StringBuilder refs = new StringBuilder();

            if (rr != null)
            {
                var n = DResolver.GetResultMember(rr, true);

                if (n != null)
                {
                    var ctxt = ResolutionContext.Create(_editorData, true);
                    if (n.ContainsAttribute(DTokens.Private) || ((n is DVariable) && (n as DVariable).IsLocal))
                    {
                        GetReferencesInModule(ast, refs, n, ctxt);
                    }
                    else
                    {
                        foreach (var basePath in _imports.Split('\n'))
                        {
                            foreach (var mod in GlobalParseCache.EnumModulesRecursively(basePath))
                            {
                                GetReferencesInModule(mod, refs, n, ctxt);
                            }
                        }
                    }
                }
                //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null);
            }
            _references = refs;
        }
Пример #4
0
        public static AbstractType[] ResolveHoveredCodeLoosely(out ResolutionContext ctxt, out IEditorData ed, out DResolver.NodeResolutionAttempt resolutionAttempt, Document doc = null)
        {
            ed = CreateEditorData(doc);
            if (ed == null)
            {
                resolutionAttempt = DResolver.NodeResolutionAttempt.Normal;
                ctxt = null;
                return(null);
            }
            ctxt = ResolutionContext.Create(ed, false);

            //return DResolver.ResolveTypeLoosely(ed, out resolutionAttempt, ctxt);
            return(AmbiguousType.TryDissolve(DResolver.ResolveTypeLoosely(ed, out resolutionAttempt, ctxt)).ToArray());
        }
Пример #5
0
        public static List <AbstractTooltipContent> BuildToolTip(IEditorData Editor)
        {
            DResolver.NodeResolutionAttempt att;
            var rr = DResolver.ResolveTypeLoosely(Editor, out att);

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

            var l = new List <AbstractTooltipContent>();

            foreach (var res in rr)
            {
                l.Add(BuildTooltipContent(res));
            }

            return(l);
        }
Пример #6
0
        public override TooltipItem GetItem(TextEditor editor, int offset)
        {
            // Note: Normally, the document already should be open
            var doc = IdeApp.Workbench.GetDocument(editor.Document.FileName);

            if (doc == null || !(doc.ParsedDocument is ParsedDModule))
            {
                return(null);
            }

            // Due the first note, the AST already should exist
            var ast = (doc.ParsedDocument as ParsedDModule).DDom;

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

            // Get code cache
            var codeCache = DResolverWrapper.CreateCacheList(doc);

            // Create editor context
            var line = editor.GetLineByOffset(offset);

            var ed = new EditorData {
                CaretOffset   = offset,
                CaretLocation = new CodeLocation(offset - line.Offset, editor.OffsetToLineNumber(offset)),
                ModuleCode    = editor.Text,
                ParseCache    = codeCache,
                SyntaxTree    = ast
            };

            // Let the engine build all contents
            DResolver.NodeResolutionAttempt att;
            var rr = DResolver.ResolveTypeLoosely(ed, out att);

            // Create tool tip item
            if (rr != null)
            {
                return(new TooltipItem(rr, offset, 1));
            }
            return(null);
        }
Пример #7
0
        public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

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

            _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;

            DResolver.NodeResolutionAttempt attempt;
            var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt);

            _tipText.Clear();
            if (rr != null)
            {
                var n = DResolver.GetResultMember(rr, true);

                if (n == null)
                {
                    return;
                }

                _tipStart = n.Location;
                _tipEnd   = n.EndLocation;
                INode node = n.NodeRoot;
                if (node is DModule)
                {
                    _tipText.Append((node as DModule).FileName);
                }
            }
        }