Skip to content

Instantly share code, notes, and snippets.

@phryneas
Last active April 25, 2021 10:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save phryneas/5ff0ed00fca812d3f4f1d18651712706 to your computer and use it in GitHub Desktop.
tsserver
node_modules
import { CommandTypes, QuickInfoRequest, FileRequestArgs, OpenRequest } from "typescript/lib/protocol";
import { resolve } from "path";
import { spawn } from "child_process";
import { createInterface } from "readline";
const fileArgs: FileRequestArgs = {
file: resolve(__dirname, `./test.ts`),
projectFileName: resolve(__dirname, `../tsconfig.json`),
};
const openReq: OpenRequest = {
command: CommandTypes.Open,
type: "request",
seq: 1,
arguments: fileArgs,
};
const infoReq: QuickInfoRequest = {
command: CommandTypes.Quickinfo,
type: "request",
seq: 2,
arguments: {
...fileArgs,
line: 25,
offset: 15,
},
};
async function run() {
const tsserver = spawn(require.resolve("typescript/bin/tsserver"), ["--suppressDiagnosticEvents"], {
stdio: "pipe",
});
if (!tsserver.stdout || !tsserver.stdin) {
throw "x";
}
const rl = createInterface({
input: tsserver.stdout,
});
rl.on("line", (line) => {
if (/^(Content-Length:.*|)$/.test(line)) {
return;
}
const parsed = JSON.parse(line);
if (parsed.type !== "response" || parsed.command !== CommandTypes.Quickinfo) {
return;
}
console.log(parsed);
});
tsserver.stdin.write(JSON.stringify(openReq) + "\r\n");
tsserver.stdin.write(JSON.stringify(infoReq) + "\r\n");
}
run();
yarn run v1.22.10
$ ts-node index.ts
{
seq: 0,
type: 'response',
command: 'quickinfo',
request_seq: 2,
success: true,
body: {
kind: 'const',
kindModifiers: '',
start: { line: 25, offset: 11 },
end: { line: 25, offset: 20 },
displayString: 'const evaluated: {\n' +
' data?: undefined;\n' +
' error?: undefined;\n' +
' fulfilledTimeStamp?: undefined;\n' +
' originalArgs?: undefined;\n' +
' requestId?: undefined;\n' +
' endpointName?: string | undefined;\n' +
' startedTimeStamp?: undefined;\n' +
' status: QueryStatus.uninitialized;\n' +
' isLoading: false;\n' +
' isFetching: false;\n' +
' isSuccess: false;\n' +
' isError: false;\n' +
' isUninitialized: true;\n' +
' refetch: () => void;\n' +
'} | {\n' +
' error?: FetchBaseQueryError | SerializedError | undefined;\n' +
' fulfilledTimeStamp?: number | undefined;\n' +
' originalArgs?: void | undefined;\n' +
' requestId?: string | undefined;\n' +
' endpointName?: string | undefined;\n' +
' startedTimeStamp?: number | undefined;\n' +
' status: QueryStatus;\n' +
' isUninitialized: false;\n' +
' isSuccess: false;\n' +
' isError: false;\n' +
' isLoading: true;\n' +
' isFetching: boolean;\n' +
' data: undefined;\n' +
' refetch: () => void;\n' +
'} | {\n' +
' originalArgs?: void | undefined;\n' +
' requestId?: string | undefined;\n' +
' endpointName?: string | undefined;\n' +
' startedTimeStamp?: number | undefined;\n' +
' status: QueryStatus;\n' +
' isUninitialized: false;\n' +
' isLoading: false;\n' +
' isError: false;\n' +
' isSuccess: true;\n' +
' isFetching: boolean;\n' +
' error: undefined;\n' +
' data: "Result";\n' +
' fulfilledTimeStamp: number;\n' +
' refetch: () => void;\n' +
'} | {\n' +
' data?: "Result" | undefined;\n' +
' fulfilledTimeStamp?: number | undefined;\n' +
' originalArgs?: void | undefined;\n' +
' requestId?: string | undefined;\n' +
' endpointName?: string | undefined;\n' +
' startedTimeStamp?: number | undefined;\n' +
' status: QueryStatus;\n' +
' isUninitialized: false;\n' +
' isLoading: false;\n' +
' isFetching: false;\n' +
' isSuccess: false ...',
documentation: '',
tags: []
}
}
{
"name": "quickinfo",
"version": "1.0.0",
"main": "index.js",
"author": "Lenz Weber",
"license": "MIT",
"dependencies": {
"ts-toolbelt": "^9.6.0",
"typescript": "^4.2.4"
},
"devDependencies": {
"@reduxjs/toolkit": "^1.6.0-alpha.1",
"@types/node": "^14.14.41",
"ts-node": "^9.1.1"
},
"scripts": {
"start": "ts-node index.ts"
}
}
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
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;
const api = createApi({
reducerPath: "apiOne",
baseQuery: fetchBaseQuery({ baseUrl: "/" }),
endpoints: (builder) => ({
test: builder.query<"Result", void>({
query: () => "",
}),
}),
});
const result = api.useTestQuery();
const evaluated = id(result);
quickinfo(evaluated);
if (evaluated.isUninitialized) {
quickinfo(evaluated);
}
if (evaluated.isFetching) {
quickinfo(evaluated);
}
if (evaluated.isSuccess) {
quickinfo(evaluated);
}
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"noErrorTruncation": true
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@babel/runtime@^7.9.2":
version "7.13.17"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.17.tgz#8966d1fc9593bf848602f0662d6b4d0069e3a7ec"
integrity sha512-NCdgJEelPTSh+FEFylhnP1ylq848l1z9t9N0j1Lfbcw0+KXGjsTvUmkxy+voLLXB5SOKMbLLx4jxYliGrYQseA==
dependencies:
regenerator-runtime "^0.13.4"
"@reduxjs/toolkit@^1.6.0-alpha.1":
version "1.6.0-alpha.1"
resolved "https://registry.yarnpkg.com/@reduxjs/toolkit/-/toolkit-1.6.0-alpha.1.tgz#123ceeb152d1491e951b288baf62a1a292d1f62c"
integrity sha512-HqGpLZC0tYv3tO5L1Sben2Elsh1+zIXk/ym9oN00qxpsv8T5xpYFFLRi0R+tQ+ngjy4W5tewOPaS+DRYb+jPPw==
dependencies:
immer "^9.0.1"
redux "^4.1.0"
redux-thunk "^2.3.0"
reselect "^4.0.0"
"@types/node@^14.14.41":
version "14.14.41"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615"
integrity sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
immer@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.1.tgz#1116368e051f9a0fd188c5136b6efb74ed69c57f"
integrity sha512-7CCw1DSgr8kKYXTYOI1qMM/f5qxT5vIVMeGLDCDX8CSxsggr1Sjdoha4OhsP0AZ1UvWbyZlILHvLjaynuu02Mg==
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
redux-thunk@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
redux@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.0.tgz#eb049679f2f523c379f1aff345c8612f294c88d4"
integrity sha512-uI2dQN43zqLWCt6B/BMGRMY6db7TTY4qeHHfGeKb3EOhmOKjU3KdWvNLJyqaHRksv/ErdNH7cFZWg9jXtewy4g==
dependencies:
"@babel/runtime" "^7.9.2"
regenerator-runtime@^0.13.4:
version "0.13.7"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
reselect@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
ts-node@^9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.1.1.tgz#51a9a450a3e959401bda5f004a72d54b936d376d"
integrity sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==
dependencies:
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
ts-toolbelt@^9.6.0:
version "9.6.0"
resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz#50a25426cfed500d4a09bd1b3afb6f28879edfd5"
integrity sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==
typescript@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment