Skip to content

Commit 8ec2efb

Browse files
committed
Revert "Use file content cache for detecting empty record"
This reverts commit 2265806.
1 parent 2265806 commit 8ec2efb

6 files changed

Lines changed: 4 additions & 50 deletions

File tree

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,5 @@
259259
"esbuild": "^0.20.1",
260260
"semver": "^7.3.7",
261261
"typescript": "^4.7.3"
262-
},
263-
"dependencies": {
264-
"vscode-languageserver-textdocument": "^1.0.12"
265262
}
266263
}

server/src/codeActions.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// actions available in the extension, but they are derived via the analysis
33
// OCaml binary.
44
import * as p from "vscode-languageserver-protocol";
5-
import { TextDocument } from "vscode-languageserver-textdocument";
65
import * as utils from "./utils";
76
import { fileURLToPath } from "url";
87

@@ -17,7 +16,6 @@ interface findCodeActionsConfig {
1716
diagnosticMessage: string[];
1817
file: string;
1918
range: p.Range;
20-
fileContentCache: Map<string, string>;
2119
addFoundActionsHere: filesCodeActions;
2220
}
2321

@@ -148,7 +146,6 @@ export let findCodeActionsInDiagnosticsMessage = ({
148146
diagnosticMessage,
149147
file,
150148
range,
151-
fileContentCache,
152149
addFoundActionsHere: codeActions,
153150
}: findCodeActionsConfig) => {
154151
diagnosticMessage.forEach((line, index, array) => {
@@ -177,7 +174,6 @@ export let findCodeActionsInDiagnosticsMessage = ({
177174
index,
178175
line,
179176
range,
180-
fileContentCache,
181177
});
182178
} catch (e) {
183179
console.error(e);
@@ -198,7 +194,6 @@ interface codeActionExtractorConfig {
198194
range: p.Range;
199195
diagnostic: p.Diagnostic;
200196
codeActions: filesCodeActions;
201-
fileContentCache: Map<string, string>;
202197
}
203198

204199
type codeActionExtractor = (config: codeActionExtractorConfig) => boolean;
@@ -324,14 +319,12 @@ let handleUndefinedRecordFieldsAction = ({
324319
file,
325320
range,
326321
diagnostic,
327-
fileContentCache
328322
}: {
329323
recordFieldNames: string[];
330324
codeActions: filesCodeActions;
331325
file: string;
332326
range: p.Range;
333327
diagnostic: p.Diagnostic;
334-
fileContentCache: Map<string, string>;
335328
}) => {
336329
if (recordFieldNames != null) {
337330
codeActions[file] = codeActions[file] || [];
@@ -386,19 +379,8 @@ let handleUndefinedRecordFieldsAction = ({
386379
// Let's put the end brace back where it was (we still have it to the direct right of us).
387380
newText += `${paddingContentEndBrace}`;
388381
} else {
389-
let insertLeadingComma = true
390-
const fileContent = fileContentCache.get(file.replace("file://", ""))
391-
if (fileContent) {
392-
const textDocument = TextDocument.create(file, "text", 0, fileContent)
393-
if (textDocument.getText(range) == "{}") {
394-
insertLeadingComma = false
395-
}
396-
}
397-
398382
// A single line record definition body is a bit easier - we'll just add the new fields on the same line.
399-
if (insertLeadingComma) {
400-
newText += ", ";
401-
}
383+
newText += ", ";
402384
newText += recordFieldNames
403385
.map((fieldName) => `${fieldName}: failwith("TODO")`)
404386
.join(", ");
@@ -439,7 +421,6 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
439421
index,
440422
line,
441423
range,
442-
fileContentCache,
443424
}) => {
444425
if (line.startsWith("Some record fields are undefined:")) {
445426
let recordFieldNames = line
@@ -459,7 +440,6 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
459440
diagnostic,
460441
file,
461442
range,
462-
fileContentCache,
463443
});
464444
}
465445

@@ -474,7 +454,6 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
474454
index,
475455
line,
476456
range,
477-
fileContentCache
478457
}) => {
479458
if (line.startsWith("Some required record fields are missing:")) {
480459
let theLine = line;
@@ -507,7 +486,6 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
507486
diagnostic,
508487
file,
509488
range,
510-
fileContentCache,
511489
});
512490
}
513491

server/src/incrementalCompilation.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,8 @@ async function compileContents(
644644
}
645645
// Reset compilation status as this compilation finished
646646
entry.compilation = null;
647-
648-
const fileContentCache = new Map();
649-
fileContentCache.set(entry.file.incrementalFilePath, fileContent)
650-
651647
const { result, codeActions } = utils.parseCompilerLogOutput(
652-
`${stderr}\n#Done()`,
653-
fileContentCache
648+
`${stderr}\n#Done()`
654649
);
655650

656651
const actions = Object.values(codeActions)[0] ?? [];

server/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ let sendUpdatedDiagnostics = () => {
102102
result: filesAndErrors,
103103
codeActions,
104104
linesWithParseErrors,
105-
} = utils.parseCompilerLogOutput(content, stupidFileContentCache);
105+
} = utils.parseCompilerLogOutput(content);
106106

107107
if (linesWithParseErrors.length > 0) {
108108
let params: p.ShowMessageParams = {

server/src/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,7 @@ type parsedCompilerLogResult = {
509509
linesWithParseErrors: string[];
510510
};
511511
export let parseCompilerLogOutput = (
512-
content: string,
513-
fileContentCache: Map<string, string>
512+
content: string
514513
): parsedCompilerLogResult => {
515514
type parsedDiagnostic = {
516515
code: number | undefined;
@@ -681,7 +680,6 @@ export let parseCompilerLogOutput = (
681680
diagnosticMessage,
682681
file,
683682
range,
684-
fileContentCache,
685683
});
686684

687685
result[file].push(diagnostic);

0 commit comments

Comments
 (0)