Virtualizing how `libsyntax` accesses the code base

At the moment libsyntax always loads source code from the file system when it imports a module. All source code loading seems to go through syntax::parse::file_to_filemap(). It should be easy add a CodebaseAccessor to ParseSess to which file_to_filemap() delegates the mapping from file name to source string. How the CodebaseAccessor then provides the source string could be pretty much anything.

One use case for this would be IDE’s which want to use libsyntax/librustc but want to provide it with source file version’s which don’t exist on disk yet.

I hope to get around to implementing this some time but I’d like to get some feedback on the idea first. Also, I haven’t investigated how this would interact with macros loaded from plugins. If someone knows anything about this, I’d be very interested in hearing about it.

Personally I wouldn’t worry about doing this until you have a concrete use for it. The ‘unsaved work’ IDE thing might never happen because libsyntax requires fully parseable code to work. (e.g. this is the reason Racer uses libsyntax to parse small snippets of code rather than full files)

I’ve read somewhere that it wouldn’t take much to make libsyntax more robust in the presence of syntax errors, so this might change in the future.

My use for it, at the moment, is that I want to dabble with creating a “symbol server” in my (sparse) spare time, mostly to see how usable rustc is as a library for such a thing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.