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

Add file extensions when auto-completing import paths #19019

Closed
mjbvz opened this issue Oct 8, 2017 · 10 comments
Closed

Add file extensions when auto-completing import paths #19019

mjbvz opened this issue Oct 8, 2017 · 10 comments
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Oct 8, 2017

From @Rich-Harris on October 6, 2017 14:58

  • VSCode Version: Code 1.17.0 (be377c0faf7574a59f84940f593a6849f12e4de7, 2017-10-05T06:07:51.906Z)
  • OS Version: Darwin x64 16.7.0
  • Extensions:
Extension Author (truncated) Version
Handlebars and 0.2.0
vscode-eslint dba 1.3.2
prettier-vscode esb 0.24.0
vscode-import-cost wix 2.5.0

Steps to Reproduce:

  1. Open or create a JavaScript file
  2. Start typing import x from './ followed by the name of a sibling file

Reproduces without extensions: Yes


When you start writing a local import statement, the intellisense helper will offer up foo and bar rather than foo.js and bar.js. Extensionless imports is a Node idiom that is incompatible with browser module loaders — adding the file extension would increase browser compatibility with no ill-effect on Node apps (to the contrary, it speeds up module resolution, and I'd argue it makes code more explicit and readable).

I wonder if you would consider changing the behaviour to add file extensions by default?

Copied from original issue: microsoft/vscode#35730

@mjbvz mjbvz self-assigned this Oct 8, 2017
@mjbvz mjbvz added VS Code Tracked There is a VS Code equivalent to this issue and removed feature-request labels Oct 8, 2017
@mjbvz mjbvz removed their assignment Oct 8, 2017
@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 8, 2017

Here's the completions information currently returned for a file x.ts:

[Trace  - 07:59:41] Response received: completions (132). Request took 2 ms. Success: true 
Result: [
    {
        "name": "x",
        "kind": "script",
        "kindModifiers": "",
        "sortText": "x",
        "replacementSpan": {
            "start": {
                "line": 1,
                "offset": 27
            },
            "end": {
                "line": 1,
                "offset": 27
            }
        }
    }
]

@aluanhaddad
Copy link
Contributor

If the behavior is changed, the ability to restore the old extensionless behavior should be made available via configuration.

Also this is not simply a Node.js convention but is used by a number of module loaders such as RequireJS.

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor labels Oct 9, 2017
@mhegazy mhegazy assigned ghost Oct 9, 2017
@mhegazy mhegazy added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Oct 9, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 9, 2017

I would like to get more user feedback on this issue.

@shannon
Copy link

shannon commented Nov 16, 2017

I ran into this when using the new auto import functionality. Not including the extension makes it invalid for browsers, while including the extension does not make it invalid for Node/RequireJS. It would be nice if it was configurable one way or the other though.

@Arilas
Copy link

Arilas commented Nov 17, 2017

Webpack, Browserify, etc support extensionless imports. Browser native import implementation is still something unusable. So I don't agree with this change

@shannon
Copy link

shannon commented Nov 17, 2017

@Arilas it's usable in Chrome and Safari by default now. In Edge and Firefox it's behind a flag but this is now the standard so it should at least be configurable to use the standard.

@Rich-Harris
Copy link

Just to reiterate, the choice isn't between Node compatibility and browser compatibility, it's between Node compatibility and (Node + browser) compatibility. Nothing would break — it would just result in faster and more explicit code.

@nicolasparada
Copy link

@shannon It's already on Edge without the flag.

@ghost
Copy link

ghost commented Nov 18, 2017

I think we could infer this from existing imports -- if they use .js new imports should too.

@ghost ghost closed this as completed in #20624 Jan 3, 2018
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jan 4, 2018
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Jan 4, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 3, 2018

With #22236 merged (TS 2.9) we can add an explicit configuration for it as well. PRs welcome.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

7 participants