| 81 | |
| 82 | |
| 83 | int StandardIOSession::Run(LanguageServer &server) { |
| 84 | auto &ioc = server.GetIOContext(); |
| 85 | IOSession::Run(server); |
| 86 | while (true) { |
| 87 | do { |
| 88 | char *writableCursor = _protocolBuffer.GetWritableCursor(); |
| 89 | std::size_t capacity = _protocolBuffer.GetRestCapacity(); |
| 90 | |
| 91 | std::size_t readSize = StandardIO::GetInstance().ReadSome(writableCursor, capacity); |
| 92 | |
| 93 | if (StandardIO::GetInstance().HasError()) { |
| 94 | goto endLoop; |
| 95 | } |
| 96 | |
| 97 | _protocolBuffer.SetWriteSize(readSize); |
| 98 | |
| 99 | if (_protocolBuffer.CanReadOneProtocol()) { |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | _protocolBuffer.FitCapacity(); |
| 104 | } while (true); |
| 105 | |
| 106 | do { |
| 107 | auto content = _protocolBuffer.ReadOneProtocol(); |
| 108 | auto parser = std::make_shared<ProtocolParser>(); |
| 109 | parser->Parse(content); |
| 110 | _protocolBuffer.Reset(); |
| 111 | asio::post(ioc, [this, parser, &server]() { |
| 112 | std::string result = Handle(server, parser); |
| 113 | |
| 114 | if (!result.empty()) { |
| 115 | Send(result); |
| 116 | } |
| 117 | }); |
| 118 | } while (_protocolBuffer.CanReadOneProtocol()); |
| 119 | } |
| 120 | endLoop: |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | void StandardIOSession::Send(std::string_view content) { |
| 125 | StandardIO::GetInstance().Write(content); |
nothing calls this directly
no test coverage detected