private bool TryFormat( ITextView textView, Document document, IEditorFormattingService formattingService, char typedChar, int position, bool formatOnReturn, CancellationToken cancellationToken) { var changes = formatOnReturn ? formattingService.GetFormattingChangesOnReturnAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken) : formattingService.GetFormattingChangesAsync(document, typedChar, position, cancellationToken).WaitAndGetResult(cancellationToken); if (changes == null || changes.Count == 0) { return false; } using (var transaction = CreateEditTransaction(textView, EditorFeaturesResources.Automatic_Formatting)) { transaction.MergePolicy = AutomaticCodeChangeMergePolicy.Instance; document.Project.Solution.Workspace.ApplyTextChanges(document.Id, changes, cancellationToken); transaction.Complete(); } return true; }
private bool TryFormat( ITextView textView, Document document, IEditorFormattingService formattingService, char typedChar, int position, bool formatOnReturn, CancellationToken cancellationToken) { var changes = formatOnReturn ? formattingService.GetFormattingChangesOnReturnAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken) : formattingService.GetFormattingChangesAsync(document, typedChar, position, cancellationToken).WaitAndGetResult(cancellationToken); if (changes == null || changes.Count == 0) { return(false); } using (var transaction = CreateEditTransaction(textView, EditorFeaturesResources.Automatic_Formatting)) { transaction.MergePolicy = AutomaticCodeChangeMergePolicy.Instance; document.Workspace.ApplyTextChanges(document.Id, changes, cancellationToken); transaction.Complete(); } return(true); }
protected override async Task <IList <TextChange>?> GetFormattingChangesOnReturnAsync(IEditorFormattingService formattingService, Document document, int position, CancellationToken cancellationToken) { // TypeScript expects to be called on the UI thread to get the formatting options. await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return(await base.GetFormattingChangesOnReturnAsync(formattingService, document, position, cancellationToken).ConfigureAwait(false)); }
protected virtual Task <IList <TextChange> > GetFormattingChangesAsync(IEditorFormattingService formattingService, Document document, TextSpan?textSpan, CancellationToken cancellationToken) => formattingService.GetFormattingChangesAsync(document, textSpan, cancellationToken);
protected virtual Task <IList <TextChange>?> GetFormattingChangesAsync(IEditorFormattingService formattingService, Document document, char typedChar, int position, CancellationToken cancellationToken) => formattingService.GetFormattingChangesAsync(document, typedChar, position, cancellationToken);
private VSTypeScriptEditorFormattingServiceWrapper(IEditorFormattingService underlyingObject) => _underlyingObject = underlyingObject;