Skip to content

Module specifier should be escaped for snippet in import statement completionΒ #52543

@jasonlyu123

Description

@jasonlyu123

Bug Report

πŸ”Ž Search Terms

import statement completion
auto import

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ and non seems to apply

⏯ Playground Link

Playground and bug workbench both don't seem to support import statement completion so I created a repo for the reproduction.
https://github.com/jasonlyu123/import-statement-completion-dollar-sign-repro. But the reproduction is simple so it might be faster to just create the file in the editor.

πŸ’» Code

// @filename: $another.ts

export function another() {
}

// @filename: imported.ts
import ano // trigger completion here

fourslash test case

/// <reference path="fourslash.ts" />

// @Filename: /$another.ts
//// export function another() {}

// @Filename: /imported.ts
//// [|import ano/*0*/|]
////

verify.completions({
  marker: `0`,
  isNewIdentifierLocation: true,
  exact: [{
    name: "another",
    source: "./$another",
    sourceDisplay: "./$another",
    insertText: `import { another$1 } from "./\\$another"`,
    isSnippet: true,
    replacementSpan: test.ranges()[0],
  }, {
    name: "type",
    sortText: completion.SortText.GlobalsOrKeywords,
  }],
  preferences: {
    includeCompletionsForImportStatements: true,
    includeCompletionsForModuleExports: true,
    includeCompletionsWithSnippetText: true,
    includeCompletionsWithInsertText: true,
  },
});

πŸ™ Actual behavior

The module specifier is not escaped so when you accept the suggestion the word that starts with $ got cut off.
For example:
./$another => ./
$lib/path/to => /path/to

The real-world use case is that SvelteKit has some module/alias that contains $ like $app/enviroment and $lib

πŸ™‚ Expected behavior

The module specifier is correctly inserted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Completion ListsThe issue relates to showing completion lists in an editorHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions