Exemple #1
0
            private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
            {
                if (XSharpProjectPackage.Instance.DebuggerIsRunning)
                {
                    return;
                }
                try
                {
                    //find the mouse position by mapping down to the subject buffer
                    SnapshotPoint?point = m_textView.BufferGraph.MapDownToFirstMatch
                                              (new SnapshotPoint(m_textView.TextSnapshot, e.Position),
                                              PointTrackingMode.Positive,
                                              snapshot => m_subjectBuffers.Contains(snapshot.TextBuffer),
                                              PositionAffinity.Predecessor);

                    if (point.HasValue && point.Value.Position != lastPointPosition)
                    {
                        lastPointPosition = point.Value.Position;
                        if (!m_provider.QuickInfoBroker.IsQuickInfoActive(m_textView))
                        {
                            ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position,
                                                                                                   PointTrackingMode.Positive);
                            m_session = m_provider.QuickInfoBroker.TriggerQuickInfo(m_textView, triggerPoint, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    XSettings.DisplayOutputMessage("XSharpQuickInfo.OnTextViewMouseHover failed");
                    XSettings.DisplayException(ex);
                }
            }
Exemple #2
0
 internal void WriteOutputMessage(string message)
 {
     if (XSettings.EnableQuickInfoLog && XSettings.EnableLogging)
     {
         XSettings.DisplayOutputMessage("XSharp.QuickInfoSource :" + message);
     }
 }
 void WriteOutputMessage(string sMessage)
 {
     if (XSettings.EnableBraceMatchLog && XSettings.EnableLogging)
     {
         XSettings.DisplayOutputMessage("Brace Matching: " + sMessage);
     }
 }
Exemple #4
0
 internal void Debug(string strMessage)
 {
     if (XSettings.EnableParameterLog && XSettings.EnableLogging)
     {
         XSettings.DisplayOutputMessage(strMessage);
     }
 }
 internal void WriteOutputMessage(string strMessage)
 {
     if (XSettings.EnableCodeCompletionLog && XSettings.EnableLogging)
     {
         XSettings.DisplayOutputMessage(strMessage);
     }
 }
Exemple #6
0
        static public bool GetMemberParameters(IXMember member, XProject project, IList <string> names, IList <string> descriptions)
        {
            if (member == null)
            {
                return(false);
            }

            if (member is XMemberDefinition)
            {
                var xdef  = (XMemberDefinition)member;
                var xml   = xdef.XmlComments;
                var xfile = XSharpXMLDocTools.firstfile;
                if (xfile != null && !string.IsNullOrEmpty(xml))
                {
                    getParameterInfo(xfile, xml, names, descriptions);
                    return(true);
                }
                return(false);
            }
            if (!(member is XMemberReference))
            {
                return(false);
            }

            var xmember             = (XMemberReference)member;
            var declarationAssembly = xmember.Assembly;
            var file = XSharpXMLDocTools.GetXmlDocFile(declarationAssembly, project);

            if (file == null)
            {
                return(false);
            }
            try
            {
                var sig = xmember.XMLSignature;
                if (!string.IsNullOrEmpty(sig))
                {
                    uint   id     = 0;
                    string xml    = "";
                    var    result = file.ParseMemberSignature(sig, out id);
                    result = file.GetMemberXML(id, out xml);
                    getParameterInfo(file, xml, names, descriptions);
                }
            }
            catch (Exception e)
            {
                XSettings.DisplayOutputMessage("Exception in XSharpXMLDocMember.GetDocSummary");
                XSettings.DisplayException(e);
                return(false);
            }
            return(true);
        }
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            try
            {
                XSharpModel.ModelWalker.Suspend();
                if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                //
                var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
                if (!tp.HasValue)
                {
                    return;
                }
                //
                var    triggerPoint = tp.Value;
                IToken stopToken;
                //
                // Check if we can get the member where we are
                XMemberDefinition member           = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file);
                XTypeDefinition   currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(triggerPoint.Position, _file);

                var           lineNumber = triggerPoint.GetContainingLine().LineNumber;
                var           snapshot   = _textBuffer.CurrentSnapshot;
                List <String> tokenList  = XSharpTokenTools.GetTokenList(triggerPoint.Position, lineNumber, snapshot, out stopToken, true, _file, false, member);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                CompletionElement gotoElement;
                String            currentNS = "";
                if (currentNamespace != null)
                {
                    currentNS = currentNamespace.Name;
                }
                CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect);
                //
                if ((gotoElement != null) && (gotoElement.IsSourceElement))
                {
                    peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.SourceElement, _peekResultFactory));
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("XSharpPeekItemSource.AugmentPeekSession failed : ");
                XSettings.DisplayException(ex);
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            try
            {
                if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
                {
                    return;
                }
                var fileName = Path.GetFileName(this.peekableItem._gotoElement.File.FullPath);
                var label    = this.peekableItem._gotoElement.Name;
                var title    = string.Format("{0} - ({1}, {2})", fileName, this.peekableItem._gotoElement.Range.StartLine, this.peekableItem._gotoElement.Range.StartColumn + 1);

                using (var displayInfo = new PeekResultDisplayInfo2(label: label, labelTooltip: this.peekableItem._gotoElement.File.FullPath, title: title, titleTooltip: this.peekableItem._gotoElement.File.FullPath, startIndexOfTokenInLabel: 0, lengthOfTokenInLabel: label.Length))
                {
                    var result = peekableItem._peekResultFactory.Create
                                 (
                        displayInfo,
                        default(ImageMoniker),
                        this.peekableItem._gotoElement.File.FullPath,
                        this.peekableItem._gotoElement.Range.StartLine,
                        this.peekableItem._gotoElement.Range.StartColumn,
                        this.peekableItem._gotoElement.Range.EndLine,
                        this.peekableItem._gotoElement.Range.EndColumn,
                        this.peekableItem._gotoElement.Range.StartLine,
                        this.peekableItem._gotoElement.Range.StartColumn,
                        this.peekableItem._gotoElement.Range.EndLine,
                        this.peekableItem._gotoElement.Range.EndColumn,
                        false,
                        new Guid(XSharpConstants.EditorFactoryGuidString)
                                 );

                    resultCollection.Add(result);
                    callback.ReportProgress(1);
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("XSharpResultSource.FindResults failed : ");
                XSettings.DisplayException(ex);
            }
        }
