blob: a39758aed8a0784e784976e40176dafe5523196d [file] [log] [blame]
Sam McCall6316e0d2018-07-12 14:49:52 +00001//===--- 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 McCall6316e0d2018-07-12 14:49:52 +000013#include "llvm/ADT/IntrusiveRefCntPtr.h"
Jonas Devliegherefc514902018-10-10 13:27:25 +000014#include "llvm/Support/VirtualFileSystem.h"
Sam McCall6316e0d2018-07-12 14:49:52 +000015
16namespace clang {
17namespace 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.
21class FileSystemProvider {
22public:
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 Carruthd966ce42018-10-11 08:05:10 +000028 virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
29 getFileSystem() const = 0;
Sam McCall6316e0d2018-07-12 14:49:52 +000030};
31
32class RealFileSystemProvider : public FileSystemProvider {
33public:
34 // FIXME: returns the single real FS instance, which is not threadsafe.
Chandler Carruthd966ce42018-10-11 08:05:10 +000035 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
36 getFileSystem() const override {
Jonas Devliegherefc514902018-10-10 13:27:25 +000037 return llvm::vfs::getRealFileSystem();
Sam McCall6316e0d2018-07-12 14:49:52 +000038 }
39};
40
41} // namespace clangd
42} // namespace clang
43
44#endif