Example #1
0
        private async void OnLanguageServiceClientConnect(
            object sender,
            ChannelBase serverChannel)
        {
            MessageDispatcher messageDispatcher = new MessageDispatcher(this.logger);

            ProtocolEndpoint protocolEndpoint =
                new ProtocolEndpoint(
                    serverChannel,
                    messageDispatcher,
                    this.logger);

            protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException;

            this.editorSession =
                CreateSession(
                    this.hostDetails,
                    this.profilePaths,
                    protocolEndpoint,
                    messageDispatcher,
                    this.enableConsoleRepl);

            this.languageServer =
                new LanguageServer(
                    this.editorSession,
                    messageDispatcher,
                    protocolEndpoint,
                    this.serverCompletedTask,
                    this.logger);

            await this.editorSession.PowerShellContext.ImportCommandsModule(
                Path.Combine(
                    Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location),
                    @"..\..\Commands"));

            this.languageServer.Start();

            // TODO: This can be moved to the point after the $psEditor object
            // gets initialized when that is done earlier than LanguageServer.Initialize
            foreach (string module in this.additionalModules)
            {
                var command =
                    new System.Management.Automation.PSCommand()
                    .AddCommand("Microsoft.PowerShell.Core\\Import-Module")
                    .AddParameter("Name", module);

                await this.editorSession.PowerShellContext.ExecuteCommand <System.Management.Automation.PSObject>(
                    command,
                    sendOutputToHost : false,
                    sendErrorToHost : true);
            }

            protocolEndpoint.Start();
        }
        public void CanDotSourcePath(string rawFileName)
        {
            string fullPath   = Path.Combine(ScriptAssetPath, rawFileName);
            string quotedPath = PowerShellContext.QuoteEscapeString(fullPath);

            var psCommand = new System.Management.Automation.PSCommand().AddScript($". {quotedPath}");

            using (var pwsh = System.Management.Automation.PowerShell.Create())
            {
                pwsh.Commands = psCommand;
                pwsh.Invoke();
            }
        }