deno icon indicating copy to clipboard operation
deno copied to clipboard

LSP: file extension changed from `.ts` to `.js` after renaming

Open lucacasonato opened this issue 1 year ago • 8 comments

Take the following project:

// a.ts
import "./b.ts";
// b.ts
console.log("foo");
// c.ts
import "./a.ts";
  1. Open this project and VS Code, select file a.ts in the sidebar and Rename (F2 on Linux). Rename the file to d.ts.
  2. VS Code asks whether I want to let extensions apply fixes. Select yes.
  3. See the following output:
// d.ts
import "./b.js";
// b.ts
console.log("foo");
// c.ts
import "./d.ts";

This is nearly correct. c.ts was updated correctly, but a.ts was not. The specifiers there were changed from .js to .ts specifiers.

It should have been:

// d.ts
import "./b.ts";

Version: Deno 1.39.2+be888c0

lucacasonato avatar Jan 10 '24 16:01 lucacasonato

I can't reproduce on release or main. If you move a file within the same dir, the imports in that file shouldn't be touched. When I try moving to a different dir, the extension is correctly preserved.

nayeemrmn avatar Jan 15 '24 21:01 nayeemrmn

I can confirm that this is still an issue. Just ran into it a few minutes ago, but I'm unable to narrow it down to a small reproduction case.

marvinhagemeister avatar Jan 16 '24 11:01 marvinhagemeister

Occasionally renaming of the files does flip .ts to .js in imports for me as well.

king8fisher avatar Jan 16 '24 12:01 king8fisher

Are you guys still able to reproduce with other extensions disabled?

I am only able to reproduce this when I have the MDX extension enabled in VS Code.

When I perform the rename VSCode notifies there are two plugins trying to make modifications.

Screenshot 2024-01-18 at 11 08 06 pm

Possibly relevant: https://github.com/mdx-js/mdx-analyzer/blob/16a3240fe083a8a7254201179fc1204a9a260f3d/packages/language-server/index.js#L55

melbourne2991 avatar Jan 18 '24 12:01 melbourne2991

I also have the MDX extension enabled. Is it doing that?

lucacasonato avatar Jan 22 '24 12:01 lucacasonato

You can try setting "typescript.updateImportsOnFileMove.enabled": "never" to disable Deno's renames, and seeing if it still happens. Unless mdx refers to the same setting..

nayeemrmn avatar Jan 22 '24 13:01 nayeemrmn

@marvinhagemeister @king8fisher Do you also have the MDX extension, or something else that could be causing these renames?

nayeemrmn avatar Jan 29 '24 17:01 nayeemrmn

@marvinhagemeister Now as you say that I confirm that I do have that extension enabled. Disabling it to see if that helps to narrow down the issue.

king8fisher avatar Jan 29 '24 17:01 king8fisher

This will probably require a setting to disable this on the MDX extension. Closing for now unless there's something we can do to alleviate it from here.

nayeemrmn avatar Feb 01 '24 03:02 nayeemrmn