Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to instrumentalize tsserver to extract evaluated types #5

Open
phryneas opened this issue Apr 18, 2021 · 1 comment
Open

Try to instrumentalize tsserver to extract evaluated types #5

phryneas opened this issue Apr 18, 2021 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@phryneas
Copy link
Owner

phryneas commented Apr 18, 2021

So, essentially we need a new plugin that parses codeblocks like this:

```ts documentation
import { createSlice } from "@reduxjs/toolkit";
import { A } from "ts-toolbelt";

type Id<T> = { [K in keyof T]: T[K] } & {};

declare function withParams<T extends (...args: any[]) => unknown>(fn: T, cb?: (params: Parameters<T>) => void): void;
declare function getParams<T extends (...args: any[]) => unknown>(fn: T): Parameters<T>;
declare function compute<T>(t: T): A.Compute<T, "deep">;
declare function id<T>(t: T): Id<T>;
declare function quickinfo(target: any): void;

withParams(createSlice, ([sliceOptions]) => quickinfo(sliceOptions));

const sliceOptions = id(getParams(createSlice)[0]);
quickinfo(sliceOptions.extraReducers);

```

and displays everything wrapped in quickinfo as nice markdown instead of that codeblock

@phryneas
Copy link
Owner Author

phryneas commented Apr 24, 2021

Did some experiments, can be seen in https://gist.github.com/phryneas/5ff0ed00fca812d3f4f1d18651712706#file-output-log

Basically that (and existing plugins in this repo) are all the building parts - challenges would now be to

  • write a temp file with the docblock contents,
  • include a .d.ts file with definitions for quickinfo & co so that, all those definitions above would not need to be repeated in every codeblock
  • find the right char positions for all quickinfo calls (especially if it is a call like quickinfo(a.b.c), it would need to be the cursor position for .c and
  • instrumentalize tsserver a bit more effective than calling it once per quickinfo request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant