AST and Language Service Plugin

Viewed 13

I would like to create a vscode extension which can help with unit testing and "live" debugging.

Lets say you have the following code:

/*1*/ export class Test {
/*2*/   public add(a: any, b: any): any {
/*3*/     return a + b;
/*4*/   }
/*5*/ }

Live debugging:
New option in the context menu to test the add function (e.g. something similar to current Peek Definition) where you can provide the function input and check the output in a new smaller editor.

Unit test generation:
After you wrote an input and checked the output you can simply generate a new unit test from it.

Now I'm only at the beginning of this project but it seems like getting type information is much more complicated than I expected.
First I would like to get some simple type information (based on cursor position) e.g.:

  • Line 1 is a class
  • Line 2-4 is a function
  • Line 5 is a class

After hours of Google search I think what I have to do is to implement my own TypeScript Language Service Plugin and use it somehow in my extension.

My questions:

  1. Is there any extension similar to my idea which I could use?
  2. Is there an easier way to get the type information I need?
  3. Am I on a right track at all?
  4. Do you have some material about how to use this language service plugin from extension?

P.S. I know that it won't be easy (e.g. several states with different visibility), but good practice for a home project.

0 Answers
Related