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

code-completion doesn't replace expected text when cursor is not at the end of name #10266

Closed
DanTup opened this issue Aug 7, 2016 · 75 comments
Assignees
Labels
api-finalization feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan suggest IntelliSense, Auto Complete
Milestone

Comments

@DanTup
Copy link
Contributor

DanTup commented Aug 7, 2016

  • VSCode Version: 1.4.0
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create a method called methodOne
  2. Write some code that calls this method as methodTwo()
  3. Place the cursor between the d and T and invoke completion
  4. Select methodOne from the completion list

You would expect methodTwo to be replaced with methodOne but you end up with methodOneTwo.

@dbaeumer dbaeumer added typescript Typescript support issues bug Issue identified by VS Code Team member as probable bug labels Aug 8, 2016
@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2016

@jrieken is there anything special I need to do to achieve this?

@DanTup
Copy link
Contributor Author

DanTup commented Aug 8, 2016

If it helps, my Dart extension seems to handle this correctly:

https://github.com/DanTup/Dart-Code/blob/master/src/dart_completion_item_provider.ts#L41

You can provide a textEdit property on the CompletionItem with a Range to replace. The Dart language service I'm using already returned the correct length here so it just worked out of the box. I guess in your MyCompletionItem class you may need to set up the textEdit (assuming you have all the necessary info from the service).

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2016

I don't :-(. I can reconstruct this using may be model API but I was hoping not being forced to do this and @jrieken knows a better way.

If we need this information to handle cases like this then it should IMO come from the tsserver since he has the full knowledge about the context of the code complete.

@jrieken
Copy link
Member

jrieken commented Aug 8, 2016

When a completion item doesn't specify a text edit we construct one with the word range until the current position. So, you can achieve the behaviour using a different range or we just change our default - tho that makes it sound more like a user option cos I am not sure if overwrite after is always the right thing to do?

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2016

Changing the default is not a good thing to do since we will break others. I will see if I can recompute this for now and make a request against the tsserver to better provide this info.

@dbaeumer dbaeumer added this to the August 2016 milestone Aug 8, 2016
@jrieken
Copy link
Member

jrieken commented Aug 8, 2016

You can always ask for the word range at position. That's usually a pretty good guess

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2016

Agree.

@dbaeumer
Copy link
Member

@jrieken and I discussed that again over lunch and we agreed that we should investigate into a language neutral solution to not have to many language specific settings. Moving to September and adding @jrieken as an owner.

@dbaeumer dbaeumer modified the milestones: September 2016, August 2016 Aug 26, 2016
@jrieken jrieken added the suggest IntelliSense, Auto Complete label Aug 26, 2016
@jrieken jrieken added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Sep 7, 2016
@jrieken jrieken removed this from the September 2016 milestone Sep 20, 2016
@dbaeumer dbaeumer assigned waderyan and unassigned dbaeumer Nov 15, 2016
@jrieken jrieken removed the typescript Typescript support issues label Mar 13, 2017
@jrieken jrieken changed the title Typescript code-completion doesn't replace expected text when cursor is not at the end of name code-completion doesn't replace expected text when cursor is not at the end of name Mar 13, 2017
@ramya-rao-a
Copy link
Contributor

Related to #4878 ?

@jrieken
Copy link
Member

jrieken commented Nov 19, 2019

Your understanding is wrong - when extensions provide a range nothing will change.

@DanTup
Copy link
Contributor Author

DanTup commented Nov 19, 2019

Ok, then I'm confused - why hold it back? It sounds like rolling it out will have no change in behaviour at all, and a change will only come when extensions update to the new API (which they can't do until after you ship it)?

@jrieken
Copy link
Member

jrieken commented Nov 19, 2019

We wanted to make sure that at least the extensions that ship with VS support this. Otherwise we should ship a setting that's not doing anything.

@DanTup
Copy link
Contributor Author

DanTup commented Nov 19, 2019

Got it, thanks 👍

@jrieken
Copy link
Member

jrieken commented Nov 19, 2019

@bmewburn re #10266 (comment). This is good feedback and wrt insert I would say that it's OK to end up with invalid code, e.g having con|sole and insert-accepting const simply results in constsole and I feel that this logic shouldn't change when accepting a suggestion that includes the invocation part. Tho, having said that - the API is designed to allow extensions to say "nah, in this case only replace or insert makes sense". Eg. your extension can provide insert and replace ranges for variable name suggestions but only replace ranges for invocation suggestions. We won't massage anything onto the ranges in that case and the UI will only offer one way of inserting. What we have planned here is to make it visible what is going to replaced, e.g rendering some background treatment.

@jrieken
Copy link
Member

jrieken commented Dec 2, 2019

We not gotten enough feedback to finalise this API and will push things out for another milestone. Tho, the setting and the default behaviour will ship.

@ctf0
Copy link

ctf0 commented Dec 20, 2019

isnt this covered with "editor.suggest.insertMode": "replace"

@DanTup
Copy link
Contributor Author

DanTup commented Dec 23, 2019

@ctf0 that functionality only works if the language extension provides two ranges to VS Code. There's an issue tracking handling that for TS at #87091.

jrieken added a commit that referenced this issue Jan 16, 2020
@jrieken jrieken closed this as completed Jan 21, 2020
@jrieken jrieken added on-testplan on-release-notes Issue/pull request mentioned in release notes and removed api-proposal labels Jan 27, 2020
@AlGantori

This comment has been minimized.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-finalization feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan suggest IntelliSense, Auto Complete
Projects
None yet
Development

No branches or pull requests