Skip to content

LS-Plugin: what to use for filesystem IO #28937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajafff opened this issue Dec 10, 2018 · 3 comments
Closed

LS-Plugin: what to use for filesystem IO #28937

ajafff opened this issue Dec 10, 2018 · 3 comments
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code

Comments

@ajafff
Copy link
Contributor

ajafff commented Dec 10, 2018

I'm currently writing a LanguageService plugin.
I need read access to the file system and probably a bit of file watching in this plugin. I don't want to use Node's fs module directly to allow execution in other environments.
So I looked for existing abstractions to do FileSystem IO. Here's what I found out so far:

PluginCreateInfo.serverHost: the host of all hosts, accesses the file system directly
PluginCreateInfo.project: uses a CachedDirectoryStructureHost to allow file system reads, doesn't support watching
PluginCreateInfo.languageServiceHost: the same as PluginCreateInfo.project in the default implementation? with a lot of optional methods so not really pleasant to use

When using ServerHost for file watching I need to clean up after myself when my plugin is disposed?

Are the assumptions above correct? Is there some kind of documentation how this all works together (other than looking at the code)?

@weswigham weswigham added Question An issue which isn't directly actionable in code API Relates to the public API for TypeScript labels Dec 10, 2018
@weswigham
Copy link
Member

@sheetalkamat do you know if we have a doc page on how the hosts for the plugin/server APIs are related?

@sheetalkamat
Copy link
Member

I dont know if there is documentation around it but ts.sys is our FS abstraction. Other hosts like language service or project arent file system implementers. Eg. Project implements languageServiceHost so it doesn't need watch implementation. it internally does watch depending on what kind of languageServiceHost commands take place. (eg. from program watching missing files etc)

@ajafff
Copy link
Contributor Author

ajafff commented Dec 18, 2018

Thank you for the insights. I think I'll try to avoid ts.sys as the ServerHost might use a different means for filesystem access.
My current approach is using Project where possible and falling back to ServerHost for watching.

@ajafff ajafff closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants