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] Support incremental document syncing
Summary:
This patch adds support for incremental document syncing, as described
in the LSP spec. The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings. So I
see two things that may not be super efficient for very large files:
- Converting a Position to an offset (the positionToOffset function)
requires searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies
copying the whole document.
However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue. This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Reviewers: malaperle, ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: MaskRay, klimek, mgorny, ilya-biryukov, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D44272
llvm-svn: 328500
2018-03-26 22:41:40 +08:00
|
|
|
#include "Protocol.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"
|
|
|
|
#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 {
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
mutable std::mutex Mutex;
|
2020-03-03 22:57:39 +08:00
|
|
|
llvm::StringMap<Draft> Drafts;
|
2017-05-16 17:38:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|