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

Completion of enums in switch #292

Closed
ncannasse opened this issue Sep 12, 2018 · 13 comments
Closed

Completion of enums in switch #292

ncannasse opened this issue Sep 12, 2018 · 13 comments

Comments

@ncannasse
Copy link
Member

When completing a switch case, constructors are now correctly inserted which is good:

switch( t ) {
case TInt: ...
case TIns|   --> becomes   case TInst(c|,args):
}

However the cursor seems to be set after the first argument whereas when there is no argument it's correctly set after the semicolon :

PS: I now about t.switch completion, just want also the single case completion to slightly improve :)

@ncannasse
Copy link
Member Author

Also, would be nice to only get currently unmatched constructors in completion results

@Gama11
Copy link
Member

Gama11 commented Sep 12, 2018

That's intentional, it's a "snippet insertion" that allows cycling through the arguments with tab:

Not sure if setting the cursor position after : would be more convenient. The behavior is similar to for generation, which allows easily renaming the iterator variable:

@back2dos
Copy link

Well, I think the enum case makes even more sense than the loop case. It may well be that you want to put a pattern in place of the variable (instead of just renaming it). Jumping to the end of the line is one key, while if the cursor were at the end of the line, going back to op would be a bit more tedious.

@Gama11
Copy link
Member

Gama11 commented Sep 12, 2018

Good point, I think that's actually the primary reason I implemented it like that (for some reason I didn't think of it just now). So yeah, I don't think we should change that.

@Simn
Copy link
Member

Simn commented Sep 12, 2018

I think last time we discussed this we concluded that it would be nice to make the behavior depend on what key you press to make the selection.

@Gama11
Copy link
Member

Gama11 commented Sep 12, 2018

I don't think that's possible with the VSCode / LSP Api.

@Simn
Copy link
Member

Simn commented Sep 12, 2018

Yes that's what you said the last time too.

@ncannasse
Copy link
Member Author

The problem is that right now there is no easy way to just write TInst(c): , because if you hit ( while you're on TInst completion, you'll get first completion, then ( insertion, which becomes TInst((c)).

I would say that 95% or more matches are done on variables without complex patterns so we should optimize for this case. And it's not like for loop because here the variables have a meaning based on the way they were declared in original enum.

@back2dos
Copy link

The problem is that right now there is no easy way to just write TInst(c): , because if you hit ( while you're on TInst completion, you'll get first completion, then ( insertion, which becomes TInst((c)).

Uhm, t+i+n+Tab will give you TInst(t, params): with t selected. Hit End and you're at the end of the line. You're right though, if you you write t+i+n+( you wind up with TInst((t), params): with t selected which is certainly not what was intended. I didn't run into this, because I find Tab much easier to reach than (, but indeed there's a problem. If ( is used to trigger completion, it should not be inserted a second time.

I would say that 95% or more matches are done on variables without complex patterns so we should optimize for this case.

For me it's the opposite. Taking the particular example, I find TInst(_.get() => c, params) to be much more useful than TInst(c, params). How about we make : autocomplete the constructor and move the cursor after the :?

@Gama11
Copy link
Member

Gama11 commented Sep 13, 2018

Perhaps ( should not be a trigger character in this particular case.

How about we make : autocomplete the constructor and move the cursor after the :?

As I said, I don't think there's a way to conditionalize what's inserted based on which character is pressed.

@ncannasse
Copy link
Member Author

I think : should be the trigger char, instead of ( and insert directly the full constructor (with parameters if any)

@ncannasse
Copy link
Member Author

Up ?

@Gama11
Copy link
Member

Gama11 commented Oct 18, 2018

Having : as a commit character doesn't seem like a good idea, you end up with this (similar to how you end up with double parentheses in the other case). :D

Maybe snippet insertion simply doesn't play well with custom commit characters.. Anyway, we can just disallow ( , that's probably good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants