public async Task <TypeLookupResponse> Handle(TypeLookupRequest request) { var document = _workspace.GetDocument(request.FileName); var response = new TypeLookupResponse(); if (document != null) { var semanticModel = await document.GetSemanticModelAsync(); var sourceText = await document.GetTextAsync(); var position = sourceText.Lines.GetPosition(new LinePosition(request.Line, request.Column)); var symbol = await SymbolFinder.FindSymbolAtPositionAsync(semanticModel, position, _workspace); if (symbol != null) { //non regular C# code semantics (interactive, script) don't allow namespaces if (document.SourceCodeKind == SourceCodeKind.Regular && symbol.Kind == SymbolKind.NamedType && !symbol.ContainingNamespace.IsGlobalNamespace) { response.Type = $"{symbol.ContainingNamespace.ToDisplayString()}.{symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)}"; } else { response.Type = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); } if (request.IncludeDocumentation) { response.Documentation = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); } } } return(response); }
public async Task <TypeLookupResponse> Handle(TypeLookupRequest request) { var document = _workspace.GetDocument(request.FileName); var response = new TypeLookupResponse(); if (document != null) { var semanticModel = await document.GetSemanticModelAsync(); var sourceText = await document.GetTextAsync(); var position = sourceText.Lines.GetPosition(new LinePosition(request.Line, request.Column)); var symbol = await SymbolFinder.FindSymbolAtPositionAsync(semanticModel, position, _workspace); if (symbol != null) { response.Type = symbol.Kind == SymbolKind.NamedType ? symbol.ToDisplayString(DefaultFormat) : symbol.ToMinimalDisplayString(semanticModel, position); if (request.IncludeDocumentation) { response.Documentation = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); response.StructuredDocumentation = DocumentationConverter.GetStructuredDocumentation(symbol, _formattingOptions.NewLine); } } } return(response); }
public async Task <IActionResult> TypeLookup(TypeLookupRequest request) { var document = _workspace.GetDocument(request.FileName); var response = new TypeLookupResponse(); if (document != null) { var semanticModel = await document.GetSemanticModelAsync(); var sourceText = await document.GetTextAsync(); var position = sourceText.Lines.GetPosition(new LinePosition(request.Line - 1, request.Column - 1)); var symbol = SymbolFinder.FindSymbolAtPosition(semanticModel, position, _workspace); if (symbol != null) { if (symbol.Kind == SymbolKind.NamedType) { response.Type = symbol.ContainingNamespace.ToDisplayString() + "." + symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); } else { response.Type = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); } if (request.IncludeDocumentation) { response.Documentation = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _options.FormattingOptions.NewLine); } } } return(new ObjectResult(response)); }
public void Has_correct_spacing_around_paramref() { var documentation = @" <summary>DoWork is a method in the TestClass class. The <paramref name=""arg""/> parameter takes a number and <paramref name=""arg2""/> takes a string. </summary>"; var plainText = DocumentationConverter.ConvertDocumentation(documentation, "\n"); var expected = @"DoWork is a method in the TestClass class. The arg parameter takes a number and arg2 takes a string."; Assert.Equal(expected, plainText, ignoreLineEndingDifferences: true); }
private AutoCompleteResponse MakeAutoCompleteResponse(AutoCompleteRequest request, ISymbol symbol, string completionText, bool preselect, bool isSuggestionMode, bool includeOptionalParams = true) { var displayNameGenerator = new SnippetGenerator(); displayNameGenerator.IncludeMarkers = false; displayNameGenerator.IncludeOptionalParameters = includeOptionalParams; var response = new AutoCompleteResponse(); response.CompletionText = completionText; // TODO: Do something more intelligent here response.DisplayText = displayNameGenerator.Generate(symbol); response.IsSuggestionMode = isSuggestionMode; if (request.WantDocumentationForEveryCompletionResult) { response.Description = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); } if (request.WantReturnType) { response.ReturnType = ReturnTypeFormatter.GetReturnType(symbol); } if (request.WantKind) { response.Kind = symbol.GetKind(); } if (request.WantSnippet) { var snippetGenerator = new SnippetGenerator(); snippetGenerator.IncludeMarkers = true; snippetGenerator.IncludeOptionalParameters = includeOptionalParams; response.Snippet = snippetGenerator.Generate(symbol); } if (request.WantMethodHeader) { response.MethodHeader = displayNameGenerator.Generate(symbol); } response.Preselect = preselect; return(response); }
public void Has_typeparam_and_param_in_description() { var documentation = @" <member name=""M:TestNamespace.TestClass.CreateWorkspace`1""> <summary> Creates a workspace. </summary> <typeparam name=""T"">The type of workspace being created.</typeparam> <param name=""Path"">The path to the workspace.</param> </member>"; var plainText = DocumentationConverter.ConvertDocumentation(documentation, "\n"); var expected = @"Creates a workspace. <T>: The type of workspace being created. Path: The path to the workspace."; Assert.Equal(expected, plainText, ignoreLineEndingDifferences: true); }
public async Task Converts_xml_documentation_to_plain_text() { var documentation = @" <member name=""M:TestNamespace.TestClass.GetZero""> <summary> The GetZero method. </summary> <example> This sample shows how to call the <see cref=""M:TestNamespace.TestClass.GetZero""/> method. <code> class TestClass { static int Main() { return GetZero(); } } </code> </example> </member>"; var plainText = DocumentationConverter.ConvertDocumentation(documentation, "\n"); var expected = @"The GetZero method. Example: This sample shows how to call the TestNamespace.TestClass.GetZero method. class TestClass { static int Main() { return GetZero(); } } "; Assert.Equal(expected, plainText, ignoreLineEndingDifferences: true); }