Esempio n. 1
0
        private bool ParseArguments(IInteractiveWindow window, string arguments, out string commandName, out IInteractiveWindowCommand command)
        {
            string name = arguments.Split(s_whitespaceChars)[0];

            if (name.Length == 0)
            {
                command = null;
                commandName = null;
                return true;
            }

            var commands = window.GetInteractiveCommands();
            string prefix = commands.CommandPrefix;

            // display help on a particular command:
            command = commands[name];

            if (command == null && name.StartsWith(prefix, StringComparison.Ordinal))
            {
                name = name.Substring(prefix.Length);
                command = commands[name];
            }

            commandName = name;
            return command != null;
        }
Esempio n. 2
0
        private static bool IsCommandApplicable(
            IInteractiveWindowCommand command,
            string[] supportedRoles,
            IContentType[] supportedContentTypes
            )
        {
            var commandRoles = command.GetType().GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true).Select(r => ((InteractiveWindowRoleAttribute)r).Name).ToArray();

            // Commands with no roles are always applicable.
            // If a command specifies roles and none apply, exclude it
            if (commandRoles.Any() && !commandRoles.Intersect(supportedRoles).Any())
            {
                return(false);
            }

            var commandContentTypes = command.GetType()
                                      .GetCustomAttributes(typeof(ContentTypeAttribute), true)
                                      .Select(a => ((ContentTypeAttribute)a).ContentTypes)
                                      .ToArray();

            // Commands with no content type are always applicable
            // If a commands specifies content types and none apply, exclude it
            if (commandContentTypes.Any() && !commandContentTypes.Any(cct => supportedContentTypes.Any(sct => sct.IsOfType(cct))))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        internal InteractiveEvaluator(
            IContentType contentType,
            HostServices hostServices,
            IViewClassifierAggregatorService classifierAggregator,
            IInteractiveWindowCommandsFactory commandsFactory,
            IInteractiveWindowCommand[] commands,
            string responseFilePath,
            string initialWorkingDirectory,
            string interactiveHostPath,
            Type replType)
        {
            Debug.Assert(responseFilePath == null || PathUtilities.IsAbsolute(responseFilePath));

            _contentType = contentType;
            _responseFilePath = responseFilePath;
            _workspace = new InteractiveWorkspace(this, hostServices);
            _contentTypeChangedHandler = new EventHandler<ContentTypeChangedEventArgs>(LanguageBufferContentTypeChanged);
            _classifierAggregator = classifierAggregator;
            _initialWorkingDirectory = initialWorkingDirectory;
            _commandsFactory = commandsFactory;
            _commands = commands.ToImmutableArray();

            var hostPath = interactiveHostPath;
            _interactiveHost = new InteractiveHost(replType, hostPath, initialWorkingDirectory);
            _interactiveHost.ProcessStarting += ProcessStarting;
        }
Esempio n. 4
0
        private string ExecuteCommand(IInteractiveWindowCommand cmd, string args)
        {
            _window.ClearScreen();
            var execute = cmd.Execute(_window, args);

            execute.Wait();
            Assert.IsTrue(execute.Result.IsSuccessful);
            return(_window.Output.TrimEnd());
        }
Esempio n. 5
0
 private async Task <ExecutionResult> ExecuteCommandAsync(IInteractiveWindowCommand command, string arguments)
 {
     try
     {
         return(await command.Execute(_window, arguments).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         _window.ErrorOutputWriter.WriteLine($"Command '{command.Names.First()}' failed: {e.Message}");
         return(ExecutionResult.Failure);
     }
 }
Esempio n. 6
0
        public void DisplayCommandUsage(IInteractiveWindowCommand command, TextWriter writer, bool displayDetails)
        {
            if (displayDetails)
            {
                writer.WriteLine(command.Description);
                writer.WriteLine(string.Empty);
            }

            writer.WriteLine("Usage:");
            writer.Write(HelpIndent);
            writer.Write(CommandPrefix);
            writer.Write(string.Join(_commandSeparator, command.Names));

            string commandLine = command.CommandLine;

            if (commandLine != null)
            {
                writer.Write(" ");
                writer.Write(commandLine);
            }

            if (displayDetails)
            {
                writer.WriteLine(string.Empty);

                var paramsDesc = command.ParametersDescription;
                if (paramsDesc != null && paramsDesc.Any())
                {
                    writer.WriteLine(string.Empty);
                    writer.WriteLine("Parameters:");

                    int    maxParamNameLength  = paramsDesc.Max(entry => entry.Key.Length);
                    string paramHelpLineFormat = HelpIndent + "{0,-" + maxParamNameLength + "}  {1}";

                    foreach (var paramDesc in paramsDesc)
                    {
                        writer.WriteLine(string.Format(paramHelpLineFormat, paramDesc.Key, paramDesc.Value));
                    }
                }

                IEnumerable <string> details = command.DetailedDescription;
                if (details != null && details.Any())
                {
                    writer.WriteLine(string.Empty);
                    foreach (var line in details)
                    {
                        writer.WriteLine(line);
                    }
                }
            }
        }
 public VsInteractiveWindowProvider(
    SVsServiceProvider serviceProvider,
    IVsInteractiveWindowFactory interactiveWindowFactory,
    IViewClassifierAggregatorService classifierAggregator,
    IContentTypeRegistryService contentTypeRegistry,
    IInteractiveWindowCommandsFactory commandsFactory,
    IInteractiveWindowCommand[] commands,
    VisualStudioWorkspace workspace)
 {
     _vsServiceProvider = serviceProvider;
     _classifierAggregator = classifierAggregator;
     _contentTypeRegistry = contentTypeRegistry;
     _vsWorkspace = workspace;
     _commands = FilterCommands(commands, contentType: PredefinedInteractiveCommandsContentTypes.InteractiveCommandContentTypeName);
     _vsInteractiveWindowFactory = interactiveWindowFactory;
     _commandsFactory = commandsFactory;
 }
 public CSharpInteractiveEvaluator(
     HostServices hostServices,
     IViewClassifierAggregatorService classifierAggregator,
     IInteractiveWindowCommandsFactory commandsFactory,
     IInteractiveWindowCommand[] commands,
     IContentTypeRegistryService contentTypeRegistry,
     string responseFileDirectory,
     string initialWorkingDirectory)
     : base(
         contentTypeRegistry.GetContentType(ContentTypeNames.CSharpContentType),
         hostServices,
         classifierAggregator,
         commandsFactory,
         commands,
         (responseFileDirectory != null) ? Path.Combine(responseFileDirectory, InteractiveResponseFile) : null,
         initialWorkingDirectory,
         typeof(InteractiveHostEntryPoint).Assembly.Location,
         typeof(CSharpRepl))
 {
 }
Esempio n. 9
0
 private string ExecuteCommand(IInteractiveWindowCommand cmd, string args)
 {
     _window.ClearScreen();
     var execute = cmd.Execute(_window, args);
     execute.Wait();
     Assert.IsTrue(execute.Result.IsSuccessful);
     return _window.Output.TrimEnd();
 }
 private static ImmutableArray<IInteractiveWindowCommand> FilterCommands(IInteractiveWindowCommand[] commands, string contentType)
 {
     return commands.Where(
         c => c.GetType().GetCustomAttributes(typeof(ContentTypeAttribute), inherit: true).Any(
             a => ((ContentTypeAttribute)a).ContentTypes == contentType)).ToImmutableArray();
 }
Esempio n. 11
0
        private bool ParseArguments(IInteractiveWindow window, string arguments, out string commandName, out IInteractiveWindowCommand command)
        {
            string name = arguments.Split(whitespaceChars)[0];

            if (name.Length == 0)
            {
                command     = null;
                commandName = null;
                return(true);
            }

            var    commands = window.GetInteractiveCommands();
            string prefix   = commands.CommandPrefix;

            // display help on a particular command:
            command = commands[name];

            if (command == null && name.StartsWith(prefix))
            {
                name    = name.Substring(prefix.Length);
                command = commands[name];
            }

            commandName = name;
            return(command != null);
        }
 public void DisplayCommandHelp(IInteractiveWindowCommand command)
 {
     DisplayCommandUsage(command, _window.OutputWriter, displayDetails: true);
 }
        public void DisplayCommandUsage(IInteractiveWindowCommand command, TextWriter writer, bool displayDetails)
        {
            if (displayDetails)
            {
                writer.WriteLine(command.Description);
                writer.WriteLine(string.Empty);
            }

            writer.WriteLine("Usage:");
            writer.Write(HelpIndent);
            writer.Write(CommandPrefix);
            writer.Write(string.Join(_commandSeparator, command.Names));

            string commandLine = command.CommandLine;
            if (commandLine != null)
            {
                writer.Write(" ");
                writer.Write(commandLine);
            }

            if (displayDetails)
            {
                writer.WriteLine(string.Empty);

                var paramsDesc = command.ParametersDescription;
                if (paramsDesc != null && paramsDesc.Any())
                {
                    writer.WriteLine(string.Empty);
                    writer.WriteLine("Parameters:");

                    int maxParamNameLength = paramsDesc.Max(entry => entry.Key.Length);
                    string paramHelpLineFormat = HelpIndent + "{0,-" + maxParamNameLength + "}  {1}";

                    foreach (var paramDesc in paramsDesc)
                    {
                        writer.WriteLine(string.Format(paramHelpLineFormat, paramDesc.Key, paramDesc.Value));
                    }
                }

                IEnumerable<string> details = command.DetailedDescription;
                if (details != null && details.Any())
                {
                    writer.WriteLine(string.Empty);
                    foreach (var line in details)
                    {
                        writer.WriteLine(line);
                    }
                }
            }
        }
 private async Task<ExecutionResult> ExecuteCommandAsync(IInteractiveWindowCommand command, string arguments)
 {
     try
     {
         return await command.Execute(_window, arguments).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         _window.ErrorOutputWriter.WriteLine(InteractiveWindowResources.CommandFailed, command.Names.First(), e.Message);
         return ExecutionResult.Failure;
     }
 }
        private static ImmutableArray<IInteractiveWindowCommand> GetApplicableCommands(IInteractiveWindowCommand[] commands, string coreContentType, string specializedContentType)
        {
            // get all commands of coreContentType - generic interactive window commands
            var interactiveCommands = commands.Where(
                c => c.GetType().GetCustomAttributes(typeof(ContentTypeAttribute), inherit: true).Any(
                    a => ((ContentTypeAttribute)a).ContentTypes == coreContentType)).ToArray();

            // get all commands of specializedContentType - smart C#/VB command implementations
            var specializedInteractiveCommands = commands.Where(
                c => c.GetType().GetCustomAttributes(typeof(ContentTypeAttribute), inherit: true).Any(
                    a => ((ContentTypeAttribute)a).ContentTypes == specializedContentType)).ToArray();

            // We should choose specialized C#/VB commands over generic core interactive window commands
            // Build a map of names and associated core command first
            Dictionary<string, int> interactiveCommandMap = new Dictionary<string, int>();
            for (int i = 0; i < interactiveCommands.Length; i++)
            {
                foreach (var name in interactiveCommands[i].Names)
                {
                    interactiveCommandMap.Add(name, i);
                }
            }

            // swap core commands with specialized command if both exist
            // Command can have multiple names. We need to compare every name to find match.
            int value;
            foreach (var command in specializedInteractiveCommands)
            {
                foreach (var name in command.Names)
                {
                    if (interactiveCommandMap.TryGetValue(name, out value))
                    {
                        interactiveCommands[value] = command;
                        break;
                    }
                }
            }
            return interactiveCommands.ToImmutableArray();
        }
Esempio n. 16
0
        private static bool IsCommandApplicable(IInteractiveWindowCommand command, string[] supportedRoles) {
            bool applicable = true;
            string[] commandRoles = command.GetType().GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true).Select(r => ((InteractiveWindowRoleAttribute)r).Name).ToArray();
            if (supportedRoles.Length > 0) {
                // The window has one or more roles, so the following commands will be applicable:
                // - commands that don't specify a role
                // - commands that specify a role that matches one of the window roles
                if (commandRoles.Length > 0) {
                    applicable = supportedRoles.Intersect(commandRoles).Count() > 0;
                }
            } else {
                // The window doesn't have any role, so the following commands will be applicable:
                // - commands that don't specify any role
                applicable = commandRoles.Length == 0;
            }

            return applicable;
        }
 public void DisplayCommandUsage(IInteractiveWindowCommand command, TextWriter writer, bool displayDetails) {
     throw new NotImplementedException();
 }
 public void DisplayCommandHelp(IInteractiveWindowCommand command) {
     throw new NotImplementedException();
 }
 public void DisplayCommandUsage(IInteractiveWindowCommand command, TextWriter writer, bool displayDetails)
 {
     throw new NotImplementedException();
 }
 public void DisplayCommandHelp(IInteractiveWindowCommand command)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 public void DisplayCommandHelp(IInteractiveWindowCommand command)
 {
     DisplayCommandUsage(command, _window.OutputWriter, displayDetails: true);
 }
Esempio n. 22
0
        private static bool IsCommandApplicable(
            IInteractiveWindowCommand command,
            string[] supportedRoles,
            IContentType[] supportedContentTypes
        ) {
            var commandRoles = command.GetType().GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true).Select(r => ((InteractiveWindowRoleAttribute)r).Name).ToArray();

            // Commands with no roles are always applicable.
            // If a command specifies roles and none apply, exclude it
            if (commandRoles.Any() && !commandRoles.Intersect(supportedRoles).Any()) {
                return false;
            }

            var commandContentTypes = command.GetType()
                .GetCustomAttributes(typeof(ContentTypeAttribute), true)
                .Select(a => ((ContentTypeAttribute)a).ContentTypes)
                .ToArray();

            // Commands with no content type are always applicable
            // If a commands specifies content types and none apply, exclude it
            if (commandContentTypes.Any() && !commandContentTypes.Any(cct => supportedContentTypes.Any(sct => sct.IsOfType(cct)))) {
                return false;
            }

            return true;
        }