DEV Community

Oleksandra
Oleksandra Subscriber

Posted on

My Open-Source Contribution: Adding a feature to typescript-language-server

I recently finished an open-source contribution that I’m actually really proud of. This time, I worked on the typescript-language-server project. I wanted to challenge myself with something more complex than what I normally do, and I came across Issue #956, which asked to support a new tsserver feature called --canUseWatchEvents.

The idea behind the feature is that, in huge TypeScript projects, tsserver ends up watching thousands of files on its own, which can slow things down a lot. Newer versions of TypeScript offer a way for the editor to handle file watching instead, and only tell tsserver when something actually changes. VS Code already does this, but other editors that rely on the language server didn’t have this yet. I thought this would be a medium-level contribution, but it turned out to be a pretty big learning experience for me.

I spent a lot of time trying to understand the codebase: how the language server talks to tsserver, how features are enabled, and how file watchers are registered. To support this feature, in my PR I had to update multiple parts of the project, including: adding a new CLI flag --canUseWatchEvents, passing the flag to tsserver when launching it, handling the new events tsserver sends related to file watching, and forwarding file change events from the editor back to tsserver properly.

I also created a new piece called WatchEventManager, which basically keeps track of what tsserver wants to watch and registers the right file watchers with the editor. Then, when files are created, changed, or deleted, it sends a watchChange message back to tsserver. And if something isn’t supported like an old TypeScript version, everything just falls back to the old behavior, so the change is safe.

I definitely struggled at times, but I learned a lot about how language servers work, so all the time I spent on this wasn’t wasted. Even though the change took longer than I expected, I’m really glad I stuck with it. It feels cool knowing that I was able to take this feature from start to finish. Having some previous experience with open-source definetely helped me feel more confident. At one point, when I realized the feature was much bigger than I first thought, I honestly considered dropping it and finding something easier. But I pushed through, and I’m proud of that.

Now I’m looking forward to the maintainer’s feedback. The codebase is complicated, and seeing what I did right and what I can improve will be really valuable for me as I keep learning and contributing.

Top comments (0)