2017-05-16 17:38:59 +08:00
|
|
|
//===--- DraftStore.h - File contents container -----------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-05-16 17:38:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DRAFTSTORE_H
|
|
|
|
|
[clangd] Move non-clang base pieces into separate support/ lib. NFCI
Summary:
This enforces layering, reduces a sprawling clangd/ directory, and makes life
easier for embedders.
Reviewers: kbobyrev
Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D79014
2020-04-28 23:49:17 +08:00
|
|
|
#include "support/Path.h"
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2021-03-09 22:35:20 +08:00
|
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
2017-05-16 17:38:59 +08:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
/// A thread-safe container for files opened in a workspace, addressed by
|
2021-03-02 07:16:33 +08:00
|
|
|
/// filenames. The contents are owned by the DraftStore.
|
|
|
|
/// Each time a draft is updated, it is assigned a version. This can be
|
2020-03-03 22:57:39 +08:00
|
|
|
/// specified by the caller or incremented from the previous version.
|
2017-05-16 17:38:59 +08:00
|
|
|
class DraftStore {
|
|
|
|
public:
|
2020-03-03 22:57:39 +08:00
|
|
|
struct Draft {
|
2021-03-09 22:35:20 +08:00
|
|
|
std::shared_ptr<const std::string> Contents;
|
2021-03-02 07:16:33 +08:00
|
|
|
std::string Version;
|
2020-03-03 22:57:39 +08:00
|
|
|
};
|
|
|
|
|
2018-03-16 22:30:42 +08:00
|
|
|
/// \return Contents of the stored document.
|
|
|
|
/// For untracked files, a llvm::None is returned.
|
2020-03-03 22:57:39 +08:00
|
|
|
llvm::Optional<Draft> getDraft(PathRef File) const;
|
[clangd] DidChangeConfiguration Notification
Summary:
Implementation of DidChangeConfiguration notification handling in
clangd. This currently only supports changing one setting: the path of
the compilation database to be used for the current project. In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: jkorous-apple, ioeric, simark, klimek, ilya-biryukov, arphaman, rwols, cfe-commits
Differential Revision: https://reviews.llvm.org/D39571
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325784
2018-02-22 22:00:39 +08:00
|
|
|
|
2018-03-16 22:30:42 +08:00
|
|
|
/// \return List of names of the drafts in this store.
|
[clangd] DidChangeConfiguration Notification
Summary:
Implementation of DidChangeConfiguration notification handling in
clangd. This currently only supports changing one setting: the path of
the compilation database to be used for the current project. In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: jkorous-apple, ioeric, simark, klimek, ilya-biryukov, arphaman, rwols, cfe-commits
Differential Revision: https://reviews.llvm.org/D39571
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325784
2018-02-22 22:00:39 +08:00
|
|
|
std::vector<Path> getActiveFiles() const;
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
/// Replace contents of the draft for \p File with \p Contents.
|
2021-03-02 07:16:33 +08:00
|
|
|
/// If version is empty, one will be automatically assigned.
|
2020-03-03 22:57:39 +08:00
|
|
|
/// Returns the version.
|
2021-03-02 07:16:33 +08:00
|
|
|
std::string addDraft(PathRef File, llvm::StringRef Version,
|
|
|
|
StringRef Contents);
|
2018-03-16 22:30:42 +08:00
|
|
|
|
|
|
|
/// Remove the draft from the store.
|
|
|
|
void removeDraft(PathRef File);
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2021-03-09 22:35:20 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> asVFS() const;
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
private:
|
2021-03-09 22:35:20 +08:00
|
|
|
struct DraftAndTime {
|
2021-03-09 22:55:55 +08:00
|
|
|
Draft D;
|
2021-03-09 22:35:20 +08:00
|
|
|
std::time_t MTime;
|
|
|
|
};
|
2017-05-16 17:38:59 +08:00
|
|
|
mutable std::mutex Mutex;
|
2021-03-09 22:35:20 +08:00
|
|
|
llvm::StringMap<DraftAndTime> Drafts;
|
2017-05-16 17:38:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|