refactor: simplify hosts to directly assign tsModule.sys
where possible
#349
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.
Summary
Simplify host files with
public func = tsModules.sys.func
where possibleDetails
no need to duplicate types this way, which can and have changed over time (some of the function args have more parameters etc now actually) -- it's always the same typings this way
also reorganize
host.ts
to have similar categories of functions near each other, instead of a mix of functions whereverhost.ts
as wellshrink the code a bit this way too
add a comment about
getDefaultLibFileName
's confusing naming pointing to the TS issues about how this is an old mistake but changing it now would be breaking (LanguageServiceHost.getDefaultLibFileName
is confusing microsoft/TypeScript#35318)this is also how the TS Wiki recommends setting up hosts
tsproxy
works to support alternate TS implementations, this does require thattsModule
exists at the time of instantiation, i.e. thatsetTypescriptModule
has already been calledhost.ts
,LanguageServiceHost
is only instantiated aftersetTypescriptModule
, but fordiagnostics-format-host.ts
, it is immediately instantiated (at the bottom of the file), hence whygetCurrentDirectory
can't just be assigned totsModule.sys
index.ts
and then passing it as an argument -- would want to refactor more at that point too, so leaving that out for now in this otherwise small, isolated refactorhost.trace
tests have to mockconsole
instead of justconsole.log
, sincetrace
would just be set to the old, unmockedconsole.log
otherwiseconsole.log
now