Injecting a custom FileSystem into SourceKit?

(Marc Rasi) #1


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()?

1 Like
(Argyrios Kyrtzidis) #2

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.

(Marc Rasi) #3

I did play around a bit with that, and I think there aren't too many places to change.

I modified those places in my own copy of Swift in a hacky way, and everything seems to work!

1 Like
(Marc Rasi) #4

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.

(Marc Rasi) #5

I have made a simple proof-of-concept PR (with working tests!) that illustrates an approach:

@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!