Allow --watchFactory option that uses user specified plugin for watching files and directories #54012
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this change we allow users to use custom
watchFactory
plugin either on command line or in editorFor plugin writers the plugin is expected to be module that returns the factory with methods to
watchFile
andwatchDirectory
This behaves similar to language service plugin as in user can have this set in
tsconfig.json
inwatchOptions
aswatchFactory
, pass it on command line during batch compilation or set in vscode's globalwatchOptions
From commandline the
watchFactory
options is honored only if running with passing--allowPlugins
flag.watchFactory
option can either be module name to look for or it can bePluginImport
which is object literal with propertyname
that is resolved as name and the object literal is passed on to the factory.The changes in PR include:
watchFactory
inwatchOptions
that takes in eitherstring
orobject literal
. The name of the factory needs to be package name to resolve (just like our LS plugins`watchFile
orwatchDirectory
we look for this resolved module and use the specific function if available.onConfigurationChanged
similar to we call for LS plugins when editor uses protocol to do so.Here are some of the prototypes for
watchFactory
plugins:Watching using parcel watcher: https:/sheetalkamat/typescript-parcel-watcher
With this you can run
tsc --watchFactory typescript-parcel-watcher
or settypescript-parcel-watcher
as option in the vscode's watchOptions preferencesIf using session events and custom command in vscode Changes to vscode to support watchFactory sheetalkamat/vscode#1
You would need the plugin and updated vscode version per PR so that plugin registers custom commands and uses events to communicate through tsserver. You would also need to set watchOptions in vscode preferences to
typescript-vscode-watcher
Watching using vscode extension and plugin https:/sheetalkamat/vscode-tsserver-watcher-plugin
Here the watching happens by creating a separate server connection between plugin and extension to do the vscode native watching. For this you would need extension, plugin and to set
vscode-tsserver-watcher-plugin
aswatchOptions
preferences in vscode. Note that this would also set the plugin as global plugin (which would in turn fail as global plugin since it does not return the LS in as part ofcreate
call. Vscode could make watchFactory extension take a flag in contributes settings that doesnt pass the plugin as global plugin as well. But this is just prototype so.