microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.02k stars 12.49k forks source link

Provide full import statement text from auto-import suggestions #31658

Closed compojoom closed 3 years ago

compojoom commented 5 years ago

Edit from @DanielRosenwasser

Given

import { someThi/**/

or

import { someThi/**/ }

The suggestion is to look for auto-imports to and to fully complete the paths with

import { someThing } from "./some/path"

Steps to Reproduce:

  1. I'm working on a react project. I have a file that does export const Buttons 2.In another file I do import { Button... and I expect auto-complete to display Buttons and hitting enter to complete the path.

But intelliSense just shows the text Buttons (with abc in front of it) and hitting enter doesn't add the path to the import.

If I try to directly import the component from a function - then auto-import correctly adds the Component to the top of the file with an import {Button} from 'correct_path'

Does this issue occur when all extensions are disabled?: Yes

andrewbranch commented 3 years ago

That would be a huge architectural change that is not worth this feature in the slightest, especially considering the feature is not just for VS Code. There is only one (semantic) TS Server, and it’s currently leveraged by one VS Code completion provider—I think changing that is off the table for now, because it would create a ton of non-backward-compatible work for every other language server client.

andrewbranch commented 3 years ago

For now I’ve managed to use a combination of isIncomplete and conditional triggering on a space character from the typescript-language-features completions provider. I wish the import statement snippet completion remained intact, but I guess with the additional trigger, it goes away, and the snippet completion is not re-triggered with a space character:

Kapture 2021-03-12 at 16 21 03

Users who don’t want that behavior can disable import statement completions with a preference, and it will avoid retriggering on that space.