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

Refactor: move to new file does not work #59650

Closed
a-x- opened this issue Aug 15, 2024 · 9 comments · Fixed by #60333
Closed

Refactor: move to new file does not work #59650

a-x- opened this issue Aug 15, 2024 · 9 comments · Fixed by #60333
Assignees
Labels
Bug A bug in TypeScript

Comments

@a-x-
Copy link

a-x- commented Aug 15, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: Version: 1.92.1 (Universal)
  • OS Version: MacOS Sonoma 14.5 / Apple M1 Pro

Steps to Reproduce:

  1. Refactor > move to new file

What I tried already:

  1. Run with --disable-extensions to ensure it's not a problem with a package.
  2. typescript.tsserver.enableTrace
  3. find minimal examples
  4. search for similar issues: Refactor: move to new file does not work vscode#51586, Refactor > Move to a new file -- not working (update, nothing in Refactor menu working) vscode#58711

It worked a few versions before. I don't know exactly what version was okay.

UPD: not working:

import { useLatest } from 'react-use';

export function useUseLatest (data: string) {
    return useLatest(data);
}

not working:

import { selectStore, useSelector } from '@proterm/core';

export function useOrders() {
    return useSelector(selectStore);
}

not working:

import { selectStore } from '@proterm/core';

export function useOrders() {
    return selectStore;
}

working:

import { AnyBaseOrder } from '@terminal/scalp/types';

export function useOrders(symbolId: string): AnyBaseOrder[] {}

working:

import { useSelector } from 'react-redux';

function useOrders() {
    return useSelector((state) => console.log(state));
}

working:

import { selectStore, useSelector } from '@proterm/core';
export function useOrders(symbolId: string): AnyBaseOrder[] {}

I though @ import aliases is a problem, however this works too:

import { FancyAlertCircleIcon } from '@terminal/icons';

export function useOrders() {
    return FancyAlertCircleIcon;
}

error:

2024-08-15 18:42:15.101 [error] <semantic> TypeScript Server Error (5.5.4)
Debug Failure.
Error: Debug Failure.
    at Object.addImportFromExportedSymbol (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:154243:32)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144288:19
    at Map.forEach (<anonymous>)
    at addTargetFileImports (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144282:17)
    at getNewStatementsAndRemoveFromOldFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:143512:3)
    at doChange4 (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144488:3)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144477:77
    at _ChangeTracker.with (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:174306:5)
    at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144477:60)
    at Object.getEditsForRefactor (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:142603:31)
    at Object.getEditsForRefactor2 [as getEditsForRefactor] (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:149939:32)
    at IpcIOSession.getEditsForRefactor (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:191087:49)
    at getEditsForRefactor (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:189305:43)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:191491:69
    at IpcIOSession.executeWithRequestId (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:191483:14)
    at IpcIOSession.executeCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:191491:29)
    at IpcIOSession.onMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:191533:51)
    at process.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:523:14)
    at process.emit (node:events:519:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21): Error: <semantic> TypeScript Server Error (5.5.4)
@a-x-
Copy link
Author

a-x- commented Aug 15, 2024

tsconfig.json:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "resolveJsonModule": true,
        "outDir": "./dist/",
        "lib": ["es2018", "dom", "ES2020.Promise", "DOM.Iterable", "es2019.array", "ES2021.String"],
        "sourceMap": true,
        "strict": true,
        "module": "esnext",
        "jsx": "react-jsx",
        "target": "es2017",
        "rootDir": ".",
        "allowJs": true,
        "moduleResolution": "node",
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "downlevelIteration": true,
        "importHelpers": true,
        "experimentalDecorators": true,
        "preserveSymlinks": true,
        "useUnknownInCatchVariables": false,

        // COPY: /webpack/tsconfig.json
        // COPY: /webpack/webpack.base.config.ts#alias
        // COPY: /.storybook/main.ts
        "paths": {
            "@proterm/core": ["./src/core"],
            "@terminal/*": ["./src/*"]
        },
        "plugins": [
            {
                "name": "typescript-plugin-css-modules",
                "options": {
                    "customMatcher": "\\.less$"
                }
            }
        ]
    },
    "types": ["node", "jest", "@testing-library/jest-dom", "@testing-library/react"],
    "include": ["./src/"],
    "exclude": ["**/__tests__", "**/*.stories.*", "**/__mock__/*.ts", "**/node_modules", "**/lib"]
}

@a-x-
Copy link
Author

a-x- commented Aug 15, 2024

So, @proterm/core is an alias to the big file with re-exports and re-exports of re-exports

Moreover, selectStore is declared as weird as:

function selectStore<State>(store: ReducerStore<State>): (state: any) => State;
function selectStore<State>(store: ReducerStore<State>, state: any): State;
function selectStore<State>(store: ReducerStore<State>, state?: any) {
    if (state) {
        return select(store, state);
    }

    function selectStoreCurried(stateCurried: State) {
        return select(store, stateCurried);
    }

    (selectStoreCurried as any)[widgetScope.symbol] = true;

    return selectStoreCurried;
}

(selectStore as any)[widgetScope.symbol] = true;

export default selectStore;

@a-x-
Copy link
Author

a-x- commented Aug 15, 2024

Looks like this is a problem, because

import { syncSettings } from '@proterm/core';

export function useOrders() {
    return syncSettings;
}

works as syncSettings hasn't multiple declarations.

In the save moment, I cannot move other functions w/o referring selectStore or things like this.
For instance this does not work too:

import { useCallback, useRef, useState } from 'react';
import { useLatest } from 'react-use';

type Opts = { lastOnly?: boolean };
type Set<D> = (data: D) => void;
export function useSubscriptionProvider<T extends Set<D>, D>(name: string, data: D, opts?: Opts) {
    const { lastOnly = true } = opts || {};
    const [buffer, setBuffer] = useState<D[]>([]);
    const queueRef = useLatest(buffer);
    const saveBuffer = useCallback((data: D) => setBuffer((q) => [...q, data]), []);
    const ref = useRef<T>();
    console.log('hm', { lastOnly, buffer, queueRef, saveBuffer, ref, name, data });
}

Currently problem is a useLatest from 'react-use',

Minimal not working example:

import { useLatest } from 'react-use';

export function useUseLatest (data: string) {
    return useLatest(data);
}

@mjbvz mjbvz transferred this issue from microsoft/vscode Aug 15, 2024
@mjbvz mjbvz removed their assignment Aug 15, 2024
@Jason3S
Copy link

Jason3S commented Aug 16, 2024

I'm seeing this issue too.

When I try to Move to a New File in vscode, the following errors appear in the Extension Host output.

2024-08-16 14:51:23.411 [error] [vscode.typescript-language-features] provider FAILED
2024-08-16 14:51:23.411 [error] Error: <semantic> TypeScript Server Error (5.5.4)
Debug Failure. False expression: Changes overlap
Verbose Debug Information: {"pos":0,"end":1125} and {"pos":455,"end":455}
Error: Debug Failure. False expression: Changes overlap
Verbose Debug Information: {"pos":0,"end":1125} and {"pos":455,"end":455}
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:174932:15

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 16, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Aug 16, 2024
@aureliopetrone
Copy link

@navya9singh any update on this?

@robMolloy
Copy link

robMolloy commented Sep 3, 2024

@navya9singh @aureliopetrone @sheetalkamat this looks like the fix for a similar issue however it's
not working for me #59625

I have just downloaded the newest version and it doesn't seem to work for me.

Additionally there is some comments about disabling/enabling "typescript.tsserver.experimental.useVsCodeWatcher". I have tried both enabled and disabled but neither resolves for me
#59603 (comment)

@sheetalkamat
Copy link
Member

This seems more or less duplicate of #58740

@komichar
Copy link

I can confirm that this bug is still present & refactoring is broken for several minor & fix versions. Any plans to fix this?

@qimmer
Copy link

qimmer commented Oct 30, 2024

Any news on this? Also getting this when trying to move almost any symbols to a new file:

2024-10-30 13:06:08.641 [error] [vscode.typescript-language-features] provider FAILED
2024-10-30 13:06:08.641 [error] Error: <semantic> TypeScript Server Error (5.6.3)
Debug Failure.
Error: Debug Failure.
    at Object.addImportFromExportedSymbol (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:155205:32)
    at /opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:145113:19
    at Map.forEach (<anonymous>)
    at addTargetFileImports (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:145107:17)
    at getNewStatementsAndRemoveFromOldFile (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:144328:3)
    at doChange4 (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:145331:3)
    at /opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:145320:77
    at _ChangeTracker.with (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:175529:5)
    at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:145320:60)
    at Object.getEditsForRefactor (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:143419:31)
    at getEditsForRefactor2 (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:150900:32)
    at Proxy.<anonymous> (/home/kim/.vscode-oss/extensions/unifiedjs.vscode-mdx-1.8.11-universal/node_modules/@mdx-js/typescript-plugin.js:5:1986)
    at IpcIOSession.getEditsForRefactor (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:192232:49)
    at getEditsForRefactor (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:190431:43)
    at /opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:192651:15
    at IpcIOSession.executeWithRequestId (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:192640:14)
    at IpcIOSession.executeCommand (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:192649:29)
    at IpcIOSession.onMessage (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/typescript.js:192697:68)
    at process.<anonymous> (/opt/vscodium-bin/resources/app/extensions/node_modules/typescript/lib/tsserver.js:525:14)
    at process.emit (node:events:519:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
	at n.create (/opt/vscodium-bin/resources/app/extensions/typescript-language-features/dist/extension.js:1:474261)
	at v.dispatchResponse (/opt/vscodium-bin/resources/app/extensions/typescript-language-features/dist/extension.js:1:468231)
	at v.dispatchMessage (/opt/vscodium-bin/resources/app/extensions/typescript-language-features/dist/extension.js:1:467029)
	at ChildProcess.<anonymous> (/opt/vscodium-bin/resources/app/extensions/typescript-language-features/dist/extension.js:1:466522)
	at ChildProcess.emit (node:events:519:28)
	at emit (node:internal/child_process:951:14)
	at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants