nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
lspserver
include
lspserver
DraftStore.h
Go to the documentation of this file.
1
//===--- DraftStore.h - File contents container -----------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#pragma once
10
11
#include "
Path.h
"
12
#include "llvm/ADT/StringMap.h"
13
#include "llvm/Support/VirtualFileSystem.h"
14
#include <mutex>
15
#include <optional>
16
#include <string>
17
#include <vector>
18
19
namespace
lspserver
{
20
21
/// A thread-safe container for files opened in a workspace, addressed by
22
/// filenames. The contents are owned by the DraftStore.
23
/// Each time a draft is updated, it is assigned a version. This can be
24
/// specified by the caller or incremented from the previous version.
25
class
DraftStore
{
26
public
:
27
struct
Draft
{
28
std::shared_ptr<const std::string>
Contents
;
29
std::string
Version
;
30
};
31
32
/// \return Contents of the stored document.
33
/// For untracked files, a std::nullopt is returned.
34
std::optional<Draft>
getDraft
(
PathRef
File
)
const
;
35
36
/// \return List of names of the drafts in this store.
37
std::vector<Path>
getActiveFiles
()
const
;
38
39
/// Replace contents of the draft for \p File with \p Contents.
40
/// If version is empty, one will be automatically assigned.
41
/// Returns the version.
42
std::string
addDraft
(
PathRef
File
, llvm::StringRef Version,
43
llvm::StringRef Contents);
44
45
/// Remove the draft from the store.
46
void
removeDraft
(
PathRef
File
);
47
48
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
asVFS
()
const
;
49
50
/// LSP defines file versions as numbers that increase.
51
/// treats them as opaque and therefore uses strings instead.
52
static
std::string
encodeVersion
(std::optional<int64_t> LSPVersion);
53
54
static
std::optional<int64_t>
decodeVersion
(llvm::StringRef Encoded);
55
56
private
:
57
struct
DraftAndTime {
58
Draft
D;
59
std::time_t MTime;
60
};
61
mutable
std::mutex Mutex;
62
llvm::StringMap<DraftAndTime> Drafts;
63
};
64
65
}
// namespace lspserver
Path.h
lspserver::DraftStore
Definition
DraftStore.h:25
lspserver::DraftStore::encodeVersion
static std::string encodeVersion(std::optional< int64_t > LSPVersion)
Definition
DraftStore.cpp:84
lspserver::DraftStore::getActiveFiles
std::vector< Path > getActiveFiles() const
Definition
DraftStore.cpp:28
lspserver::DraftStore::getDraft
std::optional< Draft > getDraft(PathRef File) const
Definition
DraftStore.cpp:18
lspserver::DraftStore::removeDraft
void removeDraft(PathRef File)
Remove the draft from the store.
Definition
DraftStore.cpp:99
lspserver::DraftStore::addDraft
std::string addDraft(PathRef File, llvm::StringRef Version, llvm::StringRef Contents)
Definition
DraftStore.cpp:88
lspserver::DraftStore::asVFS
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > asVFS() const
Definition
DraftStore.cpp:131
lspserver::DraftStore::decodeVersion
static std::optional< int64_t > decodeVersion(llvm::StringRef Encoded)
Definition
DraftStore.cpp:61
lspserver
Whether current platform treats paths case insensitively.
Definition
Connection.h:11
lspserver::CompletionItemKind::File
@ File
Definition
lspserver/include/lspserver/Protocol.h:413
lspserver::PathRef
llvm::StringRef PathRef
Definition
Path.h:27
lspserver::DraftStore::Draft
Definition
DraftStore.h:27
lspserver::DraftStore::Draft::Version
std::string Version
Definition
DraftStore.h:29
lspserver::DraftStore::Draft::Contents
std::shared_ptr< const std::string > Contents
Definition
DraftStore.h:28
Generated by
1.17.0