Exemple #1
0
        public void GetTip(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            IAbstractSyntaxTree ast = null;

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

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

            EditorData editorData = new EditorData();

            editorData.CaretLocation = _tipStart;
            editorData.SyntaxTree    = ast as DModule;
            editorData.ModuleCode    = _sources[filename];
            editorData.CaretOffset   = getCodeOffset(editorData.ModuleCode, _tipStart);
            AbstractTooltipContent[] content = AbstractTooltipProvider.BuildToolTip(editorData);
            if (content == null || content.Length == 0)
            {
                _tipText = "";
            }
            else
            {
                foreach (var c in content)
                {
                    _tipText += c.Title + ":" + c.Description + "\n";
                }
            }

            //MessageBox.Show("GetTip()");
            //throw new NotImplementedException();
        }
Exemple #2
0
        public void GetTip(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(startIndex + 2, startLine);
            _tipText  = "";

            _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;
            List <AbstractTooltipContent> content = AbstractTooltipProvider.BuildToolTip(_editorData);

            if (content == null || content.Count == 0)
            {
                _tipText = "";
            }
            else
            {
                foreach (var c in content)
                {
                    if (!string.IsNullOrEmpty(_tipText))
                    {
                        _tipText += "\n\n";
                    }
                    if (string.IsNullOrWhiteSpace(c.Description))
                    {
                        _tipText += c.Title;
                    }
                    else
                    {
                        _tipText += c.Title + ":\n" + c.Description;
                    }
                }
            }

            //MessageBox.Show("GetTip()");
            //throw new NotImplementedException();
        }
Exemple #3
0
        public static void BuildToolTip(DEditorDocument EditorDocument, ToolTipRequestArgs ToolTipRequest)
        {
            if (!ToolTipRequest.InDocument)
            {
                return;
            }

            var dataOverride = new EditorData();

            dataOverride.ApplyFrom(EditorDocument);

            dataOverride.CaretLocation = new CodeLocation(ToolTipRequest.Column, ToolTipRequest.Line);
            dataOverride.CaretOffset   = EditorDocument.Editor.Document.GetOffset(ToolTipRequest.Position);

            var ttContents = AbstractTooltipProvider.BuildToolTip(dataOverride);

            if (ttContents == null)
            {
                return;
            }

            int offset = EditorDocument.Editor.Document.GetOffset(ToolTipRequest.Line, ToolTipRequest.Column);

            try
            {
                var vertStack = new StackPanel()
                {
                    Orientation = Orientation.Vertical
                };
                string lastDescription = "";
                foreach (var tt in ttContents)
                {
                    vertStack.Children.Add(
                        ToolTipContentHelper.CreateToolTipContent(
                            tt.Title,
                            lastDescription == tt.Description ? null : lastDescription = tt.Description)
                        as UIElement);
                }

                ToolTipRequest.ToolTipContent = vertStack;
            }
            catch { }
        }
        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 EditorContext = new EditorData {
                CaretOffset   = offset,
                CaretLocation = new CodeLocation(offset - line.Offset, editor.OffsetToLineNumber(offset)),
                ModuleCode    = editor.Text,
                ParseCache    = codeCache,
                SyntaxTree    = ast as DModule
            };

            // Let the engine build all contents
            var ttContents = AbstractTooltipProvider.BuildToolTip(EditorContext);

            // Create tool tip item
            if (ttContents != null)
            {
                return(new TooltipItem(ttContents, offset, 1));
            }
            return(null);
        }