| Sam McCall | 6316e0d | 2018-07-12 14:49:52 +0000 | [diff] [blame] | 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 | |
| Sam McCall | 6316e0d | 2018-07-12 14:49:52 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 14 | #include "llvm/Support/VirtualFileSystem.h" |
| Sam McCall | 6316e0d | 2018-07-12 14:49:52 +0000 | [diff] [blame] | 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 | 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. |
| Chandler Carruth | d966ce4 | 2018-10-11 08:05:10 +0000 | [diff] [blame] | 28 | virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> |
| 29 | getFileSystem() const = 0; |
| Sam McCall | 6316e0d | 2018-07-12 14:49:52 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | class RealFileSystemProvider : public FileSystemProvider { |
| 33 | public: |
| 34 | // FIXME: returns the single real FS instance, which is not threadsafe. |
| Chandler Carruth | d966ce4 | 2018-10-11 08:05:10 +0000 | [diff] [blame] | 35 | llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> |
| 36 | getFileSystem() const override { |
| Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 37 | return llvm::vfs::getRealFileSystem(); |
| Sam McCall | 6316e0d | 2018-07-12 14:49:52 +0000 | [diff] [blame] | 38 | } |
| 39 | }; |
| 40 | |
| 41 | } // namespace clangd |
| 42 | } // namespace clang |
| 43 | |
| 44 | #endif |