Dice Question Streamline Icon: https://streamlinehq.com

Retrieving typing context and in-scope variables via the TypeScript language server

Develop a general method to retrieve the typing context at a given lexical location, including a complete list of variables in scope, using the TypeScript language server, or specify the necessary protocol extensions to expose this capability robustly for prompt construction.

Information Square Streamline Icon: https://streamlinehq.com

Background

To port their static-retrieval approach from Hazel to TypeScript, the authors attempted to use the TypeScript language server to emulate typed holes and extract relevant static context. While they could recover type information via hover and type-definition queries, they report that obtaining the typing context and a comprehensive list of in-scope variables was not directly supported.

They experimented with alternative methods, including scanning repositories with CodeQL, but did not find a satisfactory general approach. This gap motivated their proposal of ChatLSP, a conservative extension to LSP intended to make static context available to AI assistants.

References

There does not appear to be any direct way of retrieving a typing context given a lexical location, or even a complete list of variables in scope using the TypeScript language server. We experimented with different methods to retrieve relevant headers, including scanning the repository using CodeQL, but were did not find a fully satisfactory general approach.

Statically Contextualizing Large Language Models with Typed Holes (2409.00921 - Blinn et al., 2 Sep 2024) in Subsection “TypeScript Methodology”