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

import with short path using package.json #406

Closed sandrodz closed 1 year ago

sandrodz commented 1 year ago

When using component that is not imported in current doc, tsserver automatically adds import at the top of the file. File path is like this:

import AppLayout from './layouts/App/App.layout'

But in the component directory there is a file with ./layouts/App/packages.json, it contains:

{
  "main": "App.layout.tsx"
}

Which means that filename is redundant and import statement can be:

import AppLayout from './layouts/App

How do I force coc-tsserver use this pattern instead?

chemzqm commented 1 year ago

Configuration typescript.preferences.importModuleSpecifier might help

sandrodz commented 1 year ago

@chemzqm none of these seem to work, I tried:

typescript.preferences.importModuleSpecifier: Preferred path style for auto imports. default: "shortest" Valid options: ["shortest","relative","non-relative","project-relative"]
typescript.preferences.importModuleSpecifierEnding: Preferred path ending for auto imports. default: "auto" Valid options: ["auto","minimal","index","js"]

Docs also mention typescript.preferences.includePackageJsonAutoImports: default: "auto" Valid options: ["auto","on","off"] but this doesn't seem to be released feature yet. LS complains when I put this config.

chemzqm commented 1 year ago

Seems you're not using latest coc-tsserver.

sandrodz commented 1 year ago

@chemzqm 2.0.2

Screenshot 2022-11-19 at 17 24 01

I am not sure what that error means.

chemzqm commented 1 year ago

It means it may not work as folder configuration in your project :h coc-configuration-scope

sandrodz commented 1 year ago

It means it may not work as folder configuration in your project :h coc-configuration-scope

but is it the right setting for my issue?

chemzqm commented 1 year ago

Seems not, you need to send feature request to typescript project.