Line data Source code
1 : //===--- FSProvider.h - VFS provider for ClangdServer ------------*- C++-*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FSPROVIDER_H
11 : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FSPROVIDER_H
12 :
13 : #include "llvm/ADT/IntrusiveRefCntPtr.h"
14 : #include "llvm/Support/VirtualFileSystem.h"
15 :
16 : namespace clang {
17 : namespace clangd {
18 :
19 : // Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
20 : // As FileSystem is not threadsafe, concurrent threads must each obtain one.
21 : class FileSystemProvider {
22 : public:
23 0 : virtual ~FileSystemProvider() = default;
24 : /// Called by ClangdServer to obtain a vfs::FileSystem to be used for parsing.
25 : /// Context::current() will be the context passed to the clang entrypoint,
26 : /// such as addDocument(), and will also be propagated to result callbacks.
27 : /// Embedders may use this to isolate filesystem accesses.
28 : virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
29 : getFileSystem() const = 0;
30 : };
31 :
32 : class RealFileSystemProvider : public FileSystemProvider {
33 : public:
34 : // FIXME: returns the single real FS instance, which is not threadsafe.
35 : llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
36 : getFileSystem() const override {
37 : return llvm::vfs::getRealFileSystem();
38 : }
39 : };
40 :
41 : } // namespace clangd
42 : } // namespace clang
43 :
44 : #endif
|