@jpoly1219/context-extractor 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/app.d.ts +27 -0
- package/dist/app.js +284 -0
- package/dist/codeql.d.ts +17 -0
- package/dist/codeql.js +1341 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +62 -0
- package/dist/core.d.ts +20 -0
- package/dist/core.js +576 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/main.d.ts +13 -0
- package/dist/main.js +254 -0
- package/dist/ocaml-driver.d.ts +30 -0
- package/dist/ocaml-driver.js +394 -0
- package/dist/ocaml-type-checker.d.ts +52 -0
- package/dist/ocaml-type-checker.js +286 -0
- package/dist/runner.d.ts +1 -0
- package/dist/runner.js +52 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.js +14 -0
- package/dist/typescript-driver.d.ts +27 -0
- package/dist/typescript-driver.js +542 -0
- package/dist/typescript-type-checker.d.ts +64 -0
- package/dist/typescript-type-checker.js +512 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.js +350 -0
- package/package.json +1 -1
@@ -0,0 +1,286 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.OcamlTypeChecker = void 0;
|
4
|
+
const utils_1 = require("./utils");
|
5
|
+
class OcamlTypeChecker {
|
6
|
+
getIdentifierFromDecl(typeDecl) {
|
7
|
+
const declRe = /(type )(.+)( =)(.*)/;
|
8
|
+
const match = typeDecl.match(declRe);
|
9
|
+
if (!match)
|
10
|
+
return "";
|
11
|
+
return match[2];
|
12
|
+
}
|
13
|
+
getTypeContextFromDecl(typeDecl) {
|
14
|
+
if (this.checkHole(typeDecl)) {
|
15
|
+
return this.checkHole(typeDecl);
|
16
|
+
}
|
17
|
+
else if (this.checkParameter(typeDecl)) {
|
18
|
+
return this.checkParameter(typeDecl);
|
19
|
+
}
|
20
|
+
else if (this.checkFunction(typeDecl)) {
|
21
|
+
return this.checkFunction(typeDecl);
|
22
|
+
}
|
23
|
+
else if (this.checkUnion(typeDecl)) {
|
24
|
+
return this.checkUnion(typeDecl);
|
25
|
+
}
|
26
|
+
else if (this.checkObject(typeDecl)) {
|
27
|
+
return this.checkObject(typeDecl);
|
28
|
+
}
|
29
|
+
else if (this.checkImports(typeDecl)) {
|
30
|
+
return this.checkImports(typeDecl);
|
31
|
+
}
|
32
|
+
else if (this.checkModule(typeDecl)) {
|
33
|
+
return this.checkModule(typeDecl);
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return this.checkPrimitive(typeDecl);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
// pattern matching
|
40
|
+
// attempts to match strings to corresponding types, then returns an object containing the name, type span, and an interesting index
|
41
|
+
// base case - type can no longer be stepped into
|
42
|
+
// boolean, number, string, enum, unknown, any, void, null, undefined, never
|
43
|
+
// ideally this should be checked for before we do the for loop
|
44
|
+
// return typeSpan;
|
45
|
+
// check if hover result is from a primitive type
|
46
|
+
checkPrimitive(typeDecl) {
|
47
|
+
// type _ = boolean
|
48
|
+
const primitivePattern = /(type )(.+)( = )(.+)/;
|
49
|
+
const primitiveMatch = typeDecl.match(primitivePattern);
|
50
|
+
let primitiveInterestingIndex = -1;
|
51
|
+
if (primitiveMatch) {
|
52
|
+
primitiveInterestingIndex = (0, utils_1.indexOfRegexGroup)(primitiveMatch, 4);
|
53
|
+
}
|
54
|
+
if (primitiveInterestingIndex != -1) {
|
55
|
+
const typeName = primitiveMatch[2];
|
56
|
+
const typeSpan = primitiveMatch[4];
|
57
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: primitiveInterestingIndex };
|
58
|
+
}
|
59
|
+
return null;
|
60
|
+
}
|
61
|
+
// check if hover result is from an import
|
62
|
+
checkImports(typeDecl) {
|
63
|
+
// import { _, _ };
|
64
|
+
const importPattern = /(import )(\{.+\})/;
|
65
|
+
const importMatch = typeDecl.match(importPattern);
|
66
|
+
let importInterestingIndex = -1;
|
67
|
+
if (importMatch) {
|
68
|
+
importInterestingIndex = (0, utils_1.indexOfRegexGroup)(importMatch, 2);
|
69
|
+
}
|
70
|
+
// import _;
|
71
|
+
const defaultImportPattern = /(import )(.+)/;
|
72
|
+
const defaultImportMatch = typeDecl.match(defaultImportPattern);
|
73
|
+
let defaultImportInterestingIndex = -1;
|
74
|
+
if (defaultImportMatch) {
|
75
|
+
defaultImportInterestingIndex = (0, utils_1.indexOfRegexGroup)(defaultImportMatch, 2);
|
76
|
+
}
|
77
|
+
if (importInterestingIndex != -1) {
|
78
|
+
const typeName = importMatch[2];
|
79
|
+
const typeSpan = importMatch[2];
|
80
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: importInterestingIndex };
|
81
|
+
}
|
82
|
+
else if (defaultImportInterestingIndex != -1) {
|
83
|
+
const typeName = defaultImportMatch[2];
|
84
|
+
const typeSpan = defaultImportMatch[2];
|
85
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: defaultImportInterestingIndex };
|
86
|
+
}
|
87
|
+
return null;
|
88
|
+
}
|
89
|
+
// check if hover result is from a module
|
90
|
+
checkModule(typeDecl) {
|
91
|
+
// module "path/to/module"
|
92
|
+
const modulePattern = /(module )(.+)/;
|
93
|
+
const moduleMatch = typeDecl.match(modulePattern);
|
94
|
+
let moduleInterestingIndex = -1;
|
95
|
+
if (moduleMatch) {
|
96
|
+
moduleInterestingIndex = (0, utils_1.indexOfRegexGroup)(moduleMatch, 2);
|
97
|
+
}
|
98
|
+
if (moduleInterestingIndex != -1) {
|
99
|
+
const typeName = moduleMatch[2];
|
100
|
+
const typeSpan = moduleMatch[2];
|
101
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: moduleInterestingIndex };
|
102
|
+
}
|
103
|
+
return null;
|
104
|
+
}
|
105
|
+
// check if hover result is from an object
|
106
|
+
checkObject(typeDecl) {
|
107
|
+
// type _ = {
|
108
|
+
// _: t1;
|
109
|
+
// _: t2;
|
110
|
+
// }
|
111
|
+
const objectTypeDefPattern = /(type )(.+)( = )(\{.+\})/;
|
112
|
+
const objectTypeDefMatch = typeDecl.match(objectTypeDefPattern);
|
113
|
+
let objectTypeDefInterestingIndex = -1;
|
114
|
+
if (objectTypeDefMatch) {
|
115
|
+
objectTypeDefInterestingIndex = (0, utils_1.indexOfRegexGroup)(objectTypeDefMatch, 4);
|
116
|
+
}
|
117
|
+
if (objectTypeDefInterestingIndex != -1) {
|
118
|
+
const typeName = objectTypeDefMatch[2];
|
119
|
+
const typeSpan = objectTypeDefMatch[4];
|
120
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: objectTypeDefInterestingIndex };
|
121
|
+
}
|
122
|
+
return null;
|
123
|
+
}
|
124
|
+
// check if hover result is from a union
|
125
|
+
checkUnion(typeDecl) {
|
126
|
+
// type _ = A | B | C
|
127
|
+
const unionPattern = /(type )(.+)( = )((.+ | )+.+)/;
|
128
|
+
const unionMatch = typeDecl.match(unionPattern);
|
129
|
+
let unionInterestingIndex = -1;
|
130
|
+
if (unionMatch) {
|
131
|
+
unionInterestingIndex = (0, utils_1.indexOfRegexGroup)(unionMatch, 4);
|
132
|
+
}
|
133
|
+
if (unionInterestingIndex != -1) {
|
134
|
+
const typeName = unionMatch[2];
|
135
|
+
const typeSpan = unionMatch[4];
|
136
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: unionInterestingIndex };
|
137
|
+
}
|
138
|
+
return null;
|
139
|
+
}
|
140
|
+
// check if hover result is from a function
|
141
|
+
checkFunction(typeDecl) {
|
142
|
+
// const myFunc : (arg1: typ1, ...) => _
|
143
|
+
const es6AnnotatedFunctionPattern = /(const )(.+)(: )(\(.+\) => .+)/;
|
144
|
+
const es6AnnotatedFunctionMatch = typeDecl.match(es6AnnotatedFunctionPattern);
|
145
|
+
let es6AnnotatedFunctionInterestingIndex = -1;
|
146
|
+
if (es6AnnotatedFunctionMatch) {
|
147
|
+
es6AnnotatedFunctionInterestingIndex = (0, utils_1.indexOfRegexGroup)(es6AnnotatedFunctionMatch, 4);
|
148
|
+
}
|
149
|
+
// type _ = (_: t1) => t2
|
150
|
+
const es6FunctionTypeDefPattern = /(type )(.+)( = )(\(.+\) => .+)/;
|
151
|
+
const es6FunctionTypeDefPatternMatch = typeDecl.match(es6FunctionTypeDefPattern);
|
152
|
+
let es6FunctionTypeDefInterestingIndex = -1;
|
153
|
+
if (es6FunctionTypeDefPatternMatch) {
|
154
|
+
es6FunctionTypeDefInterestingIndex = (0, utils_1.indexOfRegexGroup)(es6FunctionTypeDefPatternMatch, 4);
|
155
|
+
}
|
156
|
+
// function myFunc<T>(args: types, genarg: T): returntype
|
157
|
+
const genericFunctionTypePattern = /(function )(.+)(\<.+\>\(.*\))(: )(.+)/;
|
158
|
+
const genericFunctionTypeMatch = typeDecl.match(genericFunctionTypePattern);
|
159
|
+
let genericFunctionTypeInterestingIndex = -1;
|
160
|
+
if (genericFunctionTypeMatch) {
|
161
|
+
genericFunctionTypeInterestingIndex = (0, utils_1.indexOfRegexGroup)(genericFunctionTypeMatch, 3);
|
162
|
+
}
|
163
|
+
// function myFunc(args: types): returntype
|
164
|
+
const functionTypePattern = /(function )(.+)(\(.*\))(: )(.+)/;
|
165
|
+
const functionTypeMatch = typeDecl.match(functionTypePattern);
|
166
|
+
let functionTypeInterestingIndex = -1;
|
167
|
+
if (functionTypeMatch) {
|
168
|
+
functionTypeInterestingIndex = (0, utils_1.indexOfRegexGroup)(functionTypeMatch, 3);
|
169
|
+
}
|
170
|
+
if (es6AnnotatedFunctionInterestingIndex != -1) {
|
171
|
+
const typeName = es6AnnotatedFunctionMatch[2];
|
172
|
+
const typeSpan = es6AnnotatedFunctionMatch[4];
|
173
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: es6AnnotatedFunctionInterestingIndex };
|
174
|
+
}
|
175
|
+
else if (es6FunctionTypeDefInterestingIndex != -1) {
|
176
|
+
const typeName = es6FunctionTypeDefPatternMatch[2];
|
177
|
+
const typeSpan = es6FunctionTypeDefPatternMatch[4];
|
178
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: es6FunctionTypeDefInterestingIndex };
|
179
|
+
}
|
180
|
+
else if (genericFunctionTypeInterestingIndex != -1) {
|
181
|
+
const typeName = genericFunctionTypeMatch[2];
|
182
|
+
const typeSpan = genericFunctionTypeMatch[3] + genericFunctionTypeMatch[4] + genericFunctionTypeMatch[5];
|
183
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: genericFunctionTypeInterestingIndex };
|
184
|
+
}
|
185
|
+
else if (functionTypeInterestingIndex != -1) {
|
186
|
+
const typeName = functionTypeMatch[2];
|
187
|
+
const typeSpan = functionTypeMatch[3] + functionTypeMatch[4] + functionTypeMatch[5];
|
188
|
+
return { identifier: typeName, span: typeSpan, interestingIndex: functionTypeInterestingIndex };
|
189
|
+
}
|
190
|
+
return null;
|
191
|
+
}
|
192
|
+
// check if hover result is from a hole
|
193
|
+
checkHole(typeDecl) {
|
194
|
+
// (type parameter) T in _<T>(): T
|
195
|
+
const holePattern = /(\(type parameter\) T in _\<T\>\(\): T)/;
|
196
|
+
const match = typeDecl.match(holePattern);
|
197
|
+
if (match) {
|
198
|
+
const typeName = "hole function";
|
199
|
+
const typeSpan = match[1];
|
200
|
+
return { identifier: typeName, span: typeSpan };
|
201
|
+
}
|
202
|
+
return null;
|
203
|
+
}
|
204
|
+
// check if hover result is from a parameter
|
205
|
+
checkParameter(typeDecl) {
|
206
|
+
// (parameter) name: type
|
207
|
+
// const parameterPattern = /(\(parameter\) )(.+)(: )(.+))/;
|
208
|
+
// const parameterMatch = typeDecl.match(parameterPattern);
|
209
|
+
// let parameterInterestingIndex = -1;
|
210
|
+
// if (parameterMatch) {
|
211
|
+
// parameterInterestingIndex = indexOfRegexGroup(parameterMatch, 4);
|
212
|
+
// }
|
213
|
+
//
|
214
|
+
// if (parameterInterestingIndex != -1) {
|
215
|
+
// const typeName = parameterMatch[2];
|
216
|
+
// const typeSpan = parameterMatch[4];
|
217
|
+
// return { typeName: typeName, typeSpan: typeSpan, interestingIndex: parameterInterestingIndex }
|
218
|
+
// }
|
219
|
+
return null;
|
220
|
+
}
|
221
|
+
isTuple(typeSpan) {
|
222
|
+
return typeSpan[0] === "[" && typeSpan[typeSpan.length - 1] === "]";
|
223
|
+
}
|
224
|
+
isUnion(typeSpan) {
|
225
|
+
return typeSpan.includes(" | ");
|
226
|
+
}
|
227
|
+
isArray(typeSpan) {
|
228
|
+
return typeSpan.slice(-2) === "[]";
|
229
|
+
}
|
230
|
+
isObject(typeSpan) {
|
231
|
+
return typeSpan[0] === "{" && typeSpan[typeSpan.length - 1] === "}";
|
232
|
+
}
|
233
|
+
// this is a very rudimentary check, so it should be expanded upon
|
234
|
+
isFunction(typeSpan) {
|
235
|
+
return typeSpan.includes("=>");
|
236
|
+
}
|
237
|
+
isPrimitive(typeSpan) {
|
238
|
+
const primitives = ["string", "number", "boolean"];
|
239
|
+
return primitives.includes(typeSpan);
|
240
|
+
}
|
241
|
+
isTypeAlias(typeSpan) {
|
242
|
+
const caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
243
|
+
return caps.includes(typeSpan[0]);
|
244
|
+
}
|
245
|
+
escapeQuotes(typeSpan) {
|
246
|
+
return typeSpan.replace(/"/g, `\\"`);
|
247
|
+
}
|
248
|
+
parseTypeArrayString(typeStr) {
|
249
|
+
// Remove all spaces
|
250
|
+
const cleaned = typeStr.replace(/\s/g, '');
|
251
|
+
// Remove the outermost square brackets
|
252
|
+
const inner = cleaned.slice(1, -1);
|
253
|
+
// const inner = cleaned.slice(-1) === ";" ? cleaned.slice(1, -2) : cleaned.slice(1, -1);
|
254
|
+
// Split the string, respecting nested structures
|
255
|
+
const result = [];
|
256
|
+
let currentItem = '';
|
257
|
+
let nestLevel = 0;
|
258
|
+
for (const char of inner) {
|
259
|
+
if (char === '[')
|
260
|
+
nestLevel++;
|
261
|
+
if (char === ']')
|
262
|
+
nestLevel--;
|
263
|
+
if (char === ',' && nestLevel === 0) {
|
264
|
+
// check if currentItem is a name: type pair or just type
|
265
|
+
if (currentItem.includes(":")) {
|
266
|
+
result.push(currentItem.split(":")[1]);
|
267
|
+
}
|
268
|
+
else {
|
269
|
+
result.push(currentItem);
|
270
|
+
}
|
271
|
+
currentItem = '';
|
272
|
+
}
|
273
|
+
else {
|
274
|
+
currentItem += char;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
if (currentItem.includes(":")) {
|
278
|
+
result.push(currentItem.split(":")[1]);
|
279
|
+
}
|
280
|
+
else {
|
281
|
+
result.push(currentItem);
|
282
|
+
}
|
283
|
+
return result;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
exports.OcamlTypeChecker = OcamlTypeChecker;
|
package/dist/runner.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/runner.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const main_1 = require("./main");
|
4
|
+
const types_1 = require("./types");
|
5
|
+
// extract("/home/jacob/projects/context-extractor/targets/todo/sketch.ts").then(r => console.log("todo\n", r));
|
6
|
+
// extract("/home/jacob/projects/context-extractor/targets/playlist/sketch.ts").then(r => console.log("playlist\n", r));
|
7
|
+
// extract("/home/jacob/projects/context-extractor/targets/passwords/sketch.ts").then(r => console.log("passwords\n", r));
|
8
|
+
// extract("/home/jacob/projects/context-extractor/targets/booking/sketch.ts").then(r => console.log("booking\n", r));
|
9
|
+
// extract("/home/jacob/projects/context-extractor/targets/emojipaint/sketch.ts").then(r => console.log("emojipaint\n", r));
|
10
|
+
(async () => {
|
11
|
+
try {
|
12
|
+
const x = await (0, main_1.extractContext)(types_1.Language.TypeScript, "/home/jacob/projects/context-extractor/targets/todo/sketch.ts", "/home/jacob/projects/context-extractor/targets/todo/");
|
13
|
+
console.dir(x, { depth: null });
|
14
|
+
// const y = await completeWithLLM(
|
15
|
+
// x!,
|
16
|
+
// Language.TypeScript,
|
17
|
+
// "/home/jacob/projects/context-extractor/targets/todo/sketch.ts",
|
18
|
+
// "/home/jacob/projects/context-extractor/credentials.json"
|
19
|
+
// )
|
20
|
+
//
|
21
|
+
// console.dir(y)
|
22
|
+
// const y = await extractContext(
|
23
|
+
// Language.OCaml,
|
24
|
+
// "/home/jacob/projects/context-extractor/targets/ocaml/todo/sketch.ml",
|
25
|
+
// "/home/jacob/projects/context-extractor/targets/ocaml/todo/",
|
26
|
+
// "/home/jacob/projects/context-extractor/config.json"
|
27
|
+
// );
|
28
|
+
// console.dir(y, { depth: null })
|
29
|
+
}
|
30
|
+
catch (err) {
|
31
|
+
console.log("top level err: ", err);
|
32
|
+
}
|
33
|
+
finally {
|
34
|
+
// Debug active handles if the app doesn't terminate
|
35
|
+
// if ((process as any)._getActiveHandles().length > 0) {
|
36
|
+
// // console.log(`${(process as any)._getActiveHandles().length} active handles detected:`);
|
37
|
+
// // console.log((process as any)._getActiveHandles());
|
38
|
+
// console.log(`${(process as any)._getActiveHandles().length} active handles detected.`);
|
39
|
+
// }
|
40
|
+
// process.exit(0);
|
41
|
+
}
|
42
|
+
})();
|
43
|
+
// extractWithNew(Language.TypeScript, "/home/jacob/projects/context-extractor/targets/playlist/sketch.ts", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("playlist\n", r));
|
44
|
+
// extractWithNew(Language.TypeScript, "/home/jacob/projects/context-extractor/targets/passwords/sketch.ts", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("passwords\n", r));
|
45
|
+
// extractWithNew(Language.TypeScript, "/home/jacob/projects/context-extractor/targets/booking/sketch.ts", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("booking\n", r));
|
46
|
+
// extractWithNew(Language.TypeScript, "/home/jacob/projects/context-extractor/targets/emojipaint/sketch.ts", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("emojipaint\n", r));
|
47
|
+
// extractWithNew(Language.OCaml, "/home/jacob/projects/context-extractor/targets/ocaml/todo/sketch.ml", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("todo\n", r));
|
48
|
+
// extractWithNew(Language.OCaml, "/home/jacob/projects/context-extractor/targets/ocaml/playlist/sketch.ml", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("playlist\n", r));
|
49
|
+
// extractWithNew(Language.OCaml, "/home/jacob/projects/context-extractor/targets/ocaml/passwords/sketch.ml", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("passwords\n", r));
|
50
|
+
// extractWithNew(Language.OCaml, "/home/jacob/projects/context-extractor/targets/ocaml/booking/sketch.ml", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("booking\n", r));
|
51
|
+
// extractWithNew(Language.OCaml, "/home/jacob/projects/context-extractor/targets/ocaml/emojipaint/sketch.ml", "/home/jacob/projects/context-extractor/credentials.json").then(r => console.log("emojipaint\n", r));
|
52
|
+
// extractWithNew(Language.TypeScript, "/app/targets/todo/sketch.ts").then(r => console.log("todo\n", r));
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
import { LspClient } from "../ts-lsp-client-dist/src/lspClient";
|
2
|
+
import { Range } from "../ts-lsp-client-dist/src/models";
|
3
|
+
interface relevantTypeObject {
|
4
|
+
typeAliasDeclaration: string;
|
5
|
+
typeName: string;
|
6
|
+
typeDefinition: string;
|
7
|
+
typeQLClass: string;
|
8
|
+
components: typesObject[];
|
9
|
+
}
|
10
|
+
interface varsObject {
|
11
|
+
constDeclaration: string;
|
12
|
+
bindingPattern: string;
|
13
|
+
typeAnnotation: string;
|
14
|
+
init: string;
|
15
|
+
typeQLClass: string;
|
16
|
+
functionReturnType: string;
|
17
|
+
functionReturnTypeQLClass: string;
|
18
|
+
components: typesObject[];
|
19
|
+
}
|
20
|
+
interface typesObject {
|
21
|
+
typeName: string;
|
22
|
+
typeQLClass: string;
|
23
|
+
}
|
24
|
+
interface typeAndLocation {
|
25
|
+
typeName: string;
|
26
|
+
locatedFile: string;
|
27
|
+
}
|
28
|
+
interface relevantTypeQueryResult {
|
29
|
+
"#select": {
|
30
|
+
tuples: [{
|
31
|
+
label: string;
|
32
|
+
}, string, {
|
33
|
+
label: string;
|
34
|
+
}, string, {
|
35
|
+
label: string;
|
36
|
+
}, string][];
|
37
|
+
};
|
38
|
+
}
|
39
|
+
interface varsQueryResult {
|
40
|
+
"#select": {
|
41
|
+
tuples: [{
|
42
|
+
label: string;
|
43
|
+
}, {
|
44
|
+
label: string;
|
45
|
+
}, {
|
46
|
+
label: string;
|
47
|
+
}, {
|
48
|
+
label: string;
|
49
|
+
}, string, string, string, {
|
50
|
+
label: string;
|
51
|
+
}, string][];
|
52
|
+
};
|
53
|
+
}
|
54
|
+
interface typesQueryResult {
|
55
|
+
"#select": {
|
56
|
+
tuples: [string, string, number][];
|
57
|
+
};
|
58
|
+
}
|
59
|
+
interface typesAndLocationsQueryResult {
|
60
|
+
"#select": {
|
61
|
+
tuples: [string, string][];
|
62
|
+
};
|
63
|
+
}
|
64
|
+
interface LanguageDriver {
|
65
|
+
init: (lspClient: LspClient, sketchPath: string) => Promise<void>;
|
66
|
+
getHoleContext: (lspClient: LspClient, sketchFilePath: string) => Promise<{
|
67
|
+
fullHoverResult: string;
|
68
|
+
functionName: string;
|
69
|
+
functionTypeSpan: string;
|
70
|
+
linePosition: number;
|
71
|
+
characterPosition: number;
|
72
|
+
holeTypeDefLinePos: number;
|
73
|
+
holeTypeDefCharPos: number;
|
74
|
+
range: Range;
|
75
|
+
source: string;
|
76
|
+
}>;
|
77
|
+
extractRelevantTypes: (lspClient: LspClient, fullHoverResult: string, typeName: string, startLine: number, endLine: number, foundSoFar: Map<string, TypeSpanAndSourceFile>, currentFile: string) => Promise<Map<string, TypeSpanAndSourceFile>>;
|
78
|
+
extractRelevantHeaders: (lspClient: LspClient, sources: string[], relevantTypes: Map<string, TypeSpanAndSourceFile>, holeType: string) => Promise<Set<TypeSpanAndSourceFile>>;
|
79
|
+
}
|
80
|
+
type Filepath = string;
|
81
|
+
type RelevantType = string;
|
82
|
+
type RelevantHeader = string;
|
83
|
+
interface Context {
|
84
|
+
holeType: string;
|
85
|
+
relevantTypes: Map<Filepath, RelevantType[]>;
|
86
|
+
relevantHeaders: Map<Filepath, RelevantHeader[]>;
|
87
|
+
}
|
88
|
+
declare enum Language {
|
89
|
+
TypeScript = 0,
|
90
|
+
OCaml = 1
|
91
|
+
}
|
92
|
+
interface TypeChecker {
|
93
|
+
getTypeContextFromDecl: (typeDecl: string) => {
|
94
|
+
identifier: string;
|
95
|
+
span: string;
|
96
|
+
} | null;
|
97
|
+
}
|
98
|
+
interface TypeSpanAndSourceFile {
|
99
|
+
typeSpan: string;
|
100
|
+
sourceFile: string;
|
101
|
+
}
|
102
|
+
declare enum Model {
|
103
|
+
None = 0,
|
104
|
+
GPT4 = "gpt4",
|
105
|
+
Starcoder2 = "starcoder2"
|
106
|
+
}
|
107
|
+
interface LLMConfig {
|
108
|
+
model: Model;
|
109
|
+
}
|
110
|
+
interface GPT4Config extends LLMConfig {
|
111
|
+
apiBase: string;
|
112
|
+
deployment: string;
|
113
|
+
gptModel: string;
|
114
|
+
apiVersion: string;
|
115
|
+
apiKey: string;
|
116
|
+
temperature: number;
|
117
|
+
}
|
118
|
+
interface GPT4PromptComponent {
|
119
|
+
role: string;
|
120
|
+
content: string;
|
121
|
+
}
|
122
|
+
interface TypeAnalysis {
|
123
|
+
kind: string;
|
124
|
+
text: string;
|
125
|
+
constituents?: TypeAnalysis[];
|
126
|
+
parameters?: ParameterAnalysis[];
|
127
|
+
returnType?: TypeAnalysis;
|
128
|
+
heritage?: TypeAnalysis[][];
|
129
|
+
}
|
130
|
+
interface ParameterAnalysis {
|
131
|
+
name: string;
|
132
|
+
optional: boolean;
|
133
|
+
type: TypeAnalysis;
|
134
|
+
}
|
135
|
+
export { relevantTypeObject, varsObject, typesObject, typeAndLocation, relevantTypeQueryResult, varsQueryResult, typesQueryResult, typesAndLocationsQueryResult, LanguageDriver, Language, TypeChecker, TypeSpanAndSourceFile, Context, Model, LLMConfig, GPT4Config, GPT4PromptComponent, TypeAnalysis, ParameterAnalysis };
|
package/dist/types.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Model = exports.Language = void 0;
|
4
|
+
var Language;
|
5
|
+
(function (Language) {
|
6
|
+
Language[Language["TypeScript"] = 0] = "TypeScript";
|
7
|
+
Language[Language["OCaml"] = 1] = "OCaml";
|
8
|
+
})(Language || (exports.Language = Language = {}));
|
9
|
+
var Model;
|
10
|
+
(function (Model) {
|
11
|
+
Model[Model["None"] = 0] = "None";
|
12
|
+
Model["GPT4"] = "gpt4";
|
13
|
+
Model["Starcoder2"] = "starcoder2";
|
14
|
+
})(Model || (exports.Model = Model = {}));
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { LspClient, Range } from "../ts-lsp-client-dist/src/main";
|
2
|
+
import { LanguageDriver, TypeSpanAndSourceFile } from "./types";
|
3
|
+
import { TypeScriptTypeChecker } from "./typescript-type-checker";
|
4
|
+
export declare class TypeScriptDriver implements LanguageDriver {
|
5
|
+
typeChecker: TypeScriptTypeChecker;
|
6
|
+
init(lspClient: LspClient, sketchPath: string): Promise<void>;
|
7
|
+
getHoleContext(lspClient: LspClient, sketchFilePath: string): Promise<{
|
8
|
+
fullHoverResult: string;
|
9
|
+
functionName: string;
|
10
|
+
functionTypeSpan: string;
|
11
|
+
linePosition: number;
|
12
|
+
characterPosition: number;
|
13
|
+
holeTypeDefLinePos: number;
|
14
|
+
holeTypeDefCharPos: number;
|
15
|
+
range: Range;
|
16
|
+
source: string;
|
17
|
+
}>;
|
18
|
+
extractRelevantTypes(lspClient: LspClient, fullHoverResult: string, typeName: string, startLine: number, endLine: number, foundSoFar: Map<string, TypeSpanAndSourceFile>, // identifier -> [full hover result, source]
|
19
|
+
currentFile: string): Promise<Map<string, TypeSpanAndSourceFile>>;
|
20
|
+
extractRelevantHeaders(_: LspClient, sources: string[], relevantTypes: Map<string, TypeSpanAndSourceFile>, holeType: string): Promise<Set<TypeSpanAndSourceFile>>;
|
21
|
+
generateTargetTypes(relevantTypes: Map<string, TypeSpanAndSourceFile>, holeType: string): Set<string>;
|
22
|
+
generateTargetTypesHelper(relevantTypes: Map<string, TypeSpanAndSourceFile>, currType: string, targetTypes: Set<string>): void;
|
23
|
+
extractRelevantHeadersHelper(typeSpan: string, targetTypes: Set<string>, relevantTypes: Map<string, TypeSpanAndSourceFile>, relevantContext: Set<TypeSpanAndSourceFile>, line: string, source: string): void;
|
24
|
+
isTypeEquivalent(t1: string, t2: string, relevantTypes: Map<string, TypeSpanAndSourceFile>): boolean;
|
25
|
+
normalize(typeSpan: string, relevantTypes: Map<string, TypeSpanAndSourceFile>): string;
|
26
|
+
normalize2(typeSpan: string, relevantTypes: Map<string, TypeSpanAndSourceFile>): string;
|
27
|
+
}
|