neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

Autocomplete doesn't work until import #323

Closed tylerschloesser closed 2 years ago

tylerschloesser commented 2 years ago

I can't tell if this is expected behavior but it's been bothering me for a while so I'm finally asking.

I always have to manually type out one import before coc-tsserver will let me autocomplete/autoimport anything from a package.

For example

const client = new ApolloClient<tab> // nothing

So I manually type

import { ApolloClient } from '@apollo/client'

const client = new ApolloClient<tab> // now it works (obviously)
const cache = new InMem // this now shows autocompletes/automports from @apollo/client package

Is this expected? Is asking tsserver to scan all possible imports asking for too much 😅

carlosala commented 2 years ago

If you are using node_modules be sure that in your tsconfig.json/jsconfig.json you have

{
  "compilerOptions": {
    "module": "es2020" // for example, you can also use es6 or others    
    "moduleResolution": "node" // MUST have
  }
}

When you are using import/export instead of require/module.exports, tsserver uses, as a default, classic module resolution, that doesn't support non-relative imports from node_modules folder. You can read more about the topic here. If this doesn't solves your problem, you are going to give us more information!

chemzqm commented 2 years ago

Should be issue with your tsserver, checkout https://github.com/neoclide/coc-tsserver/blob/master/Readme.md#troubleshooting

chemzqm commented 2 years ago

We have typescript.preferences.includePackageJsonAutoImports config now, maybe tsserver skipped your module for performance reason.