allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
332 stars 29 forks source link

Add in-memory strict language server #67

Closed heyimalex closed 7 months ago

heyimalex commented 7 months ago

Implementation of approach that I described in #62. TL;DR: Create a strict LanguageService in memory and getSemanticDiagnostics from it for all strict files.

The create method in a plugin returns a LanguageService, and a LanguageService's entire view of the world is through a LanguageServiceHost. By proxying only getCompilationSettings on LanguageServiceHost to add strict: true and creating a new LanguageService from it, we create a perfect mirror of the stock LanguageService but with strict enabled.

Proxying the LanguageServiceHost was more difficult than the language server, as Object.keys(host) did not return all required methods. I tried grabbing the methods to proxy by walking up the prototype chain, but ultimately I couldn't figure it out; every time I'd be missing some other property and get some variant of a "cant access x on undefined" exception in the tsserver logs. Using a Proxy seems to have done the trick, and I'm successfully using this in my work repo now.

I also proxied dispose and cleanupSemanticCache as they seemed important to the LanguageService lifecycle. I have no idea if they're necessary.

kamkry commented 7 months ago

Thank you for your contribution! It's working well on my machine. Can you please bump up the version in your pull request? Great work!

heyimalex commented 7 months ago

Version bumped 👍

KostkaBrukowa commented 7 months ago

Published 2.2.2-beta.4 version with this change

KostkaBrukowa commented 7 months ago

published with 2.3.0 version on npm. Thanks for contribution!!!