I'm interested in getting SourceKit running in an environment where necessary build files (e.g. source files, the stdlib binaries, other binary dependencies), are not actually on the real local filesystem.
clangd has a mechanism for dealing with this: When you start a ClangdServer, you can specify a custom FileSystemProvider implementation, and then clangd reads all files through that. The implementation can go do whatever it wants to fetch the files.
I wasn't able to find a similar mechanism in SourceKit. Would it make sense to add such a mechanism?
For example, would it make sense to add a "FileSystemProvider" argument to sourcekitd::initialize(), so that anyone can compile a SourceKit with custom file fetching logic by simply modifying the call to sourcekitd::initialize()?
The complicated part would be to get a FileSystemProvider through all the Swift compiler APIs and its use of Clang, the sourcekitd part is the easy one I think.
I did play around a bit with that, and I think there aren't too many places to change.
SourceKit reads files in two places in SwiftASTManager.cpp: getBufferStamp and getMemoryBuffer. These can easily be modified to use the passed-in FS.
Swift gets a FileSystem here, and appears to use that for all its file reading. CompilerInstance could probably be modified to accept a FileSystem from SourceKit.
I'm going to prepare an actual PR for this to make it more concrete and to see what people think about it. I expect it to be pretty small.
Another thing that I might want is a mechanism like clangd's context so that I can propagate per-request data into the custom filesystem implementation. I'm not completely sure if I'll need this, and I won't put it in my initial PR.
@akyrtzi I would really appreciate if you took a look and commented and let me know if you think this is something that I could pursue to completion and merge into master!