public static async Task <DocumentOptionSet> GetDocumentOptionsWithInferredIndentationAsync( this Document document, bool explicitFormat, IIndentationManagerService indentationManagerService, CancellationToken cancellationToken ) { var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var snapshot = text.FindCorrespondingEditorTextSnapshot(); if (snapshot != null) { indentationManagerService.GetIndentation( snapshot.TextBuffer, explicitFormat, out var convertTabsToSpaces, out var tabSize, out var indentSize ); options = options .WithChangedOption(FormattingOptions.UseTabs, !convertTabsToSpaces) .WithChangedOption(FormattingOptions.IndentationSize, indentSize) .WithChangedOption(FormattingOptions.TabSize, tabSize); } return(options); }
public override FormattingOptions GetOptions(LSPDocumentSnapshot documentSnapshot) { _indentationManagerService.GetIndentation(documentSnapshot.Snapshot.TextBuffer, explicitFormat: false, out var insertSpaces, out var tabSize, out _); var formattingOptions = new FormattingOptions() { InsertSpaces = insertSpaces, TabSize = tabSize, }; return(formattingOptions); }
private static LineFormattingOptions GetLineFormattingOptionsImpl(ITextBuffer textBuffer, IEditorOptions editorOptions, IIndentationManagerService indentationManager, bool explicitFormat) { indentationManager.GetIndentation(textBuffer, explicitFormat, out var convertTabsToSpaces, out var tabSize, out var indentSize); return(new LineFormattingOptions() { UseTabs = !convertTabsToSpaces, IndentationSize = indentSize, TabSize = tabSize, NewLine = editorOptions.GetNewLineCharacter(), }); }
public static async Task <SyntaxFormattingOptions> GetInferredFormattingOptionsAsync(this IIndentationManagerService indentationManager, Document document, bool explicitFormat, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var snapshot = text.FindCorrespondingEditorTextSnapshot(); var options = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); if (snapshot == null) { return(options); } indentationManager.GetIndentation(snapshot.TextBuffer, explicitFormat, out var convertTabsToSpaces, out var tabSize, out var indentSize); return(options.With(new LineFormattingOptions( UseTabs: !convertTabsToSpaces, IndentationSize: indentSize, TabSize: tabSize, NewLine: options.NewLine))); }
public override FormattingOptions?GetOptions(Uri lspDocumentUri) { if (lspDocumentUri is null) { throw new ArgumentNullException(nameof(lspDocumentUri)); } if (!_documentManager.TryGetDocument(lspDocumentUri, out var documentSnapshot)) { // Couldn't resolve document and therefore can't resolve the corresponding formatting options. return(null); } _indentationManagerService.GetIndentation(documentSnapshot.Snapshot.TextBuffer, explicitFormat: false, out var insertSpaces, out var tabSize, out _); var formattingOptions = new FormattingOptions() { InsertSpaces = insertSpaces, TabSize = tabSize, }; return(formattingOptions); }