Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide signature help inside callbacks #131

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,10 +1,15 @@
package haxeLanguageServer.features.haxe.codeAction;

import tokentree.TokenTree;
import tokentree.utils.TokenTreeCheckUtils;

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 +21,12 @@ class TokenTreeUtils {
return fun.tok.match(Kwd(KwdFunction));
}

public static function isCallPOpen(pOpen:TokenTree):Bool {
if (pOpen.tok != POpen)
return false;
return TokenTreeCheckUtils.getPOpenType(pOpen) == Call;
}

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