Skip to content

Commit

Permalink
Hide signature help inside callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
RblSb committed Oct 28, 2024
1 parent c54db13 commit dbb7ef1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src/haxeLanguageServer/features/haxe/SignatureHelpFeature.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import haxe.display.Display.SignatureInformation as HaxeSignatureInformation;
import haxe.display.Display.SignatureItem as HaxeSignatureItem;
import haxe.display.JsonModuleTypes.JsonFunctionArgument;
import haxe.extern.EitherType;
import haxeLanguageServer.features.haxe.codeAction.TokenTreeUtils;
import haxeLanguageServer.helper.DocHelper;
import haxeLanguageServer.helper.IdentifierHelper.addNamesToSignatureType;
import haxeLanguageServer.helper.SemVer;
Expand Down Expand Up @@ -39,8 +40,8 @@ class SignatureHelpFeature {
handle(params, token, resolve, reject, doc);
}

function handleJsonRpc(params:SignatureHelpParams, token:CancellationToken, resolve:Null<SignatureHelp>->Void, reject:ResponseError<NoData>->Void,
doc:HaxeDocument) {
function handleJsonRpc(params:SignatureHelpParams, cancellationToken:CancellationToken, resolve:Null<SignatureHelp>->Void,
reject:ResponseError<NoData>->Void, doc:HaxeDocument) {
var wasAutoTriggered = true;
if (context.haxeServer.haxeVersion >= new SemVer(4, 1, 0)) {
final triggerKind = params?.context?.triggerKind;
Expand All @@ -50,13 +51,33 @@ class SignatureHelpFeature {
case ContentChange | Invoked: false;
}
}

/**
close signature hint inside of callback argument scope:
```haxe
foo(0, |(name, age) -> {}|);
```
**/
var token = doc.tokens?.getTokenAtOffset(doc.offsetAt(params.position));
while (token != null) {
final isCall = TokenTreeUtils.isCallPOpen(token);
if (isCall) {
break;
}
final isInFuction = TokenTreeUtils.isFunctionBrOpen(token);
if (isInFuction) {
resolve(null);
return;
}
token = token.parent;
}
final params = {
file: doc.uri.toFsPath(),
contents: doc.content,
offset: context.displayOffsetConverter.characterOffsetToByteOffset(doc.content, doc.offsetAt(params.position)),
wasAutoTriggered: wasAutoTriggered
}
context.callHaxeMethod(DisplayMethods.SignatureHelp, params, token, function(result) {
context.callHaxeMethod(DisplayMethods.SignatureHelp, params, cancellationToken, function(result) {
if (result == null) {
resolve(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import tokentree.TokenTree;

class TokenTreeUtils {
public static function isInFunctionScope(token:TokenTree):Bool {
final brOpen = token.parent ?? return false;
final token = token.parent ?? return false;
return isFunctionBrOpen(token);
}

public static function isFunctionBrOpen(brOpen:TokenTree):Bool {
if (brOpen.tok != BrOpen)
return false;
final name = brOpen.parent ?? return false;
Expand All @@ -16,6 +20,13 @@ class TokenTreeUtils {
return fun.tok.match(Kwd(KwdFunction));
}

public static function isCallPOpen(pOpen:TokenTree):Bool {
if (pOpen.tok != POpen)
return false;
final name = pOpen.parent ?? return false;
return name.tok.match(Const(CIdent(_)));
}

public static function isFunctionArg(token:TokenTree):Bool {
final pOpen = token.parent ?? return false;
if (pOpen.tok != POpen)
Expand Down

0 comments on commit dbb7ef1

Please sign in to comment.