clang-tools  11.0.0
Classes | Public Member Functions | List of all members
clang::clangd::DraftStore Class Reference

A thread-safe container for files opened in a workspace, addressed by filenames. More...

#include <DraftStore.h>

Classes

struct  Draft
 

Public Member Functions

llvm::Optional< DraftgetDraft (PathRef File) const
 
std::vector< PathgetActiveFiles () const
 
int64_t addDraft (PathRef File, llvm::Optional< int64_t > Version, StringRef Contents)
 Replace contents of the draft for File with Contents. More...
 
llvm::Expected< DraftupdateDraft (PathRef File, llvm::Optional< int64_t > Version, llvm::ArrayRef< TextDocumentContentChangeEvent > Changes)
 Update the contents of the draft for File based on Changes. More...
 
void removeDraft (PathRef File)
 Remove the draft from the store. More...
 

Detailed Description

A thread-safe container for files opened in a workspace, addressed by filenames.

The contents are owned by the DraftStore. This class supports both whole and incremental updates of the documents. Each time a draft is updated, it is assigned a version number. This can be specified by the caller or incremented from the previous version.

Definition at line 28 of file DraftStore.h.

Member Function Documentation

◆ addDraft()

int64_t clang::clangd::DraftStore::addDraft ( PathRef  File,
llvm::Optional< int64_t >  Version,
StringRef  Contents 
)

Replace contents of the draft for File with Contents.

If no version is specified, one will be automatically assigned. Returns the version.

Definition at line 50 of file DraftStore.cpp.

References Contents, clang::clangd::DraftStore::Draft::Contents, clang::clangd::File, clang::clangd::updateVersion(), and clang::clangd::DraftStore::Draft::Version.

◆ getActiveFiles()

std::vector< Path > clang::clangd::DraftStore::getActiveFiles ( ) const
Returns
List of names of the drafts in this store.

Definition at line 27 of file DraftStore.cpp.

◆ getDraft()

llvm::Optional< DraftStore::Draft > clang::clangd::DraftStore::getDraft ( PathRef  File) const
Returns
Contents of the stored document. For untracked files, a llvm::None is returned.

Definition at line 17 of file DraftStore.cpp.

References clang::clangd::File, and clang::clangd::None.

◆ removeDraft()

void clang::clangd::DraftStore::removeDraft ( PathRef  File)

Remove the draft from the store.

Definition at line 131 of file DraftStore.cpp.

References clang::clangd::File.

◆ updateDraft()

llvm::Expected< DraftStore::Draft > clang::clangd::DraftStore::updateDraft ( PathRef  File,
llvm::Optional< int64_t >  Version,
llvm::ArrayRef< TextDocumentContentChangeEvent Changes 
)

Update the contents of the draft for File based on Changes.

If a position in Changes is invalid (e.g. out-of-range), the draft is not modified. If no version is specified, one will be automatically assigned.

Returns
The new version of the draft for File, or an error if the changes couldn't be applied.

Definition at line 60 of file DraftStore.cpp.

References Changes, Contents, and clang::clangd::File.


The documentation for this class was generated from the following files: