Esempio n. 1
0
        private async Task <bool> MakePrettier()
        {
            string input  = _view.TextBuffer.CurrentSnapshot.GetText();
            string output = await _node.ExecuteProcess(input, _encoding, _filePath);

            if (string.IsNullOrEmpty(output) || input == output)
            {
                return(false);
            }

            using (ITextEdit edit = _view.TextBuffer.CreateEdit())
                using (ITextUndoTransaction undo = _undoManager.TextBufferUndoHistory.CreateTransaction("Make Prettier"))
                {
                    edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, output);
                    edit.Apply();

                    undo.Complete();
                }

            return(true);
        }
Esempio n. 2
0
        private async Task <bool> MakePrettier()
        {
            string input  = _view.TextBuffer.CurrentSnapshot.GetText();
            string output = await _node.ExecuteProcess(input, _encoding);

            if (string.IsNullOrEmpty(output) || input == output)
            {
                return(false);
            }

            using (ITextEdit edit = _view.TextBuffer.CreateEdit())
                using (ITextUndoTransaction undo = _undoManager.TextBufferUndoHistory.CreateTransaction("Make Prettier"))
                {
                    edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, output);
                    edit.Apply();

                    var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
                    dte.ExecuteCommand("Edit.FormatDocument");

                    undo.Complete();
                }

            return(true);
        }