Exemple #9
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            try
            {
                Debug("XSharpSignatureHelpSource.AugmentSignatureHelpSession()");
                XSharpModel.ModelWalker.Suspend();
                ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot;
                int           position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot);
                int           start    = (int)session.Properties["Start"];
                int           length   = (int)session.Properties["Length"];
                var           comma    = (bool)session.Properties["Comma"];
                var           file     = (XFile)session.Properties["File"];
                m_applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(
                    new Span(start, length), SpanTrackingMode.EdgeInclusive, 0);

                object elt = session.Properties["Element"];
                m_session = session;
                if (elt is IXElement)
                {
                    IXMember element = elt as IXMember;
                    //
                    if (elt is IXMember)
                    {
                        IXMember xMember = elt as IXMember;
                        var      names   = new List <string>();
                        var      proto   = xMember.Prototype;
                        names.Add(proto);
                        signatures.Add(CreateSignature(m_textBuffer, xMember, proto, "", ApplicableToSpan, comma, xMember.Kind == XSharpModel.Kind.Constructor, file));
                        var overloads = xMember.GetOverloads();
                        foreach (var member in overloads)
                        {
                            // prevent duplicate prototypes in the list  (when a child has overriden a method)
                            proto = member.Prototype;
                            if (!names.Contains(proto))
                            {
                                signatures.Add(CreateSignature(m_textBuffer, member, proto, "", ApplicableToSpan, comma, member.Kind == XSharpModel.Kind.Constructor, file));
                                names.Add(proto);
                            }
                        }
                    }
                    else if (element != null)
                    {
                        // Type ??
                        signatures.Add(CreateSignature(m_textBuffer, null, element.Prototype, "", ApplicableToSpan, comma, false, file));
                    }
                    // why not ?
                    int paramCount = int.MaxValue;
                    foreach (ISignature sig in signatures)
                    {
                        if (sig.Parameters.Count < paramCount)
                        {
                            paramCount = sig.Parameters.Count;
                        }
                    }
                    //
                    m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged);
                }
                session.Dismissed += OnSignatureHelpSessionDismiss;
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed ");
                XSettings.DisplayException(ex);
            }
            finally
            {
                XSharpModel.ModelWalker.Resume();
            }
        }
