示例#1
0
        public void RunCommand_ExpandsHtmlAbbreviation()
        {
            // Arrange
            string       result = string.Empty;
            IEmmetEditor editor = Substitute.For <IEmmetEditor>();

            editor.GetContentTypeInActiveBuffer().Returns("htmlx");
            editor.GetContent().Returns("div");
            editor.GetSelectionRange().Returns(new Range(3, 3));
            editor.GetCurrentLineRange().Returns(new Range(0, 3));
            editor.GetCaretPosition().Returns(3);
            editor.ReplaceContentRange(Arg.Do <string>(s => result = s), Arg.Any <int>(), Arg.Any <int>());

            // Act
            _engine.RunCommand(PackageIds.CmdIDExpandAbbreviation, editor).Should().BeTrue();
            result.Should().Be("<div></div>");
        }
示例#2
0
        /// <summary>
        /// Executes Emmet command in the specified view.
        /// </summary>
        /// <param name="context">The view context to execute command in.</param>
        /// <param name="cmdId">Identifier of the command to execute.</param>
        internal bool RunCommand(ViewContext context, int cmdId)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            DTE2 dte = GetService(typeof(DTE)) as DTE2;

            Assumes.Present(dte);

            bool ownUndoContext = false;

            try
            {
                if (!dte.UndoContext.IsOpen)
                {
                    dte.UndoContext.Open(Vsix.Name);
                    ownUndoContext = true;
                }

                bool succeeded = _engine.RunCommand(cmdId, context);

                if (ownUndoContext)
                {
                    dte.UndoContext.Close();
                }

                return(succeeded);
            }
            catch (Exception ex) when(IsExpectedException(ex))
            {
                if (ownUndoContext)
                {
                    dte.UndoContext.SetAborted();
                }

                string msg;

                switch (ex)
                {
                case Exception <ChakraExceptionArgs> jsex:
                    msg = $"Unexpected error occurred inside of the Emmet engine. {jsex.Message}";
                    break;

                case COMException comex:
                    msg = $"Cannot load Microsoft Chakra engine: {comex.Message}";
                    break;

                default:
                    msg = $"Unexpected error of type {ex.GetType()}: {ex.Message}";
                    break;
                }

                ShowCriticalError(msg);

                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// Executes Emmet command in the specified view.
        /// </summary>
        /// <param name="context">The view context to execute command in.</param>
        /// <param name="cmdId">Identifier of the command to execute.</param>
        internal bool RunCommand(EmmetEditor context, int cmdId)
        {
            DTE2 dte            = GetService(typeof(DTE)) as DTE2;
            bool ownUndoContext = false;

            try
            {
                if (!dte.UndoContext.IsOpen)
                {
                    ownUndoContext = true;
                    dte.UndoContext.Open("Emmet.NET");
                }

                bool succeeded = _engine.RunCommand(cmdId, context);

                if (ownUndoContext)
                {
                    dte.UndoContext.Close();
                }

                return(succeeded);
            }
            catch (Exception <EmmetEngineExceptionArgs> ex)
            {
                if (ownUndoContext)
                {
                    dte.UndoContext.SetAborted();
                }

                string msg = $"Unexpected error occurred inside of the Emmet engine. {ex.Message}";

                VsShellUtilities.ShowMessageBox(
                    this,
                    msg,
                    "Emmet.NET: Unexpected error.",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return(false);
            }
        }