loom
1#include "InputSupplier.h"
2#include "simodo/inout/token/RefBufferStream.h"
3#include "simodo/inout/token/BufferStream.h"
4#include "simodo/inout/token/FileStream.h"
5
6#include <cassert>
7
8using namespace simodo;
9
10std::shared_ptr<inout::InputStream_interface> InputSupplier::supply(const std::string & path) const
11{
12if (path == _base_file_path) {
13std::shared_ptr<inout::InputStream_interface> stream = std::make_shared<inout::RefBufferStream>(_text.data());
14return stream;
15}
16
17if (const lsp::DocumentContext * doc = _server.findDocument(path); doc) {
18/// \note Такая последовательность нужна для выполнения разграничения доступа внутри методов
19/// классов пространства имён lsp
20std::shared_ptr<inout::InputStream_interface> stream = std::make_shared<inout::BufferStream>();
21inout::BufferStream * buffer = dynamic_cast<inout::BufferStream *>(stream.get());
22assert(buffer);
23doc->copyContent(buffer->buffer());
24return stream;
25}
26
27return std::make_shared<inout::FileStream>(path);
28}