Skip to content

Commit f4cde5a

Browse files
committed
Make utils.runAnalysisAfterSanityCheck async
1 parent df29b18 commit f4cde5a

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

server/src/codeActions.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ let takeUntil = (array: string[], startsWith: string): string[] => {
141141
return res;
142142
};
143143

144-
export let findCodeActionsInDiagnosticsMessage = ({
144+
export let findCodeActionsInDiagnosticsMessage = async ({
145145
diagnostic,
146146
diagnosticMessage,
147147
file,
148148
range,
149149
addFoundActionsHere: codeActions,
150150
}: findCodeActionsConfig) => {
151-
diagnosticMessage.forEach((line, index, array) => {
151+
for (const [index, line] of diagnosticMessage.entries()) {
152152
// Because of how actions work, there can only be one per diagnostic. So,
153153
// halt whenever a code action has been found.
154154
let codeActionExtractors = [
@@ -166,8 +166,8 @@ export let findCodeActionsInDiagnosticsMessage = ({
166166
let didFindAction = false;
167167

168168
try {
169-
didFindAction = extractCodeAction({
170-
array,
169+
didFindAction = await extractCodeAction({
170+
array: diagnosticMessage,
171171
codeActions,
172172
diagnostic,
173173
file,
@@ -183,7 +183,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
183183
break;
184184
}
185185
}
186-
});
186+
}
187187
};
188188

189189
interface codeActionExtractorConfig {
@@ -196,12 +196,12 @@ interface codeActionExtractorConfig {
196196
codeActions: filesCodeActions;
197197
}
198198

199-
type codeActionExtractor = (config: codeActionExtractorConfig) => boolean;
199+
type codeActionExtractor = (config: codeActionExtractorConfig) => Promise<boolean>;
200200

201201
// This action extracts hints the compiler emits for misspelled identifiers, and
202202
// offers to replace the misspelled name with the correct name suggested by the
203203
// compiler.
204-
let didYouMeanAction: codeActionExtractor = ({
204+
let didYouMeanAction: codeActionExtractor = async ({
205205
codeActions,
206206
diagnostic,
207207
file,
@@ -245,7 +245,7 @@ let didYouMeanAction: codeActionExtractor = ({
245245
};
246246

247247
// This action offers to wrap patterns that aren't option in Some.
248-
let wrapInSome: codeActionExtractor = ({
248+
let wrapInSome: codeActionExtractor = async ({
249249
codeActions,
250250
diagnostic,
251251
file,
@@ -425,7 +425,7 @@ let handleUndefinedRecordFieldsAction = ({
425425
// being undefined. We then offers an action that inserts all of the record
426426
// fields, with an `assert false` dummy value. `assert false` is so applying the
427427
// code action actually compiles.
428-
let addUndefinedRecordFieldsV10: codeActionExtractor = ({
428+
let addUndefinedRecordFieldsV10: codeActionExtractor = async ({
429429
array,
430430
codeActions,
431431
diagnostic,
@@ -459,7 +459,7 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
459459
return false;
460460
};
461461

462-
let addUndefinedRecordFieldsV11: codeActionExtractor = ({
462+
let addUndefinedRecordFieldsV11: codeActionExtractor = async ({
463463
array,
464464
codeActions,
465465
diagnostic,
@@ -508,7 +508,7 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
508508

509509
// This action detects suggestions of converting between mismatches in types
510510
// that the compiler tells us about.
511-
let simpleConversion: codeActionExtractor = ({
511+
let simpleConversion: codeActionExtractor = async ({
512512
line,
513513
codeActions,
514514
file,
@@ -554,7 +554,7 @@ let simpleConversion: codeActionExtractor = ({
554554

555555
// This action will apply a curried function (essentially inserting a dot in the
556556
// correct place).
557-
let applyUncurried: codeActionExtractor = ({
557+
let applyUncurried: codeActionExtractor = async ({
558558
line,
559559
codeActions,
560560
file,
@@ -608,7 +608,7 @@ let applyUncurried: codeActionExtractor = ({
608608

609609
// This action detects missing cases for exhaustive pattern matches, and offers
610610
// to insert dummy branches (using `failwith("TODO")`) for those branches.
611-
let simpleAddMissingCases: codeActionExtractor = ({
611+
let simpleAddMissingCases: codeActionExtractor = async ({
612612
line,
613613
codeActions,
614614
file,
@@ -629,7 +629,7 @@ let simpleAddMissingCases: codeActionExtractor = ({
629629

630630
let filePath = fileURLToPath(file);
631631

632-
let newSwitchCode = utils.runAnalysisAfterSanityCheck(filePath, [
632+
let newSwitchCode = await utils.runAnalysisAfterSanityCheck(filePath, [
633633
"codemod",
634634
filePath,
635635
range.start.line,
@@ -665,7 +665,7 @@ let simpleAddMissingCases: codeActionExtractor = ({
665665
// This detects concrete variables or values put in a position which expects an
666666
// optional of that same type, and offers to wrap the value/variable in
667667
// `Some()`.
668-
let simpleTypeMismatches: codeActionExtractor = ({
668+
let simpleTypeMismatches: codeActionExtractor = async ({
669669
line,
670670
codeActions,
671671
file,

server/src/incrementalCompilation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ async function compileContents(
644644
}
645645
// Reset compilation status as this compilation finished
646646
entry.compilation = null;
647-
const { result, codeActions } = utils.parseCompilerLogOutput(
647+
const { result, codeActions } = await utils.parseCompilerLogOutput(
648648
`${stderr}\n#Done()`
649649
);
650650

server/src/server.ts

Lines changed: 6 additions & 6 deletions
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);
105+
} = await utils.parseCompilerLogOutput(content);
106106

107107
if (linesWithParseErrors.length > 0) {
108108
let params: p.ShowMessageParams = {
@@ -192,7 +192,7 @@ let debug = false;
192192
let syncProjectConfigCache = (rootPath: string) => {
193193
try {
194194
if (debug) console.log("syncing project config cache for " + rootPath);
195-
utils.runAnalysisAfterSanityCheck(rootPath, ["cache-project", rootPath]);
195+
await utils.runAnalysisAfterSanityCheck(rootPath, ["cache-project", rootPath]);
196196
if (debug) console.log("OK - synced project config cache for " + rootPath);
197197
} catch (e) {
198198
if (debug) console.error(e);
@@ -202,7 +202,7 @@ let syncProjectConfigCache = (rootPath: string) => {
202202
let deleteProjectConfigCache = (rootPath: string) => {
203203
try {
204204
if (debug) console.log("deleting project config cache for " + rootPath);
205-
utils.runAnalysisAfterSanityCheck(rootPath, ["cache-delete", rootPath]);
205+
await utils.runAnalysisAfterSanityCheck(rootPath, ["cache-delete", rootPath]);
206206
if (debug) console.log("OK - deleted project config cache for " + rootPath);
207207
} catch (e) {
208208
if (debug) console.error(e);
@@ -600,7 +600,7 @@ function rename(msg: p.RequestMessage) {
600600
let params = msg.params as p.RenameParams;
601601
let filePath = fileURLToPath(params.textDocument.uri);
602602
let documentChanges: (p.RenameFile | p.TextDocumentEdit)[] | null =
603-
utils.runAnalysisAfterSanityCheck(filePath, [
603+
await utils.runAnalysisAfterSanityCheck(filePath, [
604604
"rename",
605605
filePath,
606606
params.position.line,
@@ -705,7 +705,7 @@ function completionResolve(msg: p.RequestMessage) {
705705

706706
if (item.documentation == null && item.data != null) {
707707
const data = item.data as { filePath: string; modulePath: string };
708-
let result = utils.runAnalysisAfterSanityCheck(
708+
let result = await utils.runAnalysisAfterSanityCheck(
709709
data.filePath,
710710
["completionResolve", data.filePath, data.modulePath],
711711
true
@@ -851,7 +851,7 @@ let updateDiagnosticSyntax = (fileUri: string, fileContent: string) => {
851851
let compilerDiagnosticsForFile =
852852
getCurrentCompilerDiagnosticsForFile(fileUri);
853853
let syntaxDiagnosticsForFile: p.Diagnostic[] =
854-
utils.runAnalysisAfterSanityCheck(filePath, ["diagnosticSyntax", tmpname]);
854+
await utils.runAnalysisAfterSanityCheck(filePath, ["diagnosticSyntax", tmpname]);
855855

856856
let notification: p.NotificationMessage = {
857857
jsonrpc: c.jsonrpcVersion,

server/src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ if (fs.existsSync(c.builtinAnalysisDevPath)) {
283283
builtinBinaryPath = c.builtinAnalysisProdPath;
284284
}
285285

286-
export let runAnalysisAfterSanityCheck = (
286+
export let runAnalysisAfterSanityCheck = async (
287287
filePath: p.DocumentUri,
288288
args: Array<any>,
289289
projectRequired = false
@@ -294,7 +294,7 @@ export let runAnalysisAfterSanityCheck = (
294294
}
295295
let rescriptVersion =
296296
projectsFiles.get(projectRootPath ?? "")?.rescriptVersion ??
297-
findReScriptVersion(filePath);
297+
await findReScriptVersion(filePath);
298298

299299
let binaryPath = builtinBinaryPath;
300300

@@ -366,7 +366,7 @@ export let runAnalysisCommand = (
366366
msg: RequestMessage,
367367
projectRequired = true
368368
) => {
369-
let result = runAnalysisAfterSanityCheck(filePath, args, projectRequired);
369+
let result = await runAnalysisAfterSanityCheck(filePath, args, projectRequired);
370370
let response: ResponseMessage = {
371371
jsonrpc: c.jsonrpcVersion,
372372
id: msg.id,
@@ -379,7 +379,7 @@ export let getReferencesForPosition = (
379379
filePath: p.DocumentUri,
380380
position: p.Position
381381
) =>
382-
runAnalysisAfterSanityCheck(filePath, [
382+
await runAnalysisAfterSanityCheck(filePath, [
383383
"references",
384384
filePath,
385385
position.line,

0 commit comments

Comments
 (0)