public static CodeCompletionResult FromICompletionDataToFileCodeCompletionResult(this ICompletionData completionData) { CodeCompletionResult result = new CodeCompletionResult(); // Set Defaults result.CompletionText = completionData.CompletionText; result.DisplayText = completionData.DisplayText; result.Description = completionData.Description; //result.MemberDeclaringType = ""; //result.MemberDeclaredResultType = ""; CodeCompletionDataFactory.CompletionData cd = (CodeCompletionDataFactory.CompletionData) completionData; // Extract and capture the summary from the XML documentation for the option // We shouldn't be surprised that in many cases this will be empty. var xmlDoc = new XmlDocumentationModel(cd.Documentation); result.Summary = xmlDoc.Summary; result.DeclarationCategory = cd.DeclarationCategory; bool boringDescription = string.IsNullOrWhiteSpace(result.Description) || result.Description == result.CompletionText; // For EntityCompletionData, if the entity is an IMember, NRefactory sets the CompletionCategory's DisplayText to the name of the class (i.e. member.DeclaringTypeDefinintion.Name) //if (completionData.CompletionCategory != null) // result.MemberDeclaringType = completionData.CompletionCategory.DisplayText; // Let's see if we can reproduce... var entity = cd as CodeCompletionDataFactory.EntityCompletionData; if (entity != null) { var member = entity.Entity as IMember; if (member != null) { var memberInfo = new CodeCompletionMemberOfTypeResult(); result.MemberInformation = memberInfo; memberInfo.FullName = member.FullName; memberInfo.DeclaringType = member.DeclaringTypeDefinition.FullName; memberInfo.DeclaredResultType = member.MemberDefinition.ReturnType.FullName; memberInfo.OverloadCount = completionData.OverloadedData.Count(); if (boringDescription) { result.Description = string.Format("{0} {1} {2}\r\n{3} {4}", result.DeclarationCategoryName, memberInfo.DeclaredResultType, memberInfo.FullName, result.Summary, (memberInfo.OverloadCount == 0 ? "" : " (" + memberInfo.OverloadCount + " overloads) ")); } } else { result.Description = string.Format("{0} \r\n{1}", result.DeclarationCategoryName, result.Summary); } } var ns = cd as CodeCompletionDataFactory.NamespaceCompletionData; if (ns != null) { result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, ns.Namespace.FullName); } var variable = cd as CodeCompletionDataFactory.VariableCompletionData; if (variable != null) { result.Description = string.Format("{0} {1} {2}", result.DeclarationCategoryName, variable.Variable.Type.FullName, variable.Variable.Name); } var literal = cd as CodeCompletionDataFactory.LiteralCompletionData; if (literal != null) { if (literal.Description == literal.DisplayText) result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, literal.DisplayText); else result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, literal.DisplayText, literal.Description); } var enumMember = cd as CodeCompletionDataFactory.MemberCompletionData; if (enumMember != null) { result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, enumMember.DisplayText); } var typeCompletion = cd as CodeCompletionDataFactory.TypeCompletionData; if (typeCompletion!= null) { result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, typeCompletion.Type.FullName, result.Summary); } var typeParameter = cd as CodeCompletionDataFactory.TypeParameterCompletionData; if (typeParameter != null) { var owner = typeParameter.TypeParameter.Owner; if (owner != null) { var ownerXmlDoc = new XmlDocumentationModel(owner.Documentation); result.Summary = ownerXmlDoc.GetTypeParameterDescription(typeParameter.TypeParameter.Name); } result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, typeParameter.TypeParameter.FullName, result.Summary); } result.Description = result.Description.TrimEnd('\n', '\r'); return result; }
public static CodeCompletionResult FromICompletionDataToFileCodeCompletionResult(this ICompletionData completionData) { CodeCompletionResult result = new CodeCompletionResult(); // Set Defaults result.CompletionText = completionData.CompletionText; result.DisplayText = completionData.DisplayText; result.Description = completionData.Description; //result.MemberDeclaringType = ""; //result.MemberDeclaredResultType = ""; CodeCompletionDataFactory.CompletionData cd = (CodeCompletionDataFactory.CompletionData)completionData; // Extract and capture the summary from the XML documentation for the option // We shouldn't be surprised that in many cases this will be empty. var xmlDoc = new XmlDocumentationModel(cd.Documentation); result.Summary = xmlDoc.Summary; result.DeclarationCategory = cd.DeclarationCategory; bool boringDescription = string.IsNullOrWhiteSpace(result.Description) || result.Description == result.CompletionText; // For EntityCompletionData, if the entity is an IMember, NRefactory sets the CompletionCategory's DisplayText to the name of the class (i.e. member.DeclaringTypeDefinintion.Name) //if (completionData.CompletionCategory != null) // result.MemberDeclaringType = completionData.CompletionCategory.DisplayText; // Let's see if we can reproduce... var entity = cd as CodeCompletionDataFactory.EntityCompletionData; if (entity != null) { var member = entity.Entity as IMember; if (member != null) { var memberInfo = new CodeCompletionMemberOfTypeResult(); result.MemberInformation = memberInfo; memberInfo.FullName = member.FullName; memberInfo.DeclaringType = member.DeclaringTypeDefinition.FullName; memberInfo.DeclaredResultType = member.MemberDefinition.ReturnType.FullName; memberInfo.OverloadCount = completionData.OverloadedData.Count(); if (boringDescription) { result.Description = string.Format("{0} {1} {2}\r\n{3} {4}", result.DeclarationCategoryName, memberInfo.DeclaredResultType, memberInfo.FullName, result.Summary, (memberInfo.OverloadCount == 0 ? "" : " (" + memberInfo.OverloadCount + " overloads) ")); } } else { result.Description = string.Format("{0} \r\n{1}", result.DeclarationCategoryName, result.Summary); } } var ns = cd as CodeCompletionDataFactory.NamespaceCompletionData; if (ns != null) { result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, ns.Namespace.FullName); } var variable = cd as CodeCompletionDataFactory.VariableCompletionData; if (variable != null) { result.Description = string.Format("{0} {1} {2}", result.DeclarationCategoryName, variable.Variable.Type.FullName, variable.Variable.Name); } var literal = cd as CodeCompletionDataFactory.LiteralCompletionData; if (literal != null) { if (literal.Description == literal.DisplayText) { result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, literal.DisplayText); } else { result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, literal.DisplayText, literal.Description); } } var enumMember = cd as CodeCompletionDataFactory.MemberCompletionData; if (enumMember != null) { result.Description = string.Format("{0} {1}", result.DeclarationCategoryName, enumMember.DisplayText); } var typeCompletion = cd as CodeCompletionDataFactory.TypeCompletionData; if (typeCompletion != null) { result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, typeCompletion.Type.FullName, result.Summary); } var typeParameter = cd as CodeCompletionDataFactory.TypeParameterCompletionData; if (typeParameter != null) { var owner = typeParameter.TypeParameter.Owner; if (owner != null) { var ownerXmlDoc = new XmlDocumentationModel(owner.Documentation); result.Summary = ownerXmlDoc.GetTypeParameterDescription(typeParameter.TypeParameter.Name); } result.Description = string.Format("{0} {1}\r\n{2}", result.DeclarationCategoryName, typeParameter.TypeParameter.FullName, result.Summary); } result.Description = result.Description.TrimEnd('\n', '\r'); return(result); }