Skip to content

Commit

Permalink
Generate missing constructor args (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
RblSb committed Nov 7, 2023
1 parent 67cacf6 commit 4414205
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ class MissingArgumentsAction {

static function getCallNamePos(document:HaxeDocument, argToken:TokenTree):Null<Range> {
final parent = argToken.access().findParent(helper -> {
return switch (helper!.token!.tok) {
case Const(CIdent(_)): true;
final token = helper?.token ?? return false;
return switch (token.tok) {
case Const(CIdent(_)):
final parent = token.parent ?? return false;
!parent.matches(Kwd(KwdNew));
case Kwd(KwdNew): true;
case _: false;
}
});
Expand Down
37 changes: 37 additions & 0 deletions test/codeActions/AddMissingArgsTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,41 @@ class AddMissingArgsTest extends DisplayTestCase {
});
});
}

/**
function main() {
new Foo({-1-}1{-2-});
}
class Foo {
public function new() {}
}
---
function main() {
new Foo(1);
}
class Foo {
public function new(i:Int) {}
}
**/
@:timeout(500)
function testConstructorArg(async:utest.Async) {
ctx.cacheFile();
ctx.startServer(() -> {
var action:CodeAction = {title: ""};
// diagnostics selects full arg range
final params = codeActionParams(range(1, 2));
final diag = createDiagnostic(range(1, 2));
final action:Null<Promise<CodeAction>> = MissingArgumentsAction.createMissingArgumentsAction(ctx.context, action, params, diag);
assert(action != null);
action.then(action -> {
ctx.removeCacheFile();
applyTextEdit(action.edit);
eq(ctx.result, ctx.doc.content);
async.done();
}, (err) -> {
ctx.removeCacheFile();
throw err;
});
});
}
}

0 comments on commit 4414205

Please sign in to comment.