Skip to content

Auto import inserts import into a comment #20293

Closed

Description

@mjbvz

From Simon Chan (@yume-chan) on November 22, 2017 2:8

  • VSCode Version: Code - Insiders 1.19.0-insider (d294b25, 2017-11-21T06:34:51.660Z)
  • OS Version: Windows_NT x64 10.0.16299
  • Extensions: Extensions are disabled

Steps to Reproduce:

  1. Create a new folder
  2. Open in Code
  3. npm i @types/node
  4. Create index.js
  5. Type /// <reference types="node" />
  6. Type setTimeout, select the auto import suggest.

Expected Result:

/// <reference types="node" />

import { setTimeout } from "timers";

setTimeout

Actual Result:

/// <reference types="node" />import { setTimeout } from "timers";



setTimeout

Copied from original issue: microsoft/vscode#38914

Activity

  1. removed their assignment
    on Nov 27, 2017
  2. mjbvz commented on Nov 27, 2017

    @mjbvz
    ContributorAuthor

    This is related to crlf line enedings. Here's the code action we get back for a crlf file:

     "codeActions": [
                {
                    "description": "Import 'setTimeout' from \"timers\".",
                    "changes": [
                        {
                            "fileName": "c:/source/test/y.js",
                            "textChanges": [
                                {
                                    "start": {
                                        "line": 1,
                                        "offset": 33
                                    },
                                    "end": {
                                        "line": 1,
                                        "offset": 33
                                    },
                                    "newText": "import { setTimeout } from \"timers\";\r\n\r\n"
                                }
                            ]
                        }
                    ]
                }
            ],
    

    With lf line endings, we instead get:

     {
                    "description": "Import 'setTimeout' from \"timers\".",
                    "changes": [
                        {
                            "fileName": "/Users/matb/projects/san/index.js",
                            "textChanges": [
                                {
                                    "start": {
                                        "line": 2,
                                        "offset": 1
                                    },
                                    "end": {
                                        "line": 2,
                                        "offset": 1
                                    },
                                    "newText": "import { setTimeout } from \"timers\";\n\n"
                                }
                            ]
                        }
                    ]
                }
            ],
    
  3. mhegazy commented on Nov 28, 2017

    @mhegazy
    Contributor

    From #20292 (comment)

    import { read } from "fs";
    
    #!/usr/bin/env node
  4. oliversalzburg commented on Nov 30, 2017

    @oliversalzburg

    The case that was quoted in #20293 (comment) appeared on my workstation.

    That happened on Windows in a file with LF.

  5. weswigham commented on Nov 30, 2017

    @weswigham
    Member

    I could swear that Andrew Casey (@amcasey) mentioned noticing this (or something very like it) before and having a fix for it; Am I wrong?

  6. ghost added
    Needs More InfoThe issue still hasn't been fully clarified
    on Dec 5, 2017
  7. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptNeeds More InfoThe issue still hasn't been fully clarifiedVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions