Exemplo n.º 1
0
 public PrettierCommand(IWpfTextView view, ITextBufferUndoManager undoManager, NodeProcess node, Encoding encoding)
 {
     _view        = view;
     _undoManager = undoManager;
     _node        = node;
     _encoding    = encoding;
 }
Exemplo n.º 2
0
        public PrettierCommand(IWpfTextView view, ITextBufferUndoManager undoManager, Encoding encoding, string filePath)
        {
            _view        = view;
            _undoManager = undoManager;
            _encoding    = encoding;
            _filePath    = filePath;

            _node = PrettierPackage._node;
        }
        private static async System.Threading.Tasks.Task Install(NodeProcess node)
        {
            var statusbar = (IVsStatusbar)ServiceProvider.GlobalProvider.GetService(typeof(SVsStatusbar));

            statusbar.FreezeOutput(0);
            statusbar.SetText($"Installing {NodeProcess.Packages} npm module...");
            statusbar.FreezeOutput(1);

            bool success = await node.EnsurePackageInstalled();

            string status = success ? "Done" : "Failed";

            statusbar.FreezeOutput(0);
            statusbar.SetText($"Installing {NodeProcess.Packages} npm module... {status}");
            statusbar.FreezeOutput(1);
        }
        public async void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            if (!DocumentService.TryGetTextDocument(view.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
            NodeProcess            node        = view.Properties.GetOrCreateSingletonProperty(() => new NodeProcess());

            AddCommandFilter(textViewAdapter, new PrettierCommand(view, undoManager, node, doc.Encoding, doc.FilePath));

            if (!node.IsReadyToExecute())
            {
                await Install(node);
            }
        }
Exemplo n.º 5
0
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            _dte             = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as DTE2;
            _serviceProvider = new ServiceProvider((IServiceProvider)_dte);
            _runningDocTable = new RunningDocumentTable(_serviceProvider);
            _runningDocTable.Advise(new RunningDocTableEventsHandler(this));

            optionPage = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid));
            _node      = new NodeProcess(this);

            if (!_node.IsReadyToExecute())
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                _node.EnsurePackageInstalledAsync().ConfigureAwait(false);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }

            await base.InitializeAsync(cancellationToken, progress);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            if (!DocumentService.TryGetTextDocument(view.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
            NodeProcess            node        = view.Properties.GetOrCreateSingletonProperty(() => new NodeProcess());

            var cmd = new PrettierCommand(view, undoManager, node, doc.Encoding, doc.FilePath);

            view.Properties.AddProperty("prettierCommand", cmd);

            AddCommandFilter(textViewAdapter, cmd);

            if (!node.IsReadyToExecute())
            {
                node.EnsurePackageInstalledAsync().ConfigureAwait(false);
            }
        }