Skip to content

Commit 1d46b9f

Browse files
zthcristianoc
authored andcommitted
code action for applying uncurried function call with dot
1 parent 8aa44ac commit 1d46b9f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

server/src/codeActions.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
3030
addUndefinedRecordFields,
3131
simpleConversion,
3232
topLevelUnitType,
33+
applyUncurried,
3334
];
3435

3536
for (let action of actions) {
@@ -294,6 +295,58 @@ let simpleConversion: codeActionExtractor = ({
294295
return false;
295296
};
296297

298+
let applyUncurried: codeActionExtractor = ({
299+
line,
300+
codeActions,
301+
file,
302+
range,
303+
diagnostic,
304+
}) => {
305+
if (
306+
line.startsWith(
307+
"This is an uncurried ReScript function. It must be applied with a dot."
308+
)
309+
) {
310+
const locOfOpenFnParens = {
311+
line: range.end.line,
312+
character: range.end.character + 1,
313+
};
314+
315+
codeActions[file] = codeActions[file] || [];
316+
let codeAction: p.CodeAction = {
317+
title: `Apply uncurried function call with dot`,
318+
edit: {
319+
changes: {
320+
[file]: [
321+
{
322+
range: {
323+
start: locOfOpenFnParens,
324+
end: locOfOpenFnParens,
325+
},
326+
/*
327+
* Turns `fn(123)` into `fn(. 123)`.
328+
*/
329+
newText: `. `,
330+
},
331+
],
332+
},
333+
},
334+
diagnostics: [diagnostic],
335+
kind: p.CodeActionKind.QuickFix,
336+
isPreferred: true,
337+
};
338+
339+
codeActions[file].push({
340+
range,
341+
codeAction,
342+
});
343+
344+
return true;
345+
}
346+
347+
return false;
348+
};
349+
297350
let topLevelUnitType: codeActionExtractor = ({
298351
line,
299352
codeActions,

0 commit comments

Comments
 (0)