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

Support includeAutomaticOptionalChainCompletions option #134

Closed
alxdnlnko opened this issue Apr 2, 2020 · 7 comments
Closed

Support includeAutomaticOptionalChainCompletions option #134

alxdnlnko opened this issue Apr 2, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@alxdnlnko
Copy link

alxdnlnko commented Apr 2, 2020

Hi. There is a bug with optional chain operator completion if the strictNullChecks mode is enabled in the tsconfig.json.

TL;DR - for objects which are possibly null, typescript returns the the completed item with prepended ?. symbols and vim just appends it to the previously manually added dot, and we get: obj.?.prop.

Example:

class Some {
  a?: string

  test() {
    this.a|  <-- cursor here
  }
}

When I add a dot and go through the suggestions this happens:

this.a.|
this.a.?.length|

Typescript lib returns the ?.prop completed item, and nvim wouldn't delete the dot inserted manually before. It's very annoying, and I'd prefer to insert the ? manually, and luckily there is an option: typescript.suggest.includeAutomaticOptionalChainCompletions
Look here the definition

But it seems that coc doesn't pass this option from the coc-config to the typescript.

Here is a coc-log:

2020-04-02T14:55:53.263 DEBUG (pid:22043) [events] - Event: MenuPopupChanged [
  {
    col: 18,
    row: 5,
    scrollbar: false,
    completed_item: {


      word: '?.length',


      menu: '[TSC]',
      user_data: '{"cid":1585806951,"source":"tsserver-typescript","index":16}',
      info: '',
      kind: 'm',
      abbr: 'length'
    },
    width: 15,
    height: 1,
    size: 1
  },
  4
]
@chemzqm chemzqm added the enhancement New feature or request label Apr 2, 2020
@chemzqm
Copy link
Member

chemzqm commented Apr 2, 2020

It's a new feature, not supported yet.

@alxdnlnko
Copy link
Author

alxdnlnko commented Apr 20, 2020

@chemzqm hi! just updated the extension to check your fix, and you made it wrong, sorry :(

"typescript.suggest.includeAutomaticOptionalChainCompletions": {
"type": "boolean",
"default": true,
"description": "Enable/disable showing completions on potentially undefined values that insert an optional chain call. Requires TS 3.7+ and strict null checks to be enabled.",

It must NOT disable the completion on such values. Completion must be triggered as usual after the dot, but this option must be passed to typescript engine to make it stop adding the '?.' to the suggestions.

this.a.|
this.a.?.length|  <-- this is what we were getting in the previous versions
this.a.length|  <-- we must get this results with the option set to 'false'

But with the recent update the completion is not triggered at all (for both 'true' and 'false' values), until you type this.a?., but you don't see any errors while you are in the INSERT mode, so it hard to understand why the completion is not triggered, until you go back to the NORMAL mode. So it made the experience even worse, sorry. Have to disable the strict mode again, but it is very useful, so I hope you can fix this issue.

The initial intention was to disable the wrong .?. insertions in suggestions but not the whole completion. You must get the regular this.a.length completion (without auto-inserted ? sign by the typescript engine), and after you go to the NORMAL mode, you'll see the hint that this.a could be null (it works already), so you can fix it yourself explicitly.

@chemzqm
Copy link
Member

chemzqm commented Apr 20, 2020

Looks like you're using old version of coc-tsserver.

@alxdnlnko
Copy link
Author

my version is 1.5.1

@chemzqm
Copy link
Member

chemzqm commented Apr 20, 2020

Fixed on latest release branch of coc.nvim.

@chemzqm
Copy link
Member

chemzqm commented Apr 20, 2020

The completion is triggered, but filterText could be wrong.

@alxdnlnko
Copy link
Author

Oh, thanks. Sorry for troubling you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants