Skip to content

Path completions from subpath exports containing / have broken replacement range #57313

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

Open
andrewbranch opened this issue Feb 6, 2024 · 0 comments
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Milestone

Comments

@andrewbranch
Copy link
Member

andrewbranch commented Feb 6, 2024

Fourslash test:

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

// @module: preserve
// @moduleResolution: bundler
// @allowJs: true

// @Filename: /node_modules/repo/package.json
//// {
////   "name": "repo",
////   "exports": {
////     "./foo/bar": "./src/bar.js"
////   }
//// }

// @Filename: /node_modules/repo/src/bar.js
//// export {};

// @Filename: /main.js
//// import { } from "repo/[|f/**/|]";

verify.completions({
  marker: "",
  isNewIdentifierLocation: true,
  exact: [
    { name: "foo/bar", kind: "script", kindModifiers: "", replacementSpan: test.ranges()[0] },
  ],
});

The actual replacement range is the full module specifier. (VS Code shows nothing since the text of the replacement range doesn’t match the insertion text.) The root cause is #41412. At the time, only full module specifiers from compilerOptions.paths were able to return slashes (I guess?).

The replacement range logic is really overcomplicated and based on weird heuristics like this. I think it would be simpler and more reliable for path completions to always return entries with replacement ranges equal to the entire string literal (and with text starting from the beginning of the string literal), instead of sometimes returning fragments intended to be inserted after the last slash. However, the existing code makes this really difficult, as nearly all functions directly mutate the set of results without having any knowledge of what’s already been typed in the string literal.

Originally reported at #56412 (comment)

@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this labels Feb 6, 2024
@andrewbranch andrewbranch added this to the Backlog milestone Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

1 participant