Skip to content

Support editor.suggest.insertMode to control insert/replace behaviour #1991

Closed

Description

@escamoteur

I guess this is closely related to microsoft/vscode#10266

But slightly different. My case is that if I insert a new word directly in front of another and select auto-complete the whole following word is deleted.
Maybe I'm the only one who has the problem but I regularly delete worde because I forget to add a space first.

This is especially annoying if you have moved a variaable to anotehr clas and now have to prefix everywhere the new class instance. When you use autocomplete for the instances name you delete the property name after it if you haven't included a space, that you have to delete again before you can type '.'

Also when you are inside a word and trigger autocomplete '.' as completion trigger doesn't work

Activity

  1. DanTup commented on Sep 16, 2019

    @DanTup
    Member

    I guess this is closely related to microsoft/vscode#10266

    I don't think so - that issue was about TypeScript doing bad things, and the Dart server generally does good things here :-)

    My case is that if I insert a new word directly in front of another and select auto-complete the whole following word is deleted.

    This is intended (and what I'm asking for in the TS issue above). I do sometimes have the same issue as you and insert a space to avoid this, but having worked with TypeScript doing it the opposite way, I'm not sure having that default behaviour would be better. For example, if you typo a function:

    someFuntcionCall(1);

    To fix it, you can just put the cursor somewhere in there and hit Ctrl+Space, which brings up the completion:

    Screenshot 2019-09-16 at 10 50 54 am

    Selecting the right item will correctly replace the whole thing. Doing it "the TypeScript way" you'd end up with someFunctionCallmeFuntcionCall depending on where you put the cursor. I see this a lot in TS and it's quite infuriating as there's no quick way to select the bit to delete.

    It's true that sometimes I'm trying to completion a function call before some other code (eg. wrap it around a variable), but I think that's less frequent than fixing simple typos. Most of the time, the completion includes the exact symbol name you want, so completing the whole thing is good.

    This is especially annoying if you have moved a variaable to anotehr clas and now have to prefix everywhere the new class instance. When you use autocomplete for the instances name you delete the property name after it if you haven't included a space, that you have to delete again before you can type '.'

    Would typing the . first (instead of a space) work? I think in this situation I'd probably put newProperty. in the clipboard and paste it in front of them, so maybe I don't think I've seen this enough to know how annoying it is.

    Also when you are inside a word and trigger autocomplete '.' as completion trigger doesn't work

    I can't repro this - pressing . in the middle of a word seems to open completion for me. If you can make a small repro, file a separate bug and I can look into it :-)

  2. escamoteur commented on Sep 16, 2019

    @escamoteur
    Author

    I'm with you that the behavior that if you trigger autocomplete inside the word it should replace. But could we avoid that when standing at the first character of the next word?

  3. DanTup commented on Sep 16, 2019

    @DanTup
    Member

    But could we avoid that when standing at the first character of the next word?

    I'm not sure exactly what you mean - could you give an example?

  4. escamoteur commented on Sep 16, 2019

    @escamoteur
    Author
  5. DanTup commented on Sep 17, 2019

    @DanTup
    Member

    I'm not sure how you would make this distinction. For example, given this code:

    myClass.myMethod();

    If I want to change the myMethod call to myOtherMethod() because I selected the wrong one, I might put my cursor before the m in myMethod and invoke completion, expecting to select myOtherMethod and have it replace the text.

    I think with the change you're suggesting, it would end up with myClass.myOtherMethodmyMethod()?

  6. escamoteur commented on Sep 17, 2019

    @escamoteur
    Author

    Yes, that would be the consequence. But if I want to replace the whole word I type Ctrl+d and the word is selected. If I then do control space it would replace the word.

  7. DanTup commented on Sep 17, 2019

    @DanTup
    Member

    Right, so you'd prefer it to be dependant on whether you had a selection? I don't think we have the ability to do that (from the extension). We give the completion list to VS Code, and it's in charge of applying the edits. We can't change the edits dynamically/conditionally.

    I think the only workaround would be to delete the selected text before invoking the completion.

  8. escamoteur commented on Sep 17, 2019

    @escamoteur
    Author

    When I hit ctrl+d the cursor is then at the end of the word no longer at the beginning. How would it then replace the whole word?
    And yes in that case you could just hit delete.

    Maybe we could make this behavior configurable.

  9. added
    in editorRelates to code editing or language features
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    and removed on Nov 11, 2019
  10. added this to the v3.7.0 milestone on Nov 11, 2019
  11. DanTup commented on Nov 11, 2019

    @DanTup
    Member

    VS Code now has support for both insert and replace completions and we'll adopt the new API in the next version:

    https://code.visualstudio.com/updates/v1_40#_support-intellisense-replace-mode

    By default VS Code wants to do insert, but I personally think this is the less common case and since it differs from our current behaviour we may override editor.suggest.overwriteOnAccept for Dart to match the current behaviour (and you can press with <shift> to get insert mode).

  12. 8 remaining items

  13. modified the milestones: v3.7.0, v3.8.0 on Nov 19, 2019
  14. modified the milestones: v3.8.0, v3.9.0 on Jan 16, 2020
  15. modified the milestones: v3.9.0, v3.10.0 on Mar 24, 2020
  16. DanTup commented on Apr 20, 2020

    @DanTup
    Member

    You can now control this behaviour by holding <shift> when completing. By default, we will replace (the original behaviour) but holding shift will insert. If you want to swap these around (so insert is the default), you should override the editor.suggest.insertMode setting for Dart (note: you'll need to specifically set it for Dart, or our override will win):

    "[dart]": {
      "editor.suggest.insertMode": "insert"
    }
    
  17. changed the title [-]Code completion at the beginning of a word deletes the following word.[/-] [+]Support editor.suggest.insertMode to control insert/replace behaviour[/+] on Apr 20, 2020
  18. artoale commented on Apr 8, 2025

    @artoale

    Sorry for resurrecting a very old issue...but would it be possible to actually respect the API and global configuration instead of requiring a language-specific override? It "looks" unnecessary and, more importantly, is quite hard to find.

  19. DanTup commented on Apr 8, 2025

    @DanTup
    Member

    @artoale the way settings are applied is controlled by VS Code, not the extension. The discoverability of this has been raised in the past, and a tooltip was added (by VS Code) to make it clearer when there are language-specific overrides (of which there are many for this setting):

    Image

    I appreciate that it's frustrating to change a setting and for it to appear not to work, but unfortunately there's not much we can do from the extension here (we can't set the global setting, and I wouldn't be prepared to change Dart's default to insert without some significant indications that it's what most users would prefer).

  20. artoale commented on Apr 8, 2025

    @artoale

    Ah! Appreciate that and thanks for the reply! 👍

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions