I am trying to explore Roslyn's code completion service. I am able to get the completion list, but when I try to get the description it only returns the type and access modifiers, but not the actual description (e.g. Function used for printing to the console).
This is how I tried getting the description:
var code = @"using System;
using TestDll;
public class MyClass
{
public static void MyMethod(int value)
{
Test.
}
}";
var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "MyProject", "MyProject", LanguageNames.CSharp).
WithMetadataReferences(new[] { MetadataReference.CreateFromFile("TestDll.dll", documentation: XmlDocumentationProvider.CreateFromFile("TestDLL.xml")) });
var project = workspace.AddProject(projectInfo);
var document = workspace.AddDocument(project.Id, "MyFile.cs", SourceText.From(code));
await PrintCompletionResults(document, code.LastIndexOf("Test.") + 5);
PrintCompletion Method
private static async Task PrintCompletionResults(Document document, int position)
{
var completionService = CompletionService.GetService(document);
var results = await completionService.GetCompletionsAsync(document, position);
foreach (var i in results.Items)
{
Console.WriteLine(i.DisplayText);
var desc = completionService.GetDescriptionAsync(document, i).Result; // returns for example "interface Test.DebugPrint()"
Console.WriteLine(desc.Text);
foreach (var prop in i.Properties)
{
Console.Write($"{prop.Key}:{prop.Value} ");
}
Console.WriteLine();
foreach (var tag in i.Tags)
{
Console.Write($"{tag} ");
}
Console.WriteLine();
Console.WriteLine();
}
}