TextDocumentManager.getOrFromFilesystem

Returns the managed document for the given URI or if it doesn't exist it tries to read the file from the filesystem and open it from that.

Note that a LSP close method will unload this early.

  1. Document getOrFromFilesystem(string uri, bool inserted)
    struct TextDocumentManager
    ref
    getOrFromFilesystem
    (
    string uri
    ,
    out bool inserted
    )
  2. Document getOrFromFilesystem(string uri)

Parameters

uri string

the document URI to try to load. Must be consistent with LSP URIs. (e.g. normalized URIs)

inserted bool

if specified, gets set to true if the file was read from filesystem and false if it was already present.

Return Value

Type: Document

the created document

Throws

FileException in case the file doesn't exist or other file system errors. In this case no new document should have been inserted yet.

Examples

import served.lsp.uri;

import std.file;
import std.path;

auto dir = buildPath(tempDir(), "textdocumentmanager");
mkdir(dir);
scope (exit)
	rmdirRecurse(dir);

auto app_d = buildPath(dir, "app.d");
auto src = "import std.stdio; void main() { writeln(`hello world`); }";
write(app_d, src);

TextDocumentManager documents;
bool created;
auto doc = &documents.getOrFromFilesystem(uriFromFile(app_d), created);
assert(created);
auto other = &documents.getOrFromFilesystem(uriFromFile(app_d));
assert(doc is other);

assert(doc.rawText == src);
assert(doc.rawText !is src);

Meta