private static async Task <LSP.VSInternalDocumentOnAutoInsertResponseItem?> GetDocumentationCommentResponseAsync( LSP.VSInternalDocumentOnAutoInsertParams autoInsertParams, Document document, IDocumentationCommentSnippetService service, DocumentationCommentOptions options, CancellationToken cancellationToken) { var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var linePosition = ProtocolConversions.PositionToLinePosition(autoInsertParams.Position); var position = sourceText.Lines.GetPosition(linePosition); var result = autoInsertParams.Character == "\n" ? service.GetDocumentationCommentSnippetOnEnterTyped(syntaxTree, sourceText, position, options, cancellationToken) : service.GetDocumentationCommentSnippetOnCharacterTyped(syntaxTree, sourceText, position, options, cancellationToken); if (result == null) { return(null); } return(new LSP.VSInternalDocumentOnAutoInsertResponseItem { TextEditFormat = LSP.InsertTextFormat.Snippet, TextEdit = new LSP.TextEdit { NewText = result.SnippetText.Insert(result.CaretOffset, "$0"), Range = ProtocolConversions.TextSpanToRange(result.SpanToReplace, sourceText) } }); }
public static OmniSharpDocumentationCommentSnippet?GetDocumentationCommentSnippetFromPreviousLine( Document document, DocumentOptionSet options, TextLine currentLine, TextLine previousLine) { var service = document.GetRequiredLanguageService <IDocumentationCommentSnippetService>(); var docCommentOptions = DocumentationCommentOptions.From(options); return(Translate(service.GetDocumentationCommentSnippetFromPreviousLine(docCommentOptions, currentLine, previousLine))); }
public static OmniSharpDocumentationCommentSnippet?GetDocumentationCommentSnippetOnEnterTyped( Document document, SyntaxTree syntaxTree, SourceText text, int position, DocumentOptionSet options, CancellationToken cancellationToken) { var service = document.GetRequiredLanguageService <IDocumentationCommentSnippetService>(); var docCommentOptions = DocumentationCommentOptions.From(options); return(Translate(service.GetDocumentationCommentSnippetOnEnterTyped(syntaxTree, text, position, docCommentOptions, cancellationToken))); }
public override async Task <LSP.VSInternalDocumentOnAutoInsertResponseItem?> HandleRequestAsync( LSP.VSInternalDocumentOnAutoInsertParams request, RequestContext context, CancellationToken cancellationToken) { var document = context.Document; if (document == null) { return(null); } var service = document.GetRequiredLanguageService <IDocumentationCommentSnippetService>(); // We should use the options passed in by LSP instead of the document's options. var documentOptions = await ProtocolConversions.FormattingOptionsToDocumentOptionsAsync( request.Options, document, cancellationToken).ConfigureAwait(false); var options = DocumentationCommentOptions.From(documentOptions); // The editor calls this handler for C# and VB comment characters, but we only need to process the one for the language that matches the document if (request.Character == "\n" || request.Character == service.DocumentationCommentCharacter) { var documentationCommentResponse = await GetDocumentationCommentResponseAsync( request, document, service, options, cancellationToken).ConfigureAwait(false); if (documentationCommentResponse != null) { return(documentationCommentResponse); } } // Only support this for razor as LSP doesn't support overtype yet. // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1165179/ // Once LSP supports overtype we can move all of brace completion to LSP. if (request.Character == "\n" && context.ServerKind == WellKnownLspServerKinds.RazorLspServer) { var indentationOptions = IndentationOptions.From(documentOptions, document.Project.Solution.Workspace.Services, document.Project.Language); var braceCompletionAfterReturnResponse = await GetBraceCompletionAfterReturnResponseAsync( request, document, indentationOptions, cancellationToken).ConfigureAwait(false); if (braceCompletionAfterReturnResponse != null) { return(braceCompletionAfterReturnResponse); } } return(null); }
internal OmniSharpDocumentationCommentOptionsWrapper(DocumentationCommentOptions underlyingObject) => UnderlyingObject = underlyingObject;