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 XSharpModel.XTypeMember member = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file); XSharpModel.XType 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, false, _file, false, member); // LookUp for the BaseType, reading the TokenList (From left to right) CompletionElement gotoElement; String currentNS = ""; if (currentNamespace != null) { currentNS = currentNamespace.Name; } XSharpModel.CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect); // if ((gotoElement != null) && (gotoElement.XSharpElement != null)) { peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.XSharpElement, _peekResultFactory)); } } catch (Exception ex) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpPeekItemSource.AugmentPeekSession failed : "); XSharpProjectPackage.Instance.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { try { XSharpProjectPackage.Instance.DisplayOutPutMessage("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"]; m_applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(start, length), SpanTrackingMode.EdgeInclusive, 0); object elt = session.Properties["Element"]; m_session = session; if (elt is XSharpModel.XElement) { XSharpModel.XElement element = elt as XSharpModel.XElement; signatures.Add(CreateSignature(m_textBuffer, element.Prototype, "", ApplicableToSpan, comma)); // if (elt is XSharpModel.XTypeMember) { XSharpModel.XTypeMember xMember = elt as XSharpModel.XTypeMember; List <XSharpModel.XTypeMember> namesake = xMember.Namesake(); foreach (var member in namesake) { signatures.Add(CreateSignature(m_textBuffer, member.Prototype, "", ApplicableToSpan, comma)); } // } // 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); } else if (elt is System.Reflection.MemberInfo) { System.Reflection.MemberInfo element = elt as System.Reflection.MemberInfo; XSharpLanguage.MemberAnalysis analysis = new XSharpLanguage.MemberAnalysis(element); if (analysis.IsInitialized) { signatures.Add(CreateSignature(m_textBuffer, analysis.Prototype, "", ApplicableToSpan, comma)); // Any other member with the same name in the current Type and in the Parent(s) ? SystemNameSake(element.DeclaringType, signatures, element.Name, analysis.Prototype, comma); // m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged); } } session.Dismissed += OnSignatureHelpSessionDismiss; } catch (Exception ex) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed "); XSharpProjectPackage.Instance.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (!XSharpProjectPackage.Instance.DebuggerIsRunning) { try { XSharpModel.ModelWalker.Suspend(); var package = XSharp.Project.XSharpProjectPackage.Instance; var optionsPage = package.GetIntellisenseOptionsPage(); if (optionsPage.DisableQuickInfo) { return; } // Map the trigger point down to our buffer. SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; if (subjectTriggerPoint.Value.Position == lastTriggerPoint) { if (!string.IsNullOrEmpty(lastHelp)) { qiContent.Add(lastHelp); } if (lastSpan != null) { applicableToSpan = currentSnapshot.CreateTrackingSpan( lastSpan.GetSpan(currentSnapshot), SpanTrackingMode.EdgeInclusive); } return; } lastTriggerPoint = subjectTriggerPoint.Value.Position; //look for occurrences of our QuickInfo words in the span ITextStructureNavigator navigator = _provider.NavigatorService.GetTextStructureNavigator(_subjectBuffer); TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value); string searchText = extent.Span.GetText(); // First, where are we ? int caretPos = subjectTriggerPoint.Value.Position; int lineNumber = subjectTriggerPoint.Value.GetContainingLine().LineNumber; var snapshot = session.TextView.TextBuffer.CurrentSnapshot; if (_file == null) { return; } // Then, the corresponding Type/Element if possible IToken stopToken; //ITokenStream tokenStream; XSharpModel.XTypeMember member = XSharpLanguage.XSharpTokenTools.FindMember(lineNumber, _file); XSharpModel.XType currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(caretPos, _file); // adjust caretpos, for other completions we need to stop before the caret. Now we include the caret List <String> tokenList = XSharpLanguage.XSharpTokenTools.GetTokenList(caretPos + 1, lineNumber, snapshot, out stopToken, true, _file, false, member); // Check if we can get the member where we are //if (tokenList.Count > 1) //{ // tokenList.RemoveRange(0, tokenList.Count - 1); //} // LookUp for the BaseType, reading the TokenList (From left to right) XSharpLanguage.CompletionElement gotoElement; String currentNS = ""; if (currentNamespace != null) { currentNS = currentNamespace.Name; } XSharpModel.CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber); // // if ((gotoElement != null) && (gotoElement.IsInitialized)) { // Ok, find it ! Let's go ;) applicableToSpan = currentSnapshot.CreateTrackingSpan ( extent.Span.Start, searchText.Length, SpanTrackingMode.EdgeInclusive ); if (gotoElement.XSharpElement != null) { if (gotoElement.XSharpElement.Kind == XSharpModel.Kind.Constructor) { if (gotoElement.XSharpElement.Parent != null) { qiContent.Add(gotoElement.XSharpElement.Parent.Description); } } else { qiContent.Add(gotoElement.XSharpElement.Description); } } else if (gotoElement.SystemElement is TypeInfo) { XSharpLanguage.TypeAnalysis analysis = new XSharpLanguage.TypeAnalysis((TypeInfo)gotoElement.SystemElement); qiContent.Add(analysis.Description); } else { // This works with System.MemberInfo AND XSharpLanguage.MemberAnalysis analysis = null; if (gotoElement.SystemElement is MemberInfo) { analysis = new XSharpLanguage.MemberAnalysis(gotoElement.SystemElement); if (analysis.IsInitialized) { if ((analysis.Kind == XSharpModel.Kind.Constructor) && (cType != null) && (cType.SType != null)) { XSharpLanguage.TypeAnalysis typeAnalysis; typeAnalysis = new XSharpLanguage.TypeAnalysis(cType.SType.GetTypeInfo()); if (typeAnalysis.IsInitialized) { qiContent.Add(typeAnalysis.Description); } } else { qiContent.Add(analysis.Description); } } } } if (qiContent.Count > 0) { lastHelp = (string)qiContent[0]; lastSpan = applicableToSpan; } return; } } catch (Exception ex) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpQuickInfo.AugmentQuickInfoSession failed : "); XSharpProjectPackage.Instance.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } } }
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.XTypeMember 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) { System.Diagnostics.Debug.WriteLine("HighlightWordTag Exception: " + ex.Message); } }