// static bool ContainsPublicConstructors (ITypeDefinition t) // { // if (t.Methods.Count (m => m.IsConstructor) == 0) // return true; // return t.Methods.Any (m => m.IsConstructor && m.IsPublic); // } // CompletionDataList result = new ProjectDomCompletionDataList (); // // "var o = new " needs special treatment. // if (returnType == null && returnTypeUnresolved != null && returnTypeUnresolved.FullName == "var") // returnType = returnTypeUnresolved = DomReturnType.Object; // // // ExpressionContext.TypeExpressionContext tce = context as ExpressionContext.TypeExpressionContext; // // CompletionDataCollector col = new CompletionDataCollector (this, dom, result, Document.CompilationUnit, callingType, location); // IType type = null; // if (returnType != null) // type = dom.GetType (returnType); // if (type == null) // type = dom.SearchType (Document.CompilationUnit, callingType, location, returnTypeUnresolved); // // // special handling for nullable types: Bug 674516 - new completion for nullables should not include "Nullable" // if (type is InstantiatedType && ((InstantiatedType)type).UninstantiatedType.FullName == "System.Nullable" && ((InstantiatedType)type).GenericParameters.Count == 1) { // var genericParameter = ((InstantiatedType)type).GenericParameters [0]; // returnType = returnTypeUnresolved = Document.CompilationUnit.ShortenTypeName (genericParameter, location); // type = dom.SearchType (Document.CompilationUnit, callingType, location, genericParameter); // } // // if (type == null || !(type.IsAbstract || type.ClassType == ClassType.Interface)) { // if (type == null || type.ConstructorCount == 0 || type.Methods.Any (c => c.IsConstructor && c.IsAccessibleFrom (dom, callingType, type, callingType != null && dom.GetInheritanceTree (callingType).Any (x => x.FullName == type.FullName)))) { // if (returnTypeUnresolved != null) { // col.FullyQualify = true; // CompletionData unresovedCompletionData = col.Add (returnTypeUnresolved); // col.FullyQualify = false; // // don't set default completion string for arrays, since it interferes with: // // string[] arr = new string[] vs new { "a"} // if (returnTypeUnresolved.ArrayDimensions == 0) // result.DefaultCompletionString = StripGenerics (unresovedCompletionData.CompletionText); // } else { // CompletionData unresovedCompletionData = col.Add (returnType); // if (returnType.ArrayDimensions == 0) // result.DefaultCompletionString = StripGenerics (unresovedCompletionData.CompletionText); // } // } // } // // // if (tce != null && tce.Type != null) { // // result.DefaultCompletionString = StripGenerics (col.AddCompletionData (result, tce.Type).CompletionString); // // } // // else { // // } // if (type == null) // return result; // HashSet<string > usedNamespaces = new HashSet<string> (GetUsedNamespaces ()); // if (type.FullName == DomReturnType.Object.FullName) // AddPrimitiveTypes (col); // // foreach (IType curType in dom.GetSubclasses (type)) { // if (context != null && context.FilterEntry (curType)) // continue; // if ((curType.TypeModifier & TypeModifier.HasOnlyHiddenConstructors) == TypeModifier.HasOnlyHiddenConstructors) // continue; // if (usedNamespaces.Contains (curType.Namespace)) { // if (curType.ConstructorCount > 0) { // if (!(curType.Methods.Any (c => c.IsConstructor && c.IsAccessibleFrom (dom, curType, callingType, callingType != null && dom.GetInheritanceTree (callingType).Any (x => x.FullName == curType.FullName))))) // continue; // } // col.Add (curType); // } else { // string nsName = curType.Namespace; // int idx = nsName.IndexOf ('.'); // if (idx >= 0) // nsName = nsName.Substring (0, idx); // col.Add (new Namespace (nsName)); // } // } // // // add aliases // if (returnType != null) { // foreach (IUsing u in Document.CompilationUnit.Usings) { // foreach (KeyValuePair<string, IReturnType> alias in u.Aliases) { // if (alias.Value.ToInvariantString () == returnType.ToInvariantString ()) // result.Add (alias.Key, "md-class"); // } // } // } // // return result; // } // IEnumerable<ICompletionData> GetDefineCompletionData () // { // if (Document.Project == null) // yield break; // // var symbols = new Dictionary<string, string> (); // var cp = new ProjectDomCompletionDataList (); // foreach (DotNetProjectConfiguration conf in Document.Project.Configurations) { // var cparams = conf.CompilationParameters as CSharpCompilerParameters; // if (cparams != null) { // string[] syms = cparams.DefineSymbols.Split (';'); // foreach (string s in syms) { // string ss = s.Trim (); // if (ss.Length > 0 && !symbols.ContainsKey (ss)) { // symbols [ss] = ss; // yield return factory.CreateLiteralCompletionData (ss); // } // } // } // } // } public override Task <Ide.CodeCompletion.ParameterHintingResult> ParameterCompletionCommand(CodeCompletionContext completionContext) { if (completionContext == null) { throw new ArgumentNullException(nameof(completionContext)); } char ch = completionContext.TriggerOffset > 0 ? Editor.GetCharAt(completionContext.TriggerOffset - 1) : '\0'; var info = new Ide.Editor.Extension.SignatureHelpTriggerInfo(Ide.Editor.Extension.SignatureHelpTriggerReason.InvokeSignatureHelpCommand, ch); return(InternalHandleParameterCompletionCommand(completionContext, info, default(CancellationToken))); }
public Task <MonoDevelop.Ide.CodeCompletion.ParameterHintingResult> InternalHandleParameterCompletionCommand(CodeCompletionContext completionContext, Ide.Editor.Extension.SignatureHelpTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken)) { var data = Editor; bool force = triggerInfo.TriggerReason != Ide.Editor.Extension.SignatureHelpTriggerReason.InvokeSignatureHelpCommand; ImmutableArray <ISignatureHelpProvider> providers; if (!force) { if (triggerInfo.TriggerReason == Ide.Editor.Extension.SignatureHelpTriggerReason.TypeCharCommand) { providers = signatureProviders.Value.WhereAsArray(provider => provider.IsTriggerCharacter(triggerInfo.TriggerCharacter.Value)); } else if (triggerInfo.TriggerReason == Ide.Editor.Extension.SignatureHelpTriggerReason.RetriggerCommand) { providers = signatureProviders.Value.WhereAsArray(provider => provider.IsRetriggerCharacter(triggerInfo.TriggerCharacter.Value)); } else { providers = signatureProviders.Value; } if (providers.Length == 0) { return(emptyParameterHintingResultTask); } } else { providers = signatureProviders.Value; } if (Editor.EditMode != EditMode.Edit) { return(emptyParameterHintingResultTask); } var offset = Editor.CaretOffset; try { var analysisDocument = DocumentContext.AnalysisDocument; if (analysisDocument == null) { return(emptyParameterHintingResultTask); } var result = new RoslynParameterHintingEngine().GetParameterDataProviderAsync( providers, analysisDocument, offset, triggerInfo.ToRoslyn(), token ); return(result); } catch (Exception e) { LoggingService.LogError("Unexpected parameter completion exception." + Environment.NewLine + "FileName: " + DocumentContext.Name + Environment.NewLine + "Position: line=" + completionContext.TriggerLine + " col=" + completionContext.TriggerLineOffset + Environment.NewLine + "Line text: " + Editor.GetLineText(completionContext.TriggerLine), e); return(emptyParameterHintingResultTask); } }
public override Task <MonoDevelop.Ide.CodeCompletion.ParameterHintingResult> HandleParameterCompletionAsync(CodeCompletionContext completionContext, Ide.Editor.Extension.SignatureHelpTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken)) { return(InternalHandleParameterCompletionCommand(completionContext, triggerInfo, token)); }