@jpoly1219/context-extractor 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/app.d.ts +7 -3
- package/dist/src/app.js +304 -101
- package/dist/src/ast.d.ts +6 -0
- package/dist/src/ast.js +80 -0
- package/dist/src/codeql.js +17 -7
- package/dist/src/constants.js +17 -7
- package/dist/src/core.d.ts +0 -1
- package/dist/src/core.js +17 -7
- package/dist/src/main.d.ts +8 -2
- package/dist/src/main.js +51 -13
- package/dist/src/ocaml-driver.d.ts +55 -5
- package/dist/src/ocaml-driver.js +295 -190
- package/dist/src/ocaml-utils/_build/default/test_parser.bc.cjs +194658 -0
- package/dist/src/runner.js +118 -3
- package/dist/src/tree-sitter-files/queries/hole-queries/typescript.scm +36 -0
- package/dist/src/tree-sitter-files/queries/relevant-headers-queries/typescript-get-toplevel-headers.scm +22 -0
- package/dist/src/tree-sitter-files/queries/relevant-types-queries/typescript-extract-identifiers.scm +10 -0
- package/dist/src/tree-sitter-files/queries/relevant-types-queries/typescript-find-typedecl-given-typeidentifier.scm +11 -0
- package/dist/src/tree-sitter-files/wasms/tree-sitter-ocaml.wasm +0 -0
- package/dist/src/tree-sitter-files/wasms/tree-sitter-typescript.wasm +0 -0
- package/dist/src/tree-sitter-files/wasms/tree-sitter.wasm +0 -0
- package/dist/src/tree-sitter.d.ts +40 -0
- package/dist/src/tree-sitter.js +334 -0
- package/dist/src/types.d.ts +79 -9
- package/dist/src/types.js +1 -6
- package/dist/src/typescript-driver.d.ts +81 -13
- package/dist/src/typescript-driver.js +1150 -237
- package/dist/src/typescript-type-checker.d.ts +6 -2
- package/dist/src/typescript-type-checker.js +222 -10
- package/dist/src/utils.d.ts +11 -1
- package/dist/src/utils.js +87 -10
- package/dist/src/vscode-ide.d.ts +29 -0
- package/dist/src/vscode-ide.js +161 -0
- package/package.json +12 -6
package/dist/src/ocaml-driver.js
CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
36
|
exports.OcamlDriver = void 0;
|
27
37
|
const fs = __importStar(require("fs"));
|
@@ -35,230 +45,322 @@ class OcamlDriver {
|
|
35
45
|
this.typeChecker = new ocaml_type_checker_1.OcamlTypeChecker();
|
36
46
|
}
|
37
47
|
async init(lspClient, sketchPath) {
|
38
|
-
|
39
|
-
|
40
|
-
'
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
'
|
45
|
-
'
|
46
|
-
|
47
|
-
|
48
|
+
if (lspClient) {
|
49
|
+
const capabilities = {
|
50
|
+
'textDocument': {
|
51
|
+
'codeAction': { 'dynamicRegistration': true },
|
52
|
+
'codeLens': { 'dynamicRegistration': true },
|
53
|
+
'colorProvider': { 'dynamicRegistration': true },
|
54
|
+
'completion': {
|
55
|
+
'completionItem': {
|
56
|
+
'commitCharactersSupport': true,
|
57
|
+
'documentationFormat': ['markdown', 'plaintext'],
|
58
|
+
'snippetSupport': true
|
59
|
+
},
|
60
|
+
'completionItemKind': {
|
61
|
+
'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
62
|
+
},
|
63
|
+
'contextSupport': true,
|
64
|
+
'dynamicRegistration': true
|
48
65
|
},
|
49
|
-
'
|
50
|
-
|
66
|
+
'definition': { 'dynamicRegistration': true },
|
67
|
+
'documentHighlight': { 'dynamicRegistration': true },
|
68
|
+
'documentLink': { 'dynamicRegistration': true },
|
69
|
+
'documentSymbol': {
|
70
|
+
'dynamicRegistration': true,
|
71
|
+
'symbolKind': {
|
72
|
+
'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
73
|
+
}
|
51
74
|
},
|
52
|
-
'
|
53
|
-
'
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
'dynamicRegistration': true,
|
60
|
-
'
|
61
|
-
|
62
|
-
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
75
|
+
'formatting': { 'dynamicRegistration': true },
|
76
|
+
'hover': {
|
77
|
+
'contentFormat': ['markdown', 'plaintext'],
|
78
|
+
'dynamicRegistration': true
|
79
|
+
},
|
80
|
+
'implementation': { 'dynamicRegistration': true },
|
81
|
+
// 'inlayhint': { 'dynamicRegistration': true },
|
82
|
+
'onTypeFormatting': { 'dynamicRegistration': true },
|
83
|
+
'publishDiagnostics': { 'relatedInformation': true },
|
84
|
+
'rangeFormatting': { 'dynamicRegistration': true },
|
85
|
+
'references': { 'dynamicRegistration': true },
|
86
|
+
'rename': { 'dynamicRegistration': true },
|
87
|
+
'signatureHelp': {
|
88
|
+
'dynamicRegistration': true,
|
89
|
+
'signatureInformation': { 'documentationFormat': ['markdown', 'plaintext'] }
|
90
|
+
},
|
91
|
+
'synchronization': {
|
92
|
+
'didSave': true,
|
93
|
+
'dynamicRegistration': true,
|
94
|
+
'willSave': true,
|
95
|
+
'willSaveWaitUntil': true
|
96
|
+
},
|
97
|
+
'typeDefinition': { 'dynamicRegistration': true, 'linkSupport': true },
|
98
|
+
// 'typeHierarchy': { 'dynamicRegistration': true }
|
68
99
|
},
|
69
|
-
'
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
100
|
+
'workspace': {
|
101
|
+
'applyEdit': true,
|
102
|
+
'configuration': true,
|
103
|
+
'didChangeConfiguration': { 'dynamicRegistration': true },
|
104
|
+
'didChangeWatchedFiles': { 'dynamicRegistration': true },
|
105
|
+
'executeCommand': { 'dynamicRegistration': true },
|
106
|
+
'symbol': {
|
107
|
+
'dynamicRegistration': true,
|
108
|
+
'symbolKind': {
|
109
|
+
'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
110
|
+
}
|
111
|
+
}, 'workspaceEdit': { 'documentChanges': true },
|
112
|
+
'workspaceFolders': true
|
79
113
|
},
|
80
|
-
'
|
81
|
-
'
|
82
|
-
'dynamicRegistration': true,
|
83
|
-
'willSave': true,
|
84
|
-
'willSaveWaitUntil': true
|
114
|
+
'general': {
|
115
|
+
'positionEncodings': ['utf-8']
|
85
116
|
},
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
'
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
117
|
+
};
|
118
|
+
const rootPath = path.dirname(sketchPath);
|
119
|
+
const rootUri = `file://${rootPath}`;
|
120
|
+
const workspaceFolders = [{ 'name': 'context-extractor', 'uri': rootUri }];
|
121
|
+
await lspClient.initialize({
|
122
|
+
processId: process.pid,
|
123
|
+
capabilities: capabilities,
|
124
|
+
trace: 'off',
|
125
|
+
rootUri: null,
|
126
|
+
workspaceFolders: workspaceFolders,
|
127
|
+
initializationOptions: {
|
128
|
+
preferences: {
|
129
|
+
includeInlayVariableTypeHints: true
|
99
130
|
}
|
100
|
-
}, 'workspaceEdit': { 'documentChanges': true },
|
101
|
-
'workspaceFolders': true
|
102
|
-
},
|
103
|
-
'general': {
|
104
|
-
'positionEncodings': ['utf-8']
|
105
|
-
},
|
106
|
-
};
|
107
|
-
const rootPath = path.dirname(sketchPath);
|
108
|
-
const rootUri = `file://${rootPath}`;
|
109
|
-
const workspaceFolders = [{ 'name': 'context-extractor', 'uri': rootUri }];
|
110
|
-
await lspClient.initialize({
|
111
|
-
processId: process.pid,
|
112
|
-
capabilities: capabilities,
|
113
|
-
trace: 'off',
|
114
|
-
rootUri: null,
|
115
|
-
workspaceFolders: workspaceFolders,
|
116
|
-
initializationOptions: {
|
117
|
-
preferences: {
|
118
|
-
includeInlayVariableTypeHints: true
|
119
131
|
}
|
120
|
-
}
|
121
|
-
}
|
132
|
+
});
|
133
|
+
}
|
134
|
+
}
|
135
|
+
injectHole(sketchPath) {
|
122
136
|
}
|
123
137
|
async getHoleContext(lspClient, sketchFilePath) {
|
124
138
|
const sketchDir = path.dirname(sketchFilePath);
|
125
139
|
const sketchFileContent = fs.readFileSync(sketchFilePath, "utf8");
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
140
|
+
if (lspClient) {
|
141
|
+
// Sync client and server by notifying that the client has opened all the files inside the target directory.
|
142
|
+
fs.readdirSync(sketchDir).map(fileName => {
|
143
|
+
if (fs.lstatSync(path.join(sketchDir, fileName)).isFile()) {
|
144
|
+
const langType = (() => {
|
145
|
+
switch (fileName) {
|
146
|
+
case "dune":
|
147
|
+
return "dune";
|
148
|
+
case "dune-project":
|
149
|
+
return "dune-project";
|
150
|
+
case ".ocamlformat":
|
151
|
+
return ".ocamlformat";
|
152
|
+
default:
|
153
|
+
return "ocaml";
|
154
|
+
}
|
155
|
+
})();
|
156
|
+
lspClient.didOpen({
|
157
|
+
textDocument: {
|
158
|
+
uri: `file://${sketchDir}/${fileName}`,
|
159
|
+
languageId: langType,
|
160
|
+
text: fs.readFileSync(`${sketchDir}/${fileName}`).toString("ascii"),
|
161
|
+
version: 1
|
162
|
+
}
|
163
|
+
});
|
164
|
+
}
|
165
|
+
});
|
166
|
+
// Get hole context.
|
167
|
+
const holeCtx = (await lspClient.ocamlMerlinCallCompatible({
|
168
|
+
uri: `file://${sketchFilePath}`,
|
169
|
+
command: "holes",
|
170
|
+
args: [],
|
171
|
+
resultAsSexp: false
|
172
|
+
}));
|
173
|
+
const sketchSymbol = await lspClient.documentSymbol({
|
174
|
+
textDocument: {
|
175
|
+
uri: `file://${sketchFilePath}`
|
176
|
+
}
|
177
|
+
});
|
178
|
+
return {
|
179
|
+
fullHoverResult: "", //
|
180
|
+
functionName: "_", // _
|
181
|
+
functionTypeSpan: JSON.parse(holeCtx.result).value[0].type, // model * action -> model
|
182
|
+
linePosition: JSON.parse(holeCtx.result).value[0].start.line, // hole's line
|
183
|
+
characterPosition: JSON.parse(holeCtx.result).value[0].start.col, // hole's character
|
184
|
+
holeTypeDefLinePos: 3, //
|
185
|
+
holeTypeDefCharPos: 0, // "
|
186
|
+
range: sketchSymbol[0].location.range,
|
187
|
+
source: `file://${sketchFilePath}`
|
188
|
+
};
|
189
|
+
}
|
190
|
+
else {
|
191
|
+
// TODO: Do vscode things.
|
192
|
+
return {
|
193
|
+
fullHoverResult: "", //
|
194
|
+
functionName: "_", // _
|
195
|
+
functionTypeSpan: "",
|
196
|
+
linePosition: 0,
|
197
|
+
characterPosition: 0,
|
198
|
+
holeTypeDefLinePos: 0, //
|
199
|
+
holeTypeDefCharPos: 0, // "
|
200
|
+
range: {
|
201
|
+
start: {
|
202
|
+
line: 0,
|
203
|
+
character: 0
|
204
|
+
},
|
205
|
+
end: {
|
206
|
+
line: 0,
|
207
|
+
character: 0
|
147
208
|
}
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
command: "holes",
|
155
|
-
args: [],
|
156
|
-
resultAsSexp: false
|
157
|
-
}));
|
158
|
-
const sketchSymbol = await lspClient.documentSymbol({
|
159
|
-
textDocument: {
|
160
|
-
uri: `file://${sketchFilePath}`
|
161
|
-
}
|
162
|
-
});
|
209
|
+
},
|
210
|
+
source: ""
|
211
|
+
};
|
212
|
+
}
|
213
|
+
}
|
214
|
+
async getHoleContextWithCompilerAPI(sketchFilePath, logStream) {
|
163
215
|
return {
|
164
216
|
fullHoverResult: "", //
|
165
217
|
functionName: "_", // _
|
166
|
-
functionTypeSpan:
|
167
|
-
linePosition:
|
168
|
-
characterPosition:
|
169
|
-
holeTypeDefLinePos:
|
218
|
+
functionTypeSpan: "",
|
219
|
+
linePosition: 0,
|
220
|
+
characterPosition: 0,
|
221
|
+
holeTypeDefLinePos: 0, //
|
170
222
|
holeTypeDefCharPos: 0, // "
|
171
|
-
range:
|
172
|
-
|
223
|
+
range: {
|
224
|
+
start: {
|
225
|
+
line: 0,
|
226
|
+
character: 0
|
227
|
+
},
|
228
|
+
end: {
|
229
|
+
line: 0,
|
230
|
+
character: 0
|
231
|
+
}
|
232
|
+
},
|
233
|
+
source: ""
|
234
|
+
};
|
235
|
+
}
|
236
|
+
async getHoleContextWithTreesitter(sketchFilePath, cursorPosition, logStream) {
|
237
|
+
return {
|
238
|
+
fullHoverResult: "", //
|
239
|
+
functionName: "_", // _
|
240
|
+
functionTypeSpan: "",
|
241
|
+
linePosition: 0,
|
242
|
+
characterPosition: 0,
|
243
|
+
holeTypeDefLinePos: 0, //
|
244
|
+
holeTypeDefCharPos: 0, // "
|
245
|
+
range: {
|
246
|
+
start: {
|
247
|
+
line: 0,
|
248
|
+
character: 0
|
249
|
+
},
|
250
|
+
end: {
|
251
|
+
line: 0,
|
252
|
+
character: 0
|
253
|
+
}
|
254
|
+
},
|
255
|
+
source: ""
|
173
256
|
};
|
174
257
|
}
|
175
258
|
async extractRelevantTypes(lspClient, fullHoverResult, typeName, startLine, foundSoFar, currentFile) {
|
176
|
-
if (
|
177
|
-
foundSoFar.
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
uri: currentFile
|
187
|
-
},
|
188
|
-
position: {
|
189
|
-
character: charPos,
|
190
|
-
line: linePos
|
191
|
-
}
|
192
|
-
});
|
193
|
-
if (typeDefinitionResult && typeDefinitionResult instanceof Array && typeDefinitionResult.length != 0) {
|
194
|
-
// Use documentSymbol instead of hover.
|
195
|
-
// This prevents type alias "squashing" done by tsserver.
|
196
|
-
// This also allows for grabbing the entire definition range and not just the symbol range.
|
197
|
-
// PERF: feels like this could be memoized to improve performance.
|
198
|
-
const documentSymbolResult = await lspClient.documentSymbol({
|
259
|
+
if (lspClient) {
|
260
|
+
if (!foundSoFar.has(typeName)) {
|
261
|
+
foundSoFar.set(typeName, { typeSpan: fullHoverResult, sourceFile: currentFile.slice(7) });
|
262
|
+
// outputFile.write(`${fullHoverResult};\n`);
|
263
|
+
const content = fs.readFileSync(currentFile.slice(7), "utf8");
|
264
|
+
for (let linePos = startLine; linePos <= fullHoverResult.length; ++linePos) {
|
265
|
+
const numOfCharsInLine = parseInt((0, child_process_1.execSync)(`wc -m <<< "${content.split("\n")[linePos]}"`, { shell: "/bin/bash" }).toString());
|
266
|
+
for (let charPos = 0; charPos < numOfCharsInLine; ++charPos) {
|
267
|
+
try {
|
268
|
+
const typeDefinitionResult = await lspClient.typeDefinition({
|
199
269
|
textDocument: {
|
200
|
-
uri:
|
270
|
+
uri: currentFile
|
271
|
+
},
|
272
|
+
position: {
|
273
|
+
character: charPos,
|
274
|
+
line: linePos
|
201
275
|
}
|
202
276
|
});
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
const
|
209
|
-
|
210
|
-
|
211
|
-
if (existing.end.line - existing.start.line >= newSymbol.location.range.end.line - newSymbol.location.range.start.line) {
|
212
|
-
return m;
|
277
|
+
if (typeDefinitionResult && typeDefinitionResult instanceof Array && typeDefinitionResult.length != 0) {
|
278
|
+
// Use documentSymbol instead of hover.
|
279
|
+
// This prevents type alias "squashing" done by tsserver.
|
280
|
+
// This also allows for grabbing the entire definition range and not just the symbol range.
|
281
|
+
// PERF: feels like this could be memoized to improve performance.
|
282
|
+
const documentSymbolResult = await lspClient.documentSymbol({
|
283
|
+
textDocument: {
|
284
|
+
uri: typeDefinitionResult[0].uri
|
213
285
|
}
|
214
|
-
|
215
|
-
|
286
|
+
});
|
287
|
+
// grab if the line number of typeDefinitionResult and documentSymbolResult matches
|
288
|
+
// FIX: This overwrites older definitions if the lines are the same. Especially for type constructors, such as playlist_state.
|
289
|
+
// Generally the one that comes first is the largest, but this could be dependent on the source code.
|
290
|
+
const dsMap = documentSymbolResult.reduce((m, obj) => {
|
291
|
+
const newSymbol = obj;
|
292
|
+
const existing = m.get(newSymbol.location.range.start.line);
|
293
|
+
if (existing) {
|
294
|
+
// Compare range between existing doucment symbol and the current symbol.
|
295
|
+
if (existing.end.line - existing.start.line >= newSymbol.location.range.end.line - newSymbol.location.range.start.line) {
|
296
|
+
return m;
|
297
|
+
}
|
298
|
+
else if (existing.end.character - existing.start.character >= newSymbol.location.range.end.character - newSymbol.location.range.start.character) {
|
299
|
+
return m;
|
300
|
+
}
|
216
301
|
}
|
302
|
+
m.set(obj.location.range.start.line, obj.location.range);
|
303
|
+
return m;
|
304
|
+
}, new Map());
|
305
|
+
const matchingSymbolRange = dsMap.get(typeDefinitionResult[0].range.start.line);
|
306
|
+
if (matchingSymbolRange) {
|
307
|
+
const snippetInRange = (0, utils_1.extractSnippet)(fs.readFileSync(typeDefinitionResult[0].uri.slice(7)).toString("utf8"), matchingSymbolRange.start, matchingSymbolRange.end);
|
308
|
+
// TODO: this can potentially be its own method. the driver would require some way to get type context.
|
309
|
+
// potentially, this type checker can be its own class.
|
310
|
+
const identifier = this.typeChecker.getIdentifierFromDecl(snippetInRange);
|
311
|
+
await this.extractRelevantTypes(lspClient, snippetInRange, identifier, matchingSymbolRange.start.line, foundSoFar, typeDefinitionResult[0].uri);
|
217
312
|
}
|
218
|
-
m.set(obj.location.range.start.line, obj.location.range);
|
219
|
-
return m;
|
220
|
-
}, new Map());
|
221
|
-
const matchingSymbolRange = dsMap.get(typeDefinitionResult[0].range.start.line);
|
222
|
-
if (matchingSymbolRange) {
|
223
|
-
const snippetInRange = (0, utils_1.extractSnippet)(fs.readFileSync(typeDefinitionResult[0].uri.slice(7)).toString("utf8"), matchingSymbolRange.start, matchingSymbolRange.end);
|
224
|
-
// TODO: this can potentially be its own method. the driver would require some way to get type context.
|
225
|
-
// potentially, this type checker can be its own class.
|
226
|
-
const identifier = this.typeChecker.getIdentifierFromDecl(snippetInRange);
|
227
|
-
await this.extractRelevantTypes(lspClient, snippetInRange, identifier, matchingSymbolRange.start.line, foundSoFar, typeDefinitionResult[0].uri);
|
228
313
|
}
|
229
314
|
}
|
230
|
-
|
231
|
-
|
232
|
-
|
315
|
+
catch (err) {
|
316
|
+
console.log(`${err}`);
|
317
|
+
}
|
233
318
|
}
|
234
319
|
}
|
235
320
|
}
|
321
|
+
return foundSoFar;
|
322
|
+
}
|
323
|
+
else {
|
324
|
+
// TODO: Do vscode things.
|
325
|
+
return foundSoFar;
|
236
326
|
}
|
327
|
+
}
|
328
|
+
async extractRelevantTypesWithCompilerAPI(fullHoverResult, typeName, linePosition, characterPosition, foundSoFar, currentFile) {
|
329
|
+
return foundSoFar;
|
330
|
+
}
|
331
|
+
async extractRelevantTypesWithTreesitter(lspClient, fullHoverResult, typeName, startLine, foundSoFar, // identifier -> [full hover result, source]
|
332
|
+
currentFile, foundContents, // uri -> contents
|
333
|
+
logStream) {
|
237
334
|
return foundSoFar;
|
238
335
|
}
|
239
336
|
async extractRelevantHeaders(lspClient,
|
240
337
|
// preludeFilePath: string,
|
241
338
|
sources, relevantTypes, holeType) {
|
242
339
|
const relevantContext = new Set();
|
243
|
-
|
244
|
-
const
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
const
|
249
|
-
|
250
|
-
|
251
|
-
|
340
|
+
if (lspClient) {
|
341
|
+
for (const source of sources) {
|
342
|
+
const headerTypeSpans = await this.extractHeaderTypeSpans(lspClient, source);
|
343
|
+
const targetTypes = this.generateTargetTypes(holeType, relevantTypes, source);
|
344
|
+
try {
|
345
|
+
for (const hts of headerTypeSpans) {
|
346
|
+
const recursiveChildTypes = ocamlParser.parse(hts.typeSpan);
|
347
|
+
if (recursiveChildTypes.some((rct) => targetTypes.has(rct))) {
|
348
|
+
relevantContext.add({ typeSpan: (hts.identifier + " : " + hts.typeSpan), sourceFile: source });
|
349
|
+
continue;
|
350
|
+
}
|
351
|
+
this.extractRelevantHeadersHelper(hts.typeSpan, targetTypes, relevantTypes, relevantContext, hts.snippet, source);
|
252
352
|
}
|
253
|
-
|
353
|
+
}
|
354
|
+
catch (err) {
|
355
|
+
return new Set();
|
356
|
+
console.log(err);
|
254
357
|
}
|
255
358
|
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
359
|
+
return relevantContext;
|
360
|
+
}
|
361
|
+
else {
|
362
|
+
return relevantContext;
|
260
363
|
}
|
261
|
-
return relevantContext;
|
262
364
|
}
|
263
365
|
async extractHeaderTypeSpans(lspClient, preludeFilePath) {
|
264
366
|
const docSymbols = await lspClient.documentSymbol({
|
@@ -390,5 +492,8 @@ class OcamlDriver {
|
|
390
492
|
return typeSpan;
|
391
493
|
}
|
392
494
|
}
|
495
|
+
async extractRelevantHeadersWithTreesitter(lspClient, sources, relevantTypes, holeType, holeIdentifier, projectRoot) {
|
496
|
+
return new Set();
|
497
|
+
}
|
393
498
|
}
|
394
499
|
exports.OcamlDriver = OcamlDriver;
|