Exemple #10
0
        private void OnSelectionChanged(object sender, object e)
        {
            try
            {
                String selectedText = this.View.Selection.StreamSelectionSpan.GetText();
                if (!string.IsNullOrEmpty(selectedText) && !string.IsNullOrWhiteSpace(selectedText))
                {
                    // where are we
                    SnapshotPoint       currentRequest = this.View.Selection.Start.Position;
                    List <SnapshotSpan> wordSpans      = new List <SnapshotSpan>();
                    // Search for me please
                    TextExtent word      = TextStructureNavigator.GetExtentOfWord(currentRequest);
                    bool       foundWord = true;
                    //
                    if (!WordExtentIsValid(currentRequest, word))
                    {
                        //Same context ?
                        if (word.Span.Start != currentRequest ||
                            currentRequest == currentRequest.GetContainingLine().Start ||
                            char.IsWhiteSpace((currentRequest - 1).GetChar()))
                        {
                            foundWord = false;
                        }
                        else
                        {
                            // Move back, and start again
                            word = TextStructureNavigator.GetExtentOfWord(currentRequest - 1);

                            //If the word still isn't valid, we're done
                            if (!WordExtentIsValid(currentRequest, word))
                            {
                                foundWord = false;
                            }
                        }
                    }

                    if (!foundWord)
                    {
                        //If we couldn't find a word, clear out the existing markers
                        SynchronousUpdate(new NormalizedSnapshotSpanCollection());
                        return;
                    }
                    SnapshotSpan currentWord = word.Span;
                    selectedWord = this.View.Selection.StreamSelectionSpan.SnapshotSpan;


                    //If this is the current word, and the caret moved within a word, we're done.
                    if (!(selectedWord.HasValue && currentWord == selectedWord))
                    {
                        return;
                    }
                    //Find the new spans
                    FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
                    findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
                    // Values are zero-based
                    SnapshotPoint point = View.Caret.Position.BufferPosition;
                    // Retrieve the XFile
                    XSharpModel.XFile xFile = this.View.TextBuffer.GetFile();
                    if (xFile != null)
                    {
                        // Now, retrieve the current member
                        XSharpModel.XMemberDefinition member = XSharpTokenTools.FindMemberAtPosition(point.Position, xFile);
                        if (member == null)
                        {
                            return;
                        }
                        // Ok, so we now have the "range" of the Member, and will only select text in THIS member
                        SnapshotSpan memberSpan = new SnapshotSpan(currentWord.Snapshot, member.Interval.Start, member.Interval.Width);
                        // Get all the corresponding Words
                        Collection <SnapshotSpan> allFound    = TextSearchService.FindAll(findData);
                        Collection <SnapshotSpan> memberFound = new Collection <SnapshotSpan>();
                        foreach (SnapshotSpan ssp in allFound)
                        {
                            // Inside the Member ?
                            if (memberSpan.Contains(ssp))
                            {
                                memberFound.Add(ssp);
                            }
                        }
                        //
                        wordSpans.AddRange(memberFound);
                        // Show please
                        SynchronousUpdate(new NormalizedSnapshotSpanCollection(wordSpans));
                    }
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("HighlightWordTag Exception: " + ex.Message);
            }
        }
Exemple #11
0
        static public string GetMemberSummary(IXMember member, XProject project, out string returns, out string remarks)
        {
            string summary = null;

            returns = remarks = "";
            if (member == null)
            {
                return("");
            }

            //
            if (member is XMemberDefinition)
            {
                var xdef  = (XMemberDefinition)member;
                var xml   = xdef.XmlComments;
                var xfile = XSharpXMLDocTools.firstfile;
                if (xfile != null && !string.IsNullOrEmpty(xml))
                {
                    summary = getSummary(xfile, xml, out returns, out remarks);
                }
                return(summary);
            }
            if (!(member is XMemberReference))
            {
                return("");
            }

            var xmember             = (XMemberReference)member;
            var declarationAssembly = xmember.Assembly;

            //
            var file = XSharpXMLDocTools.GetXmlDocFile(declarationAssembly, project);

            if (file == null)
            {
                return(null);
            }
            lastfile = file;
            var sig = xmember.XMLSignature;

            try
            {
                if (!string.IsNullOrEmpty(sig))
                {
                    uint   id     = 0;
                    string xml    = "";
                    var    result = file.ParseMemberSignature(sig, out id);

                    result = file.GetMemberXML(id, out xml);
                    if (!string.IsNullOrEmpty(xml))
                    {
                        summary = getSummary(file, xml, out returns, out remarks);
                    }
                }
            }
            catch (Exception e)
            {
                XSettings.DisplayOutputMessage("Exception in XSharpXMLDocMember.GetDocSummary");
                XSettings.DisplayException(e);
            }
            //
            return(summary);
        }