-
Notifications
You must be signed in to change notification settings - Fork 315
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
Implement textDocument/signatureHelp #51
Conversation
This feature is only triggered when opening a parentheses at a function call-site. The box disappears as soon as you write the first parameter. We reuse the completion mechanism to find the method symbol and extract the parameter lists.
aa3ba1e
to
fe14433
Compare
I was unable to get this to work. I tried duplicating your success step exactly but when I type Predef.assert(
tailing metaserver.log shows me a request was made, but I don't see any response for it. Not sure if I am looking in the correct places or not.
|
I just updated my Atom plugin to try this out. And it works! Although I'm not sure it's supposed to look like this.. 🤔
@ShaneDelmore you see
and response:
|
Here's what I got with some little changes (laughedelic@0749371). I think (notice that the first parameter is highlighted in bold) Probably you guys don't care much for Atom, but I think it's useful to see how different clients implement these things to stay unbiased. Here's atom-ide-ui docs for this thing. Some relevant implementation details:
|
Nice! does it highlight the second parameter when you get to it? |
No, but it's just not implemented yet as far as I understand. I didn't read the code in details yet, so I'm not sure how exactly it works. |
@laughedelic that weird behavior is due to the fact that signature helper uses code completions to get the symbols of the methods, it works fine as long as you only invoke it on the trigger character |
This will grow tiring very quickly. Is there any chance to use a stable -SNAPSHOT version number outside of CI? |
It grows very tiring to manually update extension.js on every new commit.
Previously we blindly used the offset provided by the client even if that offset didn't point to a trigger character. Now we locate the relevant open paren.
@laughedelic I've fixed the weird behavior for basic cases but to make it handle multiple nested arguments we'll need a slightly more sophisticated solution explained in #52. Now it behaves like this |
I agree. So did you solve it with a9c4cac?
Looks good! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// symbol of `bar` when we want to match against `foo`. | ||
// Related https://github.com/scalameta/language-server/issues/52 | ||
val lastParenOffset = | ||
position.source.content.lastIndexOf('(', position.point) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
SignatureInformation( | ||
label = s"${sym.nameString}${sym.info.toLongString}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.completionsAt(lastParenPosition) | ||
.matchingResults() | ||
.distinct | ||
if member.sym.isMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, we found the first open paren but now we keep a stack of how many open parens are in between. This change makes it possible to return the correct active parameter, as well as filtering out overloads that have too few parameters. This also means we no longer return bogus results when outside of an argument list.
I think I got it working reasonably well now, it tracks the active argument and doesn't return results anymore if you're outside of an argument list! The activeParameter detection is character based so it will count commas inside string literals so that |
@laughedelic great question! I'll take a look, we can try to fallback to the |
That java.lang.StringIndexOutOfBoundsException: String index out of range: -2
java.lang.String.<init>(String.java:196)
scala.tools.nsc.interactive.Global.typeCompletions$1(Global.scala:1217) |
This commit prevents a StringIndexOutOfBounds by triggering a mutative call to `.typedTreeAt` before calling `.completionsAt`. If the completions return no results, which is what happens for `.apply`, we fallback to the symbol of `typedTreeAt`.
Previously, didn't use the open paren offset to find the fallback `.apply` symbol causing a NPE since `.typedTreeAt` returns null on error.
Previously we only returned the primary constructor, which is a bit annoying esp. when dealing with java apis.
Very nice job! These are super useful when paired with autocompletion! A thing I can see improving (for future PRs) is to pretty print the signature. For instance adding a colon between the param list and the result typ |
trait OverloadHack2; implicit object OverloadHack2 extends OverloadHack2 | ||
trait OverloadHack3; implicit object OverloadHack3 extends OverloadHack3 | ||
trait OverloadHack4; implicit object OverloadHack4 extends OverloadHack4 | ||
trait OverloadHack5; implicit object OverloadHack5 extends OverloadHack5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for? If it's for disambiguating the erased signature, can you maybe use DummyImplicit on just one of the targeted signature below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copied from the scalameta test suite where there are 6 targeted
overloads. It seems we don't need any overloads here so we can just remove this.
It works now with (besides different typesetting and no syntax highlighting, which is Atom's fault) It seems that the first parameter list is missing (and brackets around type parameters too). And by the way, what about multiple parameter lists? |
It seems it doesn't matter if we force compilation or not the exception still occurs. Best to catch it for now.
Previously, signature help didn't work for varargs or applications with explicit type parameters. This commit generalizes the open/close trick to work for both brackets and parens, this opens up the possibility to show signature help for type parameters too in the future. Varargs are also special cased since the argument count does not match the length of the method's parameter list.
@laughedelic I got Unfortunately, I couldn't get |
@laughedelic I am not able to reproduce the missing argument list for |
Gonna merge this since we have #55 using the same testing infrastructure |
This feature is only triggered when opening a parentheses at a function
call-site. The box disappears as soon as you write the first parameter.
We reuse the completion mechanism to find the method symbol and extract
the parameter lists.