/// <summary> /// Determines if current caret position is in the same function /// argument list as before or is it a different one and signature /// help session should be dismissed and re-triggered. This is helpful /// when user types nested function calls such as 'a(b(c(...), d(...)))' /// </summary> public static bool IsSameSignatureContext(ITextView textView, ITextBuffer subjectBuffer) { ISignatureHelpBroker signatureBroker = EditorShell.Current.ExportProvider.GetExportedValue <ISignatureHelpBroker>(); var sessions = signatureBroker.GetSessions(textView); Debug.Assert(sessions.Count < 2); if (sessions.Count == 1) { IFunctionInfo sessionFunctionInfo = null; sessions[0].Properties.TryGetProperty <IFunctionInfo>("functionInfo", out sessionFunctionInfo); if (sessionFunctionInfo != null) { try { IREditorDocument document = REditorDocument.FromTextBuffer(textView.TextBuffer); document.EditorTree.EnsureTreeReady(); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer( document.EditorTree.AstRoot, subjectBuffer.CurrentSnapshot, textView.Caret.Position.BufferPosition); return(parametersInfo != null && parametersInfo.FunctionName == sessionFunctionInfo.Name); } catch (Exception) { } } } return(false); }
public ISignatureHelpSession GetSignatureSession() { ISignatureHelpBroker broker = EditorShell.Current.ExportProvider.GetExportedValue <ISignatureHelpBroker>(); var sessions = broker.GetSessions(EditorWindow.CoreEditor.View); ISignatureHelpSession session = sessions.FirstOrDefault(); int retries = 0; while (session == null && retries < 10) { this.DoIdle(1000); sessions = broker.GetSessions(EditorWindow.CoreEditor.View); session = sessions.FirstOrDefault(); retries++; } return(session); }
/// <summary> /// Determines if current caret position is in the same function /// argument list as before or is it a different one and signature /// help session should be dismissed and re-triggered. This is helpful /// when user types nested function calls such as 'a(b(c(...), d(...)))' /// </summary> public static bool IsSameSignatureContext(ITextView textView, ITextBuffer subjectBuffer, ISignatureHelpBroker signatureBroker) { var sessions = signatureBroker.GetSessions(textView); Debug.Assert(sessions.Count < 2); if (sessions.Count == 1) { IFunctionInfo sessionFunctionInfo = null; sessions[0].Properties.TryGetProperty<IFunctionInfo>("functionInfo", out sessionFunctionInfo); if (sessionFunctionInfo != null) { try { IREditorDocument document = REditorDocument.FromTextBuffer(textView.TextBuffer); document.EditorTree.EnsureTreeReady(); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer( document.EditorTree.AstRoot, subjectBuffer.CurrentSnapshot, textView.Caret.Position.BufferPosition); return parametersInfo != null && parametersInfo.FunctionName == sessionFunctionInfo.Name; } catch (Exception) { } } } return false; }
private void StartSignatureSession() { if (_currentSignatureSession != null) { return; } if (_signatureHelpBroker.IsSignatureHelpActive(_textView)) { _currentSignatureSession = _signatureHelpBroker.GetSessions(_textView)[0]; } else { var point = _textView.Caret.Position.BufferPosition; var snapshot = point.Snapshot; var trackingPoint = snapshot.CreateTrackingPoint(point, PointTrackingMode.Positive); _currentSignatureSession = _signatureHelpBroker.CreateSignatureHelpSession(_textView, trackingPoint, true); _textView.TextBuffer.Properties.AddProperty(typeof(ISignatureHelpSession), _currentSignatureSession); } _currentSignatureSession.Dismissed += SignatureSessionDismissed; _currentSignatureSession.Start(); }
internal bool StartSignatureSession(bool comma, IXTypeSymbol type = null, string methodName = null, char triggerchar = '\0') { WriteOutputMessage("StartSignatureSession()"); if (_signatureSession != null) { return(false); } IXMemberSymbol currentElement = null; SnapshotPoint ssp = this._textView.Caret.Position.BufferPosition; if (triggerchar == '(' && ssp.Position < ssp.Snapshot.Length && ssp.GetChar() == ')') { ssp -= 1; } var location = _textView.FindLocation(ssp); if (location == null || location.Member == null) { return(false); } if (location.Member.Range.StartLine == location.LineNumber) { return(false); } var props = new XSharpSignatureProperties(location); props.triggerChar = triggerchar; props.triggerPosition = this._textView.Caret.Position.BufferPosition.Position; if (type != null && methodName != null) { var findStatic = triggerchar == '.'; currentElement = XSharpLookup.SearchMethod(location, type, methodName, Modifiers.Private, findStatic).FirstOrDefault(); } else { currentElement = findElementAt(comma, ssp, props); } if (currentElement == null) { return(false); } SnapshotPoint caret = _textView.Caret.Position.BufferPosition; ITextSnapshot caretsnapshot = caret.Snapshot; // if (_signatureBroker.IsSignatureHelpActive(_textView)) { _signatureSession = _signatureBroker.GetSessions(_textView)[0]; } else { _signatureSession = _signatureBroker.CreateSignatureHelpSession(_textView, caretsnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } _signatureSession.Properties[typeof(XSharpSignatureProperties)] = props; if (location.Member.Kind.IsGlobalTypeMember()) { props.Visibility = Modifiers.Public; } else { props.Visibility = Modifiers.Protected; } _signatureSession.Dismissed += OnSignatureSessionDismiss; props.Element = currentElement; if (comma) { var tokenList = XSharpTokenTools.GetTokenListBeforeCaret(location, out var state); bool done = false; int nested = 0; for (int i = tokenList.Count - 1; i >= 0 && !done; i--) { var token = tokenList[i]; switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: done = nested == 0; if (done) { props.Start = token.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - token.Position; } nested -= 1; break; case XSharpLexer.RPAREN: case XSharpLexer.RCURLY: case XSharpLexer.RBRKT: nested += 1; break; } } } else { props.Start = ssp.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - ssp.Position; } try { _signatureSession.Start(); } catch (Exception e) { XSettings.LogException(e, "Start Signature session failed:"); } // return(true); }
public IReadOnlyList <IEditorIntellisenseSession> GetSessions(IEditorView view) => _signatureBroker.GetSessions(view.As <ITextView>()) .Select(s => s.ToEditorIntellisenseSession()) .ExcludeDefault() .ToList();