Skip to content

Commit d9a761b

Browse files
zthcristianoc
authored andcommitted
explanations for the current diagnostics driven code actions
1 parent 983bdd7 commit d9a761b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

server/src/codeActions.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ interface codeActionExtractorConfig {
133133

134134
type codeActionExtractor = (config: codeActionExtractorConfig) => boolean;
135135

136+
// This action extracts hints the compiler emits for misspelled identifiers, and
137+
// offers to replace the misspelled name with the correct name suggested by the
138+
// compiler.
136139
let didYouMeanAction: codeActionExtractor = ({
137140
codeActions,
138141
diagnostic,
@@ -176,6 +179,10 @@ let didYouMeanAction: codeActionExtractor = ({
176179
return false;
177180
};
178181

182+
// This action handles when the compiler errors on certain fields of a record
183+
// being undefined. We then offers an action that inserts all of the record
184+
// fields, with an `assert false` dummy value. `assert false` is so applying the
185+
// code action actually compiles.
179186
let addUndefinedRecordFields: codeActionExtractor = ({
180187
array,
181188
codeActions,
@@ -281,6 +288,8 @@ let addUndefinedRecordFields: codeActionExtractor = ({
281288
return false;
282289
};
283290

291+
// This action detects suggestions of converting between mismatches in types
292+
// that the compiler tells us about.
284293
let simpleConversion: codeActionExtractor = ({
285294
line,
286295
codeActions,
@@ -325,6 +334,8 @@ let simpleConversion: codeActionExtractor = ({
325334
return false;
326335
};
327336

337+
// This action will apply a curried function (essentially inserting a dot in the
338+
// correct place).
328339
let applyUncurried: codeActionExtractor = ({
329340
line,
330341
codeActions,
@@ -377,6 +388,9 @@ let applyUncurried: codeActionExtractor = ({
377388
return false;
378389
};
379390

391+
// This action detects the compiler erroring when it finds a top level value
392+
// that's not `unit`, and offers to wrap that value in `ignore`, which will make
393+
// it compile.
380394
let topLevelUnitType: codeActionExtractor = ({
381395
line,
382396
codeActions,
@@ -449,6 +463,12 @@ let transformVariant = (variant: string): string | null => {
449463
return text;
450464
};
451465

466+
// This action detects missing cases for exhaustive pattern matches, and offers
467+
// to insert dummy branches (using `assert false`) for those branches. Right now
468+
// it works on single variants/polyvariants with and without payloads. In the
469+
// future it could be made to work on anything the compiler tell us about, but
470+
// the compiler needs to emit proper ReScript in the error messages for that to
471+
// work.
452472
let simpleAddMissingCases: codeActionExtractor = ({
453473
line,
454474
codeActions,
@@ -548,6 +568,9 @@ let simpleAddMissingCases: codeActionExtractor = ({
548568
return false;
549569
};
550570

571+
// This detects concrete variables or values put in a position which expects an
572+
// optional of that same type, and offers to wrap the value/variable in
573+
// `Some()`.
551574
let simpleWrapOptionalWithSome: codeActionExtractor = ({
552575
line,
553576
codeActions,
@@ -609,6 +632,8 @@ let simpleWrapOptionalWithSome: codeActionExtractor = ({
609632
return false;
610633
};
611634

635+
// This detects when an optional is passed into a non optional slot, and offers
636+
// to insert a switch for unwrapping that optional.
612637
let simpleUnwrapOptional: codeActionExtractor = ({
613638
line,
614639
codeActions,

0 commit comments

Comments
 (0)