コード例 #1
0
        /// <summary>
        /// Starts the channel and initializes the MessageDispatcher.
        /// </summary>
        /// <param name="messageProtocolType">The type of message protocol used by the channel.</param>
        public void Start(MessageProtocolType messageProtocolType)
        {
            IMessageSerializer messageSerializer = null;

            if (messageProtocolType == MessageProtocolType.LanguageServer)
            {
                messageSerializer = new JsonRpcMessageSerializer();
            }
            else
            {
                messageSerializer = new V8MessageSerializer();
            }

            this.Initialize(messageSerializer);

            if (this.MessageDispatcher == null)
            {
                this.MessageDispatcher =
                    new MessageDispatcher(
                        this.MessageReader,
                        this.MessageWriter);

                this.MessageDispatcher.Start();
            }
        }
コード例 #2
0
        private Message Deserialize(string s, MessageType messageType)
        {
            byte[]                   bytes             = Encoding.UTF8.GetBytes(s);
            MemoryStream             inputStream       = new MemoryStream(bytes);
            JsonRpcMessageSerializer messageSerializer = new JsonRpcMessageSerializer(Encoding.UTF8);

            return(messageSerializer.Deserialize(inputStream, messageType));
        }
コード例 #3
0
        /// <summary>
        /// Starts the channel and initializes the MessageDispatcher.
        /// </summary>
        /// <param name="messageProtocolType">The type of message protocol used by the channel.</param>
        public void Start(MessageProtocolType messageProtocolType)
        {
            IMessageSerializer messageSerializer = null;

            if (messageProtocolType == MessageProtocolType.LanguageServer)
            {
                messageSerializer = new JsonRpcMessageSerializer();
            }
            else
            {
                messageSerializer = new V8MessageSerializer();
            }

            this.Initialize(messageSerializer);
        }
コード例 #4
0
        /// <summary>
        /// Create a new LSP pipe around a named pipe client stream.
        /// </summary>
        /// <param name="namedPipeClient">The named pipe client stream to use for the LSP pipe.</param>
        public PsesLspClient(NamedPipeClientStream namedPipeClient)
        {
            _namedPipeClient = namedPipeClient;

            _jsonSettings = new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            _jsonSerializer = JsonSerializer.Create(_jsonSettings);

            // Reuse the PSES JSON RPC serializer
            _jsonRpcSerializer = new JsonRpcMessageSerializer();

            _pipeEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
        }
コード例 #5
0
        private static string Serialize(Message messageStream)
        {
            MemoryStream             outputStream      = new MemoryStream();
            JsonRpcMessageSerializer messageSerializer = new JsonRpcMessageSerializer(Encoding.UTF8);

            messageSerializer.Serialize(messageStream, outputStream);
            outputStream.Position = 0;
            StreamReader  reader = new StreamReader(outputStream);
            string        line;
            StringBuilder sb = new StringBuilder();

            while ((line = reader.ReadLine()) != null)
            {
                sb.Append(line);
            }
            return(sb.ToString());
        }
コード例 #6
0
        async Task ListenForMessages()
        {
            this.messageLoopSyncContext = SynchronizationContext.Current;

            // Ensure that the console is using UTF-8 encoding
            System.Console.InputEncoding  = Encoding.UTF8;
            System.Console.OutputEncoding = Encoding.UTF8;

            // Open the standard input/output streams
            this.inputStream  = System.Console.OpenStandardInput();
            this.outputStream = System.Console.OpenStandardOutput();

            IMessageSerializer messageSerializer = null;
            IMessageProcessor  messageProcessor  = null;

            // Use a different serializer and message processor based
            // on whether this instance should host a language server
            // debug adapter.
            if (this.runDebugAdapter)
            {
                DebugAdapter debugAdapter = new DebugAdapter();
                debugAdapter.Initialize();

                messageProcessor  = debugAdapter;
                messageSerializer = new V8MessageSerializer();
            }
            else
            {
                // Set up the LanguageServer
                LanguageServer languageServer = new LanguageServer();
                languageServer.Initialize();

                messageProcessor  = languageServer;
                messageSerializer = new JsonRpcMessageSerializer();
            }

            // Set up the reader and writer
            this.messageReader =
                new MessageReader(
                    this.inputStream,
                    messageSerializer);

            this.messageWriter =
                new MessageWriter(
                    this.outputStream,
                    messageSerializer);

            // Set up the console host which will send events
            // through the MessageWriter
            this.consoleHost = new StdioConsoleHost(messageWriter);

            // Set up the PowerShell session
            this.editorSession = new EditorSession();
            this.editorSession.StartSession(this.consoleHost);
            this.editorSession.PowerShellContext.OutputWritten += powerShellContext_OutputWritten;

            if (this.runDebugAdapter)
            {
                // Attach to debugger events from the PowerShell session
                this.editorSession.DebugService.DebuggerStopped += DebugService_DebuggerStopped;
            }

            // Run the message loop
            bool isRunning = true;

            while (isRunning)
            {
                Message newMessage = null;

                try
                {
                    // Read a message from stdin
                    newMessage = await this.messageReader.ReadMessage();
                }
                catch (MessageParseException e)
                {
                    // TODO: Write an error response

                    Logger.Write(
                        LogLevel.Error,
                        "Could not parse a message that was received:\r\n\r\n" +
                        e.ToString());

                    // Continue the loop
                    continue;
                }

                // Process the message
                await messageProcessor.ProcessMessage(
                    newMessage,
                    this.editorSession,
                    this.messageWriter);
            }
        }
コード例 #7
0
        public void Start()
        {
            // If the test is running in the debugger, tell the language
            // service to also wait for the debugger
            string languageServiceArguments = string.Empty;

            if (System.Diagnostics.Debugger.IsAttached)
            {
                languageServiceArguments = "/waitForDebugger";
            }

            this.languageServiceProcess = new System.Diagnostics.Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "Microsoft.PowerShell.EditorServices.Host.exe",
                    Arguments              = languageServiceArguments,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    StandardOutputEncoding = Encoding.UTF8,
                },
                EnableRaisingEvents = true,
            };

            // Start the process
            this.languageServiceProcess.Start();

            // Attach to the language service process if debugging
            if (System.Diagnostics.Debugger.IsAttached)
            {
                AttachToProcessIfDebugging(this.languageServiceProcess.Id);
            }

            IMessageSerializer messageSerializer = new JsonRpcMessageSerializer();

            // Open the standard input/output streams
            this.inputStream  = this.languageServiceProcess.StandardOutput.BaseStream;
            this.outputStream = this.languageServiceProcess.StandardInput.BaseStream;

            // Set up the message reader and writer
            this.MessageReader =
                new MessageReader(
                    this.inputStream,
                    messageSerializer);
            this.MessageWriter =
                new MessageWriter(
                    this.outputStream,
                    messageSerializer);


            // Send the 'initialize' request and wait for the response
            var initializeRequest = new InitializeRequest
            {
                RootPath     = "",
                Capabilities = new ClientCapabilities()
            };

            // TODO: Assert some capability data?
            this.MessageWriter.WriteRequest(InitializeRequest.Type, initializeRequest, 1).Wait();
            Message initializeResponse = this.MessageReader.ReadMessage().Result;
        }