public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures, AstRoot ast, Action <object> triggerSession) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); // Retrieve parameter positions from the current text buffer snapshot ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); if (parametersInfo != null) { position = Math.Min(parametersInfo.SignatureEnd, position); int start = Math.Min(position, snapshot.Length); int end = Math.Min(parametersInfo.SignatureEnd, snapshot.Length); ITrackingSpan applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive); // Get collection of function signatures from documentation (parsed RD file) IFunctionInfo functionInfo = FunctionIndex.GetFunctionInfo(parametersInfo.FunctionName, triggerSession, session.TextView); if (functionInfo != null && functionInfo.Signatures != null) { foreach (ISignatureInfo signatureInfo in functionInfo.Signatures) { ISignature signature = CreateSignature(session, functionInfo, signatureInfo, applicableToSpan, ast, position); signatures.Add(signature); } session.Properties["functionInfo"] = functionInfo; return(true); } } return(false); }
public async System.Threading.Tasks.Task CollectSignatureLists(ISignatureHelpSession newSession) { JavaEditor javaEditor = null; if (TextBuffer.Properties.TryGetProperty<JavaEditor>(typeof(JavaEditor), out javaEditor) && javaEditor.TypeRootIdentifier != null) { var textReader = new TextSnapshotToTextReader(TextBuffer.CurrentSnapshot) as TextReader; var position = newSession.GetTriggerPoint(TextBuffer).GetPosition(TextBuffer.CurrentSnapshot); var paramHelpRequest = ProtocolHandlers.CreateParamHelpRequest( textReader, javaEditor.TypeRootIdentifier, position); var paramHelpResponse = await javaEditor.JavaPkgServer.Send(javaEditor, paramHelpRequest); if (paramHelpResponse.responseType == Protocol.Response.ResponseType.ParamHelp && paramHelpResponse.paramHelpResponse != null) { if (paramHelpResponse.paramHelpResponse.status && paramHelpResponse.paramHelpResponse.signatures.Count != 0) { var applicableTo = TextBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(paramHelpResponse.paramHelpResponse.scopeStart, paramHelpResponse.paramHelpResponse.scopeLength), SpanTrackingMode.EdgeInclusive, 0); int selectedParameterIndex = paramHelpResponse.paramHelpResponse.paramCount; Signatures = TransformSignatures(TextBuffer, paramHelpResponse.paramHelpResponse.signatures, applicableTo, selectedParameterIndex); } } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer); ParseItem item = document.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null) return; Declaration dec = item.FindType<Declaration>(); if (dec == null || dec.PropertyName == null || dec.Colon == null) return; var span = _buffer.CurrentSnapshot.CreateTrackingSpan(dec.Colon.Start, dec.Length - dec.PropertyName.Length, SpanTrackingMode.EdgeNegative); ValueOrderFactory.AddSignatures method = ValueOrderFactory.GetMethod(dec); if (method != null) { signatures.Clear(); method(session, signatures, dec, span); Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => { session.Properties.AddProperty("dec", dec); session.Match(); }), DispatcherPriority.Normal, null); } }
public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures, AstRoot ast, Action <ITextView, IEnumerable <IRFunctionSignatureHelp> > callback) { // Try cached if this was a re-trigger on async information retrieval var eis = new EditorIntellisenseSession(session, _services); if (GetCachedSignatures(signatures, eis)) { return(true); } var editorBuffer = _textBuffer.ToEditorBuffer(); var position = session.GetTriggerPoint(_textBuffer).GetCurrentPosition(); var context = new RIntellisenseContext(eis, editorBuffer, ast, position); // See if information is immediately available var sigs = _engine.GetSignaturesAsync(context, null); if (sigs != null) { AddSignatures(signatures, ToVsEditorSignatures(sigs)); return(true); } // If not available, start async retrieval. Session wil be re-triggered // when information becomes available. _engine.GetSignaturesAsync(context, s => callback(session.TextView, s)); return(false); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { if (!session.TextView.Properties.ContainsProperty(SessionKey)) { return; } // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { var snapshot = _textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(snapshot); if (!triggerPoint.HasValue) return; var triggerLine = triggerPoint.Value.GetContainingLine(); var searchSpan = new SnapshotSpan(triggerLine.Start, triggerPoint.Value); var analysisResult = ThreadHelper.JoinableTaskFactory.Run( () => _documentAnalysis.GetAnalysisResultAsync(snapshot)); var triggerBlock = analysisResult.GetBlock(searchSpan.Start); var triggerToken = triggerBlock.Tokens .Where(t => ContainsInclusive(searchSpan, t.Span)) .OrderBy(t => t.Span.Start) .FirstOrDefault(t => t.Type == RadAsmTokenType.FunctionReference || t.Type == RadAsmTokenType.Instruction); if (triggerToken == null) return; var applicableSpan = new SnapshotSpan(triggerToken.Span.End, triggerLine.End); var trackingSpan = snapshot.CreateTrackingSpan(applicableSpan, SpanTrackingMode.EdgeInclusive); var parameterSpan = new SnapshotSpan(applicableSpan.Start, triggerPoint.Value); var parameterIdx = parameterSpan.GetCurrentParameter(_signatureConfig.TriggerParameterChar); switch (triggerToken.Type) { case RadAsmTokenType.FunctionReference: AddFunctionSignature(trackingSpan, triggerToken, parameterIdx, signatures); break; case RadAsmTokenType.Instruction: AddInstructionSignature(snapshot, trackingSpan, triggerToken, parameterIdx, signatures); break; } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer); ParseItem item = document.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null) return; Declaration dec = item.FindType<Declaration>(); if (dec == null || dec.PropertyName == null || dec.Colon == null) return; foreach (ISignature signature in signatures) { if (signature is ValueOrderSignature) { signatures.RemoveAt(signatures.Count - 1); break; } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { try { var snapshot = _buffer.CurrentSnapshot; var trackingPoint = session.GetTriggerPoint(_buffer); var position = trackingPoint.GetPosition(snapshot); var file = _compilerService.LatestResult?.GetFile(_document.FilePath); var compiledSnapshot = file?.Meta.Snapshot as ITextSnapshot; if (compiledSnapshot == null || compiledSnapshot.TextBuffer != _buffer) { return; } var span = new Span(position, 0); var applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive, 0); var signature = GetSignature(position, file.Ast, applicableToSpan); if (signature != null) { signatures.Add(signature); } } catch (Exception e) { Debug.WriteLine("AugmentSignatureHelpSession failed"); Debug.WriteLine(e.ToString()); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; // trigger point SnapshotPoint?point = session.GetTriggerPoint(snapshot); if (point == null) { return; } // get syntax tree SyntaxTree syntaxTree = snapshot.GetSyntaxTree(); var root = syntaxTree.Root as RobotsTxtDocumentSyntax; // find line in syntax tree ITextSnapshotLine line = point.Value.GetContainingLine(); RobotsTxtLineSyntax lineSyntax = root.Records.SelectMany(r => r.Lines) .Where(l => !l.NameToken.IsMissing && !l.DelimiterToken.IsMissing) .FirstOrDefault(l => l.Span.IntersectsWith(line.Extent)); // found if (lineSyntax != null) { if (lineSyntax.DelimiterToken.Span.Span.End <= point.Value) { // get semantic model ISemanticModel model = syntaxTree.GetSemanticModel(); // add signature signatures.Add(new RobotsTxtSignature(model, lineSyntax)); } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } ITextSnapshotLine line = point.Value.GetContainingLine(); string lineText = line.GetText().Trim(); if (!lineText.StartsWith("[", StringComparison.Ordinal)) { return; } _span = _buffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeNegative); signatures.Add(new SectionSignature("[*.cs]", "Matches multiple files with a .cs file extension", _span, session)); signatures.Add(new SectionSignature("[*.vb]", "Matches multiple files with a .vb file extension", _span, session)); signatures.Add(new SectionSignature("[*.{cs,vb}]", "Matches multiple files with brace expansion notation", _span, session)); signatures.Add(new SectionSignature("[app/**.js]", "Matches all .js files under lib directory", _span, session)); signatures.Add(new SectionSignature("[{package.json,.npmrc}]", "Matches the exact files - either package.json or .npmrc", _span, session)); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { if (!session.TextView.Properties.ContainsProperty(SessionKey)) { return; } // At the moment there is a bug in the javascript provider which causes it to // repeatedly insert the same Signature values into an ISignatureHelpSession // instance. There is no way, other than reflection, for us to prevent this // from happening. Instead we just ensure that our provider runs after // Javascript and then remove the values they add here signatures.Clear(); // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); if (encouragement != null) { var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); SnapshotPoint point = session.TextView.Caret.Position.BufferPosition - 2; TextExtent extent = m_navigator.GetTextStructureNavigator(m_textBuffer).GetExtentOfWord(point); string hintfunction = extent.Span.GetText(); var knownFunctions = m_parsedProject.GetAvailableFunctionSignatures(); foreach (var func in knownFunctions) { if (!func.Name.Text.Equals(hintfunction)) { continue; } foreach (var overload in func.Overloads) { signatures.Add(CreateSignature(m_textBuffer, func.Name.Text, overload, "Documentation goes here.", applicableToSpan)); } } }
public async System.Threading.Tasks.Task CollectSignatureLists(ISignatureHelpSession newSession) { JavaEditor javaEditor = null; if (TextBuffer.Properties.TryGetProperty <JavaEditor>(typeof(JavaEditor), out javaEditor) && javaEditor.TypeRootIdentifier != null) { var textReader = new TextSnapshotToTextReader(TextBuffer.CurrentSnapshot) as TextReader; var position = newSession.GetTriggerPoint(TextBuffer).GetPosition(TextBuffer.CurrentSnapshot); var paramHelpRequest = ProtocolHandlers.CreateParamHelpRequest( textReader, javaEditor.TypeRootIdentifier, position); var paramHelpResponse = await javaEditor.JavaPkgServer.Send(javaEditor, paramHelpRequest); if (paramHelpResponse.responseType == Protocol.Response.ResponseType.ParamHelp && paramHelpResponse.paramHelpResponse != null) { if (paramHelpResponse.paramHelpResponse.status && paramHelpResponse.paramHelpResponse.signatures.Count != 0) { var applicableTo = TextBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(paramHelpResponse.paramHelpResponse.scopeStart, paramHelpResponse.paramHelpResponse.scopeLength), SpanTrackingMode.EdgeInclusive, 0); int selectedParameterIndex = paramHelpResponse.paramHelpResponse.paramCount; Signatures = TransformSignatures(TextBuffer, paramHelpResponse.paramHelpResponse.signatures, applicableTo, selectedParameterIndex); } } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer); ParseItem item = document.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null) { return; } Declaration dec = item.FindType <Declaration>(); if (dec == null || dec.PropertyName == null || dec.Colon == null) { return; } foreach (ISignature signature in signatures) { if (signature is ValueOrderSignature) { signatures.RemoveAt(signatures.Count - 1); break; } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; // trigger point SnapshotPoint? point = session.GetTriggerPoint(snapshot); if (point == null) return; // get syntax tree SyntaxTree syntaxTree = snapshot.GetSyntaxTree(); var root = syntaxTree.Root as RobotsTxtDocumentSyntax; // find line in syntax tree ITextSnapshotLine line = point.Value.GetContainingLine(); RobotsTxtLineSyntax lineSyntax = root.Records.SelectMany(r => r.Lines) .Where(l => !l.NameToken.IsMissing && !l.DelimiterToken.IsMissing) .FirstOrDefault(l => l.Span.IntersectsWith(line.Extent)); // found if (lineSyntax != null) { if (lineSyntax.DelimiterToken.Span.Span.End <= point.Value) { // get semantic model ISemanticModel model = syntaxTree.GetSemanticModel(); // add signature signatures.Add(new RobotsTxtSignature(model, lineSyntax)); } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); Span span; if (session.Properties.ContainsProperty("span")) { span = session.Properties.GetProperty <Span>("span"); } else { span = new Span(position + 1, 1); } ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward); if (session.Properties.ContainsProperty("word")) { string word = session.Properties.GetProperty <string>("word"); if (nodeprovider.Funcs != null) { foreach (var func in nodeprovider.Funcs) { if (StringComparer.InvariantCultureIgnoreCase.Equals(word, func.Name)) { signatures.Add(CreateSignature(m_textBuffer, func.ToString(), func.Description, applicableToSpan)); } } } if (nodeprovider.Triggers != null) { foreach (var func in nodeprovider.Triggers) { if (StringComparer.InvariantCultureIgnoreCase.Equals(word, func.Name)) { signatures.Add(CreateSignature(m_textBuffer, func.ToString(), string.Empty, applicableToSpan)); } } } if (nodeprovider.CoreFuncs != null) { foreach (var func in nodeprovider.CoreFuncs) { if (StringComparer.InvariantCultureIgnoreCase.Equals(word, func.Name)) { signatures.Add(CreateSignature(m_textBuffer, func.ToString(), func.Description, applicableToSpan)); } } } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { var snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); var applicableToSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); // Add to signatures list using CreateSignature() method here signatures.Add(CreateSignature(_textBuffer, "add(int firstInt, int secondInt)", "Documentation", applicableToSpan)); }
/// <summary> /// The augment signature help session. /// </summary> /// <param name="session"> /// The session. /// </param> /// <param name="signatures"> /// The signatures. /// </param> public void AugmentSignatureHelpSession([NotNull] ISignatureHelpSession session, IList <ISignature> signatures) { var point = session.GetTriggerPoint(this.textBuffer).GetPoint(this.textBuffer.CurrentSnapshot); var functionName = this.provider.NavigatorService.GetTextStructureNavigator(this.textBuffer).GetExtentOfWord(point - 1).Span.GetText(); var applicableToSpan = this.textBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(point, 0), SpanTrackingMode.EdgeInclusive, 0); foreach (var function in this.provider.DocumentProvider.GetDocument(this.textBuffer).GetFunctionsByName(functionName).ToArray()) { signatures.Add(new Signature(this.textBuffer, function, applicableToSpan)); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot currentSnapshot = _textBuffer.CurrentSnapshot; int currentPosition = session.GetTriggerPoint(_textBuffer).GetPosition(currentSnapshot); ITrackingSpan currentApplicableSpan = currentSnapshot.CreateTrackingSpan(new Span(currentPosition, 0), SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward); signatures.Add(CreateSignature(_textBuffer, "<content name=\"namedContentArea\" />", "Spools all output in the content element into a named text writer", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<content var=\"variable\" />", "Spools all output into a temporary text writer", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<content def=\"variable\" />", "Spools all output into a temporary text writer (same as 'var')", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<default x=\"xValue\" y=\"yValue\" />", "Declares local variables if a symbol of a given name is not known to be in scope", currentApplicableSpan)); }
//</Snippet17> //<Snippet18> public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); signatures.Add(CreateSignature(m_textBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan)); signatures.Add(CreateSignature(m_textBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan)); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { ITextSnapshot currentSnapshot = _textBuffer.CurrentSnapshot; int currentPosition = session.GetTriggerPoint(_textBuffer).GetPosition(currentSnapshot); ITrackingSpan currentApplicableSpan = currentSnapshot.CreateTrackingSpan(new Span(currentPosition, 0), SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward); signatures.Add(CreateSignature(_textBuffer, "<content name=\"namedContentArea\" />", "Spools all output in the content element into a named text writer", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<content var=\"variable\" />", "Spools all output into a temporary text writer", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<content def=\"variable\" />", "Spools all output into a temporary text writer (same as 'var')", currentApplicableSpan)); signatures.Add(CreateSignature(_textBuffer, "<default x=\"xValue\" y=\"yValue\" />", "Declares local variables if a symbol of a given name is not known to be in scope", currentApplicableSpan)); }
public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures, AstRoot ast, Action <object, string> triggerSession, string packageName) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); // Retrieve parameter positions from the current text buffer snapshot ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); if (parametersInfo != null) { position = Math.Min(parametersInfo.SignatureEnd, position); int start = Math.Min(position, snapshot.Length); int end = Math.Min(parametersInfo.SignatureEnd, snapshot.Length); ITrackingSpan applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive); IFunctionInfo functionInfo = null; // First try user-defined function if (string.IsNullOrEmpty(parametersInfo.PackageName)) { functionInfo = ast.GetUserFunctionInfo(parametersInfo.FunctionName, position); } else { packageName = parametersInfo.PackageName; } if (functionInfo == null) { var functionIndex = _shell.ExportProvider.GetExportedValue <IFunctionIndex>(); // Then try package functions packageName = packageName ?? _packageName; _packageName = null; // Get collection of function signatures from documentation (parsed RD file) functionInfo = functionIndex.GetFunctionInfo(parametersInfo.FunctionName, packageName, triggerSession, session); } if (functionInfo != null && functionInfo.Signatures != null) { foreach (ISignatureInfo signatureInfo in functionInfo.Signatures) { ISignature signature = CreateSignature(session, parametersInfo.FunctionName, functionInfo, signatureInfo, applicableToSpan, ast, position); signatures.Add(signature); } session.Properties["functionInfo"] = functionInfo; return(true); } } return(false); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = this.textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(this.textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = this.textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); SnapshotPoint?sp = session.GetTriggerPoint(snapshot); if (!sp.HasValue) { return; } string word = navigator.GetExtentOfWord(sp.Value - 1).Span.GetText().Trim(); ShaderlabDataManager.Instance.HLSLCGFunctions.ForEach(f => { foreach (var item in f.Synopsis) { if (f.Name.Equals(word)) { signatures.Add(CreateSignature(this.textBuffer, item, f.Description, applicableToSpan)); } } }); ShaderlabDataManager.Instance.UnityBuiltinFunctions.ForEach(f => { foreach (var item in f.Synopsis) { if (f.Name.Equals(word)) { signatures.Add(CreateSignature(this.textBuffer, item, f.Description, applicableToSpan)); } } }); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } CssEditorDocument document = CssEditorDocument.FromTextBuffer(_buffer); ParseItem item = document.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null) { return; } Declaration dec = item.FindType <Declaration>(); if (dec == null || dec.PropertyName == null || dec.Colon == null) { return; } int length = dec.Length - (dec.Colon.Start - dec.Start); var span = _buffer.CurrentSnapshot.CreateTrackingSpan(dec.Colon.Start, length, SpanTrackingMode.EdgeNegative); ValueOrderFactory.AddSignatures method = ValueOrderFactory.GetMethod(dec); if (method != null) { signatures.Clear(); method(session, signatures, dec, span); Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => { if (session == null || session.Properties == null) { return; } session.Properties.AddProperty("dec", dec); session.Match(); }), DispatcherPriority.Normal, null); } }
public List <ClassificationSpan> GetReplacementSpans(ISignatureHelpSession session) { ITextSnapshot snapshot = this.textBuffer.CurrentSnapshot; int currentVersion = snapshot.Version.VersionNumber; SnapshotPoint currentPoint = session.GetTriggerPoint(snapshot).Value; if (replacementSpansVersion != currentVersion || replacementSpansPoint != currentPoint) { // TODO: detect when the current point is within the spans and re-use? this.replacementSpans = this.GetReplacementSpans(currentPoint); this.replacementSpansVersion = currentVersion; this.replacementSpansPoint = currentPoint; } return(this.replacementSpans); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ThreadHelper.ThrowIfNotOnUIThread(); var snapshot = _textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(_textBuffer); var snapshotPoint = triggerPoint.GetPoint(snapshot); var position = triggerPoint.GetPosition(snapshot); var applicableToSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward); // Parse the entire document into an AST var index = CXIndex.Create(false, false); if ((_dte.ActiveDocument, snapshot).TryParseDocument(index, out var translationUnit, out _)) { var visitor = new EmplacingVisitor(_dte.ActiveDocument.FullName, snapshotPoint.GetContainingLine().LineNumber); visitor.CtorFound += (templateParameters, parameters) => { // TODO: eliminate this stupid back-and-forth string handling var signatureBuilder = new StringBuilder("emplace"); signatureBuilder.Append('('); foreach (var parameter in parameters) { signatureBuilder.Append(parameter.Type).Append(' ').Append(parameter.Name).Append(", "); } if (parameters.Count > 0) { signatureBuilder.Length -= 2; } signatureBuilder.Append(')'); signatures.Add(CreateSignature(_textBuffer, signatureBuilder.ToString(), applicableToSpan)); }; visitor.Visit(translationUnit); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 1, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession"); //if (true) return; if (!Settings.Default.SignatureHelp_On) { return; } try { DateTime time1 = DateTime.Now; ITextSnapshot snapshot = this._buffer.CurrentSnapshot; int position = session.GetTriggerPoint(this._buffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = this._buffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); ITextSnapshotLine line = snapshot.GetLineFromPosition(position); string lineStr = line.GetText(); //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: lineStr=" + lineStr+ "; positionInLine=" + positionInLine); var t = AsmSourceTools.ParseLine(lineStr); IList <Operand> operands = AsmSourceTools.MakeOperands(t.Args); Mnemonic mnemonic = t.Mnemonic; ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On(); //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: selected architectures=" + ArchTools.ToString(selectedArchitectures)); foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(this._store.GetSignatures(mnemonic), operands, selectedArchitectures)) { signatures.Add(Create_Signature(this._buffer, se, applicableToSpan)); } AsmDudeToolsStatic.Print_Speed_Warning(time1, "Signature Help"); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:AugmentSignatureHelpSession; e={1}", ToString(), e.ToString())); } }
public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures, AstRoot ast, Action<object, string> triggerSession) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); // Retrieve parameter positions from the current text buffer snapshot ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); if (parametersInfo != null) { position = Math.Min(parametersInfo.SignatureEnd, position); int start = Math.Min(position, snapshot.Length); int end = Math.Min(parametersInfo.SignatureEnd, snapshot.Length); ITrackingSpan applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive); IFunctionInfo functionInfo = null; // First try user-defined function functionInfo = ast.GetUserFunctionInfo(parametersInfo.FunctionName, position); if (functionInfo == null) { var functionIndex = _shell.ExportProvider.GetExportedValue<IFunctionIndex>(); // Then try package functions var packageName = _packageName; _packageName = null; // Get collection of function signatures from documentation (parsed RD file) functionInfo = functionIndex.GetFunctionInfo(parametersInfo.FunctionName, packageName, triggerSession, session); } if (functionInfo != null && functionInfo.Signatures != null) { foreach (ISignatureInfo signatureInfo in functionInfo.Signatures) { ISignature signature = CreateSignature(session, parametersInfo.FunctionName, functionInfo, signatureInfo, applicableToSpan, ast, position); signatures.Add(signature); } session.Properties["functionInfo"] = functionInfo; return true; } } return false; }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ThreadHelper.ThrowIfNotOnUIThread(); var snapshot = _textBuffer.CurrentSnapshot; _triggerPos = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); if (ProbeSignatureHelpCommandHandler.s_typedChar == '(') { foreach (var sig in HandleOpenBracket(snapshot, ProbeEnvironment.CurrentAppSettings)) { signatures.Add(sig); } } else if (ProbeSignatureHelpCommandHandler.s_typedChar == ',') { foreach (var sig in HandleComma(snapshot, ProbeEnvironment.CurrentAppSettings)) { signatures.Add(sig); } } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { if (!session.TextView.Properties.ContainsProperty(SessionKey)) { return; } // At the moment there is a bug in the javascript provider which causes it to // repeatedly insert the same Signature values into an ISignatureHelpSession // instance. There is no way, other than reflection, for us to prevent this // from happening. Instead we just ensure that our provider runs after // Javascript and then remove the values they add here signatures.Clear(); // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); if (encouragement != null) { var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { try { Debug("XSharpSignatureHelpSource.AugmentSignatureHelpSession()"); m_session = session; XSharpModel.ModelWalker.Suspend(); ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; XSharpSignatureProperties props; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); session.Properties.TryGetProperty(typeof(XSharpSignatureProperties), out props); m_applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(props.Start, props.Length), SpanTrackingMode.EdgeInclusive, 0); object elt = props.Element; if (elt is IXSymbol) { IXMemberSymbol element = elt as IXMemberSymbol; // if (elt is IXMemberSymbol xMember) { var names = new List <string>(); var proto = getProto(xMember, props); names.Add(proto); signatures.Add(CreateSignature(m_textBuffer, xMember, proto, ApplicableToSpan, xMember.Kind == XSharpModel.Kind.Constructor, m_file)); var overloads = xMember.GetOverloads(); foreach (var member in overloads) { if (member.Visibility < props.Visibility) { continue; } // prevent duplicate prototypes in the list (when a child has overriden a method) proto = getProto(member, props); if (!names.Contains(proto)) { signatures.Add(CreateSignature(m_textBuffer, member, proto, ApplicableToSpan, member.Kind == XSharpModel.Kind.Constructor, m_file)); names.Add(proto); } } } else if (element != null) { // Type ?? signatures.Add(CreateSignature(m_textBuffer, null, element.Prototype, ApplicableToSpan, false, m_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.LogException(ex, "XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed "); } finally { XSharpModel.ModelWalker.Resume(); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { ITextSnapshot snapshot = this.textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(this.textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = this.textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); SnapshotPoint? sp = session.GetTriggerPoint(snapshot); if (!sp.HasValue) { return; } string word = navigator.GetExtentOfWord(sp.Value - 1).Span.GetText().Trim(); ShaderlabDataManager.Instance.HLSLCGFunctions.ForEach(f => { foreach (var item in f.Synopsis) { if (f.Name.Equals(word)) { signatures.Add(CreateSignature(this.textBuffer, item, f.Description, applicableToSpan)); } } }); ShaderlabDataManager.Instance.UnityBuiltinFunctions.ForEach(f => { foreach (var item in f.Synopsis) { if (f.Name.Equals(word)) { signatures.Add(CreateSignature(this.textBuffer, item, f.Description, applicableToSpan)); } } }); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ContractsPackageAccessor.Current.Logger.PublicEntry(() => { //Record our start time for preformance considerations var startTime = DateTime.Now; //Do we have signatures? if (signatures == null || signatures.Count < 1) { return; } //Do we have a well-formed session? if (session == null || session.TextView == null || session.TextView.TextBuffer == null) { return; } //Can we get our trigger point? var triggerPoint = session.GetTriggerPoint(_textBuffer); if (triggerPoint == null) { return; } //Can we get our snapshot? var workingSnapshot = _textBuffer.CurrentSnapshot; if (workingSnapshot == null) { return; } //Can we get our SourceFile? var sourceFile = _textViewTracker.LatestSourceFile; if (sourceFile == null) { return; } //Can we get our ParseTree? var parseTree = sourceFile.GetParseTree(); if (parseTree == null) { return; } //Can we get our compilation? var comp = _textViewTracker.LatestCompilation; if (comp == null) { return; } //Is the model ready? if (!parseTree.IsModelReady() || _textViewTracker.IsLatestCompilationStale || _textViewTracker.IsLatestSourceFileStale) { //Ask for a new model ContractsPackageAccessor.Current.AskForNewVSModel(_textBuffer); //Return a message saying we aren't ready yet ContractsPackageAccessor.Current.Logger.WriteToLog("The VS model is out of date! Aborting contract lookup."); return;//"(VS isn't ready for possible contract lookup yet. Please try again in a few seconds.)"; } string[] contractContents = null; //Proceed cautiously try { //Can we get a call node? var callNode = IntellisenseContractsHelper.GetAnyCallNodeAboveTriggerPoint(triggerPoint, workingSnapshot, parseTree); if (callNode == null || comp == null || sourceFile == null) { return; } //Can we get our semantic member? var semanticMember = IntellisenseContractsHelper.GetSemanticMember(callNode, comp, sourceFile); if (semanticMember == null) { return; } var declType = semanticMember.ContainingType; // find all members of the same name (virt/non-virt) var overloads = GetSignatureOverloads(declType, signatures, semanticMember); contractContents = GetContractsForOverloads(overloads); //Give up on our contracts if we get an exception } catch (IllFormedSemanticModelException) { return; } catch (InvalidOperationException e) { if (!e.Message.Contains(ContractsPackageAccessor.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate)) { throw e; } else { this._textViewTracker.IsLatestCompilationStale = true; return; } } catch (System.Runtime.InteropServices.COMException) { // various reasons for COMException // - binding failed // - project unavailable // - ... return; } //Enumerate the signatures and append our custom content for (int i = 0; i < signatures.Count; i++) { var sig = signatures[i]; if (contractContents != null && !String.IsNullOrEmpty(contractContents[i])) { signatures[i] = new SignatureWithContracts(sig, contractContents[i]); } } //Print our elapsed time for preformance considerations var elapseTime = DateTime.Now - startTime; ContractsPackageAccessor.Current.Logger.WriteToLog("Time to compute quickinfo: " + elapseTime.Milliseconds + "ms"); }, "AugmentSignatureHelpSession"); }
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) { package.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed "); package.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); //First try to get a compilable source code snapshot = snapshot.TextBuffer.Insert(position, "();"); Span spanToRemove = new Span(position, 3); //StaDynParser parser = new StaDynParser(snapshot.TextBuffer, FileUtilities.Instance.getCurrentOpenDocumentFilePath()); ////Parse source //StaDynSourceFileAST parseResult = parser.parseSource(); //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult); StaDynParser parser = new StaDynParser(); parser.parseAll(); StaDynSourceFileAST parseResult = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (parseResult == null || parseResult.Ast == null) { snapshot = snapshot.TextBuffer.Delete(spanToRemove); return; } System.Drawing.Point caretPosition = FileUtilities.Instance.getCurrentCaretPoint(); int column = caretPosition.Y; int line = caretPosition.X + 1; //AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column)); AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(parseResult.FileName, line, column)); //Signature help is not needed on method definition if (foundNode is MethodDefinition) { snapshot = snapshot.TextBuffer.Delete(spanToRemove); return; } AstNode lastInvocationNode = StaDynIntellisenseHelper.Instance.getCurrentInvocation(parseResult, snapshot, position, line, column); //StaDynSourceFileAST file = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); //if (file.Ast == null) return ; //AstNode foundNode = (AstNode)file.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(file.FileName), line, column)); //Remove added chars snapshot = snapshot.TextBuffer.Delete(spanToRemove); if (lastInvocationNode == null) { return; } this.createSignatures(lastInvocationNode, m_textBuffer, applicableToSpan, signatures); /*****************************************/ //signatures.Add(CreateSignature(m_textBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan)); //signatures.Add(CreateSignature(m_textBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan)); }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { Snapshot snapshot = this.source.CurrentSnapshot; SyntaxTree tree = this.source.Tree; int triggerPosition = session.GetTriggerPoint(snapshot.ToITextSnapshot()).Value.Position; SyntaxNode node = tree?.GetNodeFromPosition(snapshot, triggerPosition); IdentifierSyntax identifier = node as IdentifierSyntax; if (identifier?.Definition?.Kind != DefinitionKind.Function) { FunctionCallSyntax functionCall = null; foreach (SyntaxNode decendent in node.DescendantsAndSelf) { if (decendent.SyntaxType == SyntaxType.FunctionCall) { functionCall = decendent as FunctionCallSyntax; break; } } if (functionCall == null) { foreach (SyntaxNode ancestor in node.AncestorsAndSelf) { if (ancestor.SyntaxType == SyntaxType.FunctionCall) { functionCall = ancestor as FunctionCallSyntax; break; } } } if (functionCall?.Identifier?.Definition != null && functionCall.Span.GetSpan(snapshot).Contains(triggerPosition)) { TrackingSpan span = null; if (functionCall.RightParentheses == null) { SourceLine line = snapshot.GetLineFromPosition(functionCall.Span.GetSpan(snapshot).Start); span = snapshot.CreateTrackingSpan(Span.Create(functionCall.Span.GetSpan(snapshot).Start, line.Span.End)); } else { span = functionCall.Span; } for (int i = 0; i < functionCall.Identifier.Definition.Overloads.Count; i++) { signatures.Add(new GLSLSignature(functionCall.Identifier.Definition.Overloads[i], span, snapshot, session.TextView, session)); } } } else if (identifier?.Definition != null) { TrackingSpan span = null; if (node?.Parent.SyntaxType == SyntaxType.FunctionCall) { span = node.Parent.Span; } else { span = node.Span; } for (int i = 0; i < identifier.Definition.Overloads.Count; i++) { signatures.Add(new GLSLSignature(identifier.Definition.Overloads[i], span, snapshot, session.TextView, session)); } if (BuiltInData.Instance.Definitions.ContainsKey(identifier.Definition.Name.Text)) { for (int i = 0; i < BuiltInData.Instance.Definitions[identifier.Definition.Name.Text].Count; i++) { signatures.Add(new GLSLSignature(BuiltInData.Instance.Definitions[identifier.Definition.Name.Text][i], span, snapshot, session.TextView, session)); } } } }
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 AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { //if (!session.TextView.Properties.ContainsProperty(SessionKey)) { // return; //} NSUtil.DebugPrintAlways("NSSig - AugmentSignatureHelpSession"); if (NSPackage.nimsuggest == null) { return; } signatures.Clear(); var caretpos = NSLangServ.CaretPosGet(); NSPackage.nimsuggest.Query(NimSuggestProc.Qtype.con, caretpos["line"], caretpos["col"]); SnapshotPoint?point_trigger = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!point_trigger.HasValue) { return; } //ITextSnapshot snapshot = subjectBuffer.CurrentSnapshot; //int position = session.GetTriggerPoint(subjectBuffer).GetPosition(subjectBuffer.CurrentSnapshot); int position = point_trigger.Value.Position; string text = subjectBuffer.CurrentSnapshot.GetText(); SnapshotPoint point_curr = session.GetTriggerPoint(subjectBuffer).GetPoint(subjectBuffer.CurrentSnapshot); point_curr = point_trigger.Value; SnapshotPoint point_left = point_curr; SnapshotPoint point_right = point_curr; ITextSnapshotLine line = point_left.GetContainingLine(); string terms = "\n\r\t.:()[]{}?/+-;=*!<>"; while (true) { point_left -= 1; if (point_left <= line.Start) { point_left = line.Start; break; } if (terms.IndexOf(point_left.GetChar()) != -1) { point_left += 1; break; } } while (true) { if (point_right >= line.End) { point_right = line.End; break; } if (terms.IndexOf(point_right.GetChar()) != -1) { point_right -= 1; break; } point_right += 1; } if (point_left > point_right) { point_right = point_left; } ITrackingSpan applicable_to_span = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(point_left, point_right - point_left, SpanTrackingMode.EdgeInclusive); //ITrackingSpan applicableToSpan = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); string sig_help_default = ""; foreach (string skey in NSPackage.nimsuggest.sugdct.Keys) { var sigdct = NSPackage.nimsuggest.sugdct[skey]; if (sigdct["help"].Length > sig_help_default.Length) { sig_help_default = sigdct["help"]; } } foreach (string skey in NSPackage.nimsuggest.sugdct.Keys) { var sigdct = NSPackage.nimsuggest.sugdct[skey]; //SortedDictionary<string,string> signatures.Add(SigAdd(subjectBuffer, skey, sigdct, sig_help_default, applicable_to_span, session)); } //var currentSnapshot = subjectTriggerPoint.Value.Snapshot; //var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); //var applicableToSpan = currentSnapshot.CreateTrackingSpan(querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); //signatures.Add(CreateSignature(subjectBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan)); //signatures.Add(CreateSignature(subjectBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan)); //string sighelp = "hey1"; //if (sighelp != null) { //} }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { VSServiceProvider.Current.Logger.PublicEntry(() => { //Record our start time for preformance considerations var startTime = DateTime.Now; //Do we have signatures? if (signatures == null || signatures.Count < 1) return; //Do we have a well-formed session? if (session == null || session.TextView == null || session.TextView.TextBuffer == null) return; //Can we get our trigger point? var triggerPoint = session.GetTriggerPoint(_textBuffer); if (triggerPoint == null) return; //Can we get our snapshot? var workingSnapshot = _textBuffer.CurrentSnapshot; if (workingSnapshot == null) return; //Can we get our SourceFile? var sourceFile = _textViewTracker.LatestSourceFile; if (sourceFile == null) return; //Can we get our ParseTree? var parseTree = sourceFile.GetParseTree(); if (parseTree == null) return; //Can we get our compilation? var comp = _textViewTracker.LatestCompilation; if (comp == null) return; //Is the model ready? if (!VSServiceProvider.IsModelReady(parseTree) || _textViewTracker.IsLatestCompilationStale || _textViewTracker.IsLatestSourceFileStale) { //Ask for a new model VSServiceProvider.Current.AskForNewVSModel(); //Return a message saying we aren't ready yet VSServiceProvider.Current.Logger.WriteToLog("The VS model is out of date! Aborting contract lookup."); return;//"(VS isn't ready for possible contract lookup yet. Please try again in a few seconds.)"; } string[] contractContents = null; //Proceed cautiously try { //Can we get a call node? var callNode = IntellisenseContractsHelper.GetAnyCallNodeAboveTriggerPoint(triggerPoint, workingSnapshot, parseTree); if (callNode == null || comp == null || sourceFile == null) return; //Can we get our semantic member? var semanticMember = IntellisenseContractsHelper.GetSemanticMember(callNode, comp, sourceFile); if (semanticMember == null) return; var declType = semanticMember.ContainingType; // find all members of the same name (virt/non-virt) var overloads = GetSignatureOverloads(declType, signatures, semanticMember); contractContents = GetContractsForOverloads(overloads); //Give up on our contracts if we get an exception } catch (IllFormedSemanticModelException) { return; } catch (InvalidOperationException e) { if (!e.Message.Contains(VSServiceProvider.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate)) throw e; else { this._textViewTracker.IsLatestCompilationStale = true; return; } } catch (System.Runtime.InteropServices.COMException) { // various reasons for COMException // - binding failed // - project unavailable // - ... return; } //Enumerate the signatures and append our custom content for (int i = 0; i < signatures.Count; i++) { var sig = signatures[i]; if (contractContents != null && !String.IsNullOrEmpty(contractContents[i])) { signatures[i] = new SignatureWithContracts(sig, contractContents[i]); } } //Print our elapsed time for preformance considerations var elapseTime = DateTime.Now - startTime; VSServiceProvider.Current.Logger.WriteToLog("Time to compute quickinfo: " + elapseTime.Milliseconds + "ms"); }, "AugmentSignatureHelpSession"); }