ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Display tern_argument_hints in the popup #47

Closed danihodovic closed 9 years ago

danihodovic commented 9 years ago

Is it possible to display the argument hints and return values in the popup? Right now, the string that displays on the small bottom panel is not very intuitive.

There are two alternatives to this: a) Display the arguments and return values at the same time as the function suggestion is being displayed in the tooltip. b) Display the arguments and return values when the user enters the parenthesis, just like it works now, except that the values are displayed in the status panel.

danihodovic commented 9 years ago

Is this repository being maintained anymore @marijnh

marijnh commented 9 years ago

Which popup are you talking about? As far as I know, Sublime Text does not expose an API for tooltips. If that has changed since the last time I looked at the docs, a pull request that moves the argument hints from the (indeed poorly visible) status bar into a tooltip (on versions of ST that support it) would be very welcome.

(Adding impatient comments after a few days does not help, by the way.)

danihodovic commented 9 years ago

I wasn't impatient, I saw you were active on Github but the activity on this repository looked pretty dead. So I was wondering if you still maintain this, seems like you do.

SublimeCodeIntel (I think Jedi too) display the arguments inside the autocomplete popup. Seeing as you had the functionality there, I assumed you could do the same. Maybe not when the function autocomplete displays, but at least when you enter the parenthesis.

marijnh commented 9 years ago

SublimeCodeIntel appears to be abusing the autocomplete popup to fake a tooltip (see here ). That's clever, but a bit too hacky for me to copy -- I don't know what repercussions it has, and how it can go wrong. It would make a lot of sense for ST to add native tooltips, but there doesn't seem to be much activity in that direction.

So until there's a safe way to do this, or someone with a deep understanding of Sublime Text explains to me how to safely use the completion hack, I'm going to hold back on this.

danihodovic commented 9 years ago

Hey Marjin, thanks for the feedback. If we put the tooltips aside, is it possible to automatically insert best suited function parameters? I know that Tern may miss the type of a parameter or two sometimes, but usually it's stable enough. I think this would greatly benefit in terms of productivity; since if you don't know what a function takes you usually have to go back and forth before entering the parameters.

AnAppAMonth commented 9 years ago

@marijnh How do you think of providing an option to use an output panel (at the bottom of the screen) to display the argument hints? The facelessuser/ScopeHunter plugin uses this technique to display scope hints.

The user can even resize the panel to one-line tall, in which case it looks like a secondary status bar (and sits just above the status bar), but with bigger text, and is dedicated to this purpose instead of being cluttered with lots of information. I haven't found a way to resize the panel programmatically, but the user just needs to do it once and the new size will persist across restarts of ST.

I have modified the plugin to do it this way and I personally like it. In fact I even like it more than the tooltips used in other editors. With the tooltips method, the tooltip often either disappears too soon (so it's gone by the time you type the second argument, for example), or interferes with the code completion popup. With the output panel method, it's always there but doesn't interfere with your typing, it just sits harmlessly at the bottom.

I couldn't live with the current status bar method because it's too small and also it disappears after a few seconds.

I can send a PR if you are interested in this solution. Thanks for TernJS, Javascript coding is different with it.

marijnh commented 9 years ago

@AnAppAMonth I have no idea what kind of panel you're talking about, but it sounds interesting. The emacs plugin also displays argument hints in the status area at the bottom of the screen, which is not as ridiculously tiny in emacs, and it works well there. A pull request would be great.

AnAppAMonth commented 9 years ago

@marijnh I have created a pull request. I have tested (briefly) in both ST2 and 3.

I have to add that since ST only supports displaying a single output panel at a time, so opening another output panel will automatically hide this one, and vice versa. The Find/Replace dialog also uses an output panel, for example. I personally don't find this a problem though.

danihodovic commented 9 years ago

@AnAppAMonth I'm curious to see this implementation. Does it automatically show the panel or do you have to press a key?

AnAppAMonth commented 9 years ago

@dani-h The panel is shown automatically (and hides other panels if any because only one can be shown at a time) when your cursor is placed in the args section (between the brackets) of a function call.

danihodovic commented 9 years ago

I'll try it out

Edit: It seems to be better than the small panel that exists right now (more readable), but I still prefer auto-insertion of arguments when calling a function that has been implemented in Jedi. I'll use your fork for now.

danihodovic commented 9 years ago

@AnAppAMonth If @marijnh decides to pull your changes mention the extra setting "tern_argument_hints_type": "panel || status", in the README.md or make it the default setting.

I wonder if this can be implemented for the dropdown menu as easily.

Edit: Yeah, a quick one liner did the job. So implementing 3 alternatives: current status bar, output panel, and quick panel to show the argument hints would easily be implemented in this plugin without a lot of refactoring.

in render_argument_hints() view.window().show_quick_panel([msg], None)

Edit: after trying the popup panel it seems like a very bad option as it pops up every time you move the cursor.

PixelT commented 9 years ago

Great work! The only thing that is still missing, are put the default arguments in the function / methods (like a placeholder). They can be displayed, and switch to the next using Tab (just like in snippets in ST)

Edit: When display hint in the panel, they could always display short info about current function / method (something like a small API)

danihodovic commented 9 years ago

@PixelT I think that might have to do with the Tern server too. I'm not sure if it has the functionality to parse and save docstrings.

subhaze commented 9 years ago

@dani-h @PixelT @AnAppAMonth ST 3 received a proper tooltip API today and I've a WIP pull request in progress, hopefully this will solve some of the concerns raised on this thread. #61

danihodovic commented 9 years ago

:+1:

marijnh commented 9 years ago

I think #61 resolves this.