Skip to content

<semantic> TS Server Error Debug Failure when moving to a js file #59240

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
Tyriar opened this issue Jul 10, 2024 · 3 comments · Fixed by #60333
Open

<semantic> TS Server Error Debug Failure when moving to a js file #59240

Tyriar opened this issue Jul 10, 2024 · 3 comments · Fixed by #60333
Assignees
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Fix Available A PR has been opened for this issue

Comments

@Tyriar
Copy link
Member

Tyriar commented Jul 10, 2024

Repo/file: https://github.com/xtermjs/xterm.js/blob/995ccc72f85dc2f8ab1353dacbfea12202b4a16c/demo/start.js

Recording 2024-07-10 at 06 35 22

TypeScript output:

2024-07-10 06:36:36.984 [trace] <semantic> Sending request: getMoveToRefactoringFileSuggestions (2566). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9
}
2024-07-10 06:36:36.985 [trace] <semantic> Response received: getMoveToRefactoringFileSuggestions (2566). Request took 1 ms. Success: true  {
    "newFileName": "d:/Tyriar/xterm.js/demo/newFile.js",
    "files": [
        "d:/Tyriar/xterm.js/out-esbuild/vs/base/browser/canIUse.js",
        "d:/Tyriar/xterm.js/out-esbuild/browser/Terminal.test.js",
        "d:/Tyriar/xterm.js/demo/server.js"
    ]
}
2024-07-10 06:36:38.868 [trace] <semantic> Sending request: getEditsForRefactor (2567). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9,
    "action": "Move to file",
    "refactor": "Move to file",
    "interactiveRefactorArguments": {
        "targetFile": "d:/Tyriar/xterm.js/out-esbuild/vs/base/browser/canIUse.js"
    }
}
2024-07-10 06:36:38.872 [trace] <semantic> Response received: getEditsForRefactor (2567). Request took 4 ms. Success: false . Message: Error processing request. Debug Failure.
Error: Debug Failure.
    at Object.addImportFromExportedSymbol (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:154158:32)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:144203:19
    at Map.forEach (<anonymous>)
    at addTargetFileImports (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:144197:17)
    at getNewStatementsAndRemoveFromOldFile (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143427:3)
    at doChange3 (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143411:3)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143396:79
    at _ChangeTracker.with (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:174213:5)
    at Object.getRefactorEditsToMoveToFile [as getEditsForAction] (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143396:62)
    at Object.getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:142518:31)
    at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149854:32)
    at IpcIOSession.getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:190993:49)
    at getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:189211:43)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191397:69
    at IpcIOSession.executeWithRequestId (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191389:14)
    at IpcIOSession.executeCommand (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191397:29)
    at IpcIOSession.onMessage (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191439:51)
    at process.<anonymous> (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\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)
2024-07-10 06:36:38.879 [trace] <semantic> Sending request: getApplicableRefactors (2568). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9,
    "triggerReason": "implicit",
    "includeInteractiveActions": true
}
2024-07-10 06:36:38.880 [trace] <semantic> Response received: getApplicableRefactors (2568). Request took 1 ms. Success: true  [
    {
        "name": "Convert export",
        "description": "Convert default export to named export",
        "actions": [
            {
                "name": "Convert default export to named export",
                "description": "Convert default export to named export",
                "kind": "refactor.rewrite.export.named",
                "notApplicableReason": "Could not find export statement"
            },
            {
                "name": "Convert named export to default export",
                "description": "Convert named export to default export",
                "kind": "refactor.rewrite.export.default",
                "notApplicableReason": "Could not find export statement"
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert namespace import to named imports",
        "actions": [
            {
                "name": "Convert namespace import to named imports",
                "description": "Convert namespace import to named imports",
                "kind": "refactor.rewrite.import.named",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert named imports to default import",
        "actions": [
            {
                "name": "Convert named imports to default import",
                "description": "Convert named imports to default import",
                "kind": "refactor.rewrite.import.default",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert named imports to namespace import",
        "actions": [
            {
                "name": "Convert named imports to namespace import",
                "description": "Convert named imports to namespace import",
                "kind": "refactor.rewrite.import.namespace",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Extract type",
        "description": "Extract type",
        "actions": [
            {
                "name": "Extract to typedef",
                "description": "Extract to typedef",
                "kind": "refactor.extract.typedef",
                "notApplicableReason": "Selection is not a valid type node"
            },
            {
                "name": "Extract to type alias",
                "description": "Extract to type alias",
                "kind": "refactor.extract.type",
                "notApplicableReason": "Selection is not a valid type node"
            },
            {
                "name": "Extract to interface",
                "description": "Extract to interface",
                "kind": "refactor.extract.interface",
                "notApplicableReason": "Selection is not a valid type node"
            }
        ]
    },
    {
        "name": "Move to file",
        "description": "Move to file",
        "actions": [
            {
                "name": "Move to file",
                "description": "Move to file",
                "kind": "refactor.move.file",
                "range": {
                    "start": {
                        "line": 10,
                        "offset": 1
                    },
                    "end": {
                        "line": 10,
                        "offset": 15
                    }
                }
            }
        ]
    },
    {
        "name": "Move to a new file",
        "description": "Move to a new file",
        "actions": [
            {
                "name": "Move to a new file",
                "description": "Move to a new file",
                "kind": "refactor.move.newFile",
                "range": {
                    "start": {
                        "line": 10,
                        "offset": 1
                    },
                    "end": {
                        "line": 10,
                        "offset": 15
                    }
                }
            }
        ]
    },
    {
        "name": "Add or remove braces in an arrow function",
        "description": "Add or remove braces in an arrow function",
        "actions": [
            {
                "name": "Add braces to arrow function",
                "description": "Add braces to arrow function",
                "kind": "refactor.rewrite.arrow.braces.add",
                "notApplicableReason": "Could not find a containing arrow function"
            },
            {
                "name": "Remove braces from arrow function",
                "description": "Remove braces from arrow function",
                "kind": "refactor.rewrite.arrow.braces.remove",
                "notApplicableReason": "Could not find a containing arrow function"
            }
        ]
    },
    {
        "name": "Convert to template string",
        "description": "Convert to template string",
        "actions": [
            {
                "name": "Convert to template string",
                "description": "Convert to template string",
                "kind": "refactor.rewrite.string",
                "notApplicableReason": "Can only convert string concatenations and string literals"
            }
        ]
    },
    {
        "name": "Extract Symbol",
        "description": "Extract function",
        "actions": [
            {
                "name": "Extract Function",
                "description": "Extract function",
                "kind": "refactor.extract.function",
                "notApplicableReason": "Cannot extract empty range."
            }
        ]
    },
    {
        "name": "Extract Symbol",
        "description": "Extract constant",
        "actions": [
            {
                "name": "Extract Constant",
                "description": "Extract constant",
                "kind": "refactor.extract.constant",
                "notApplicableReason": "Cannot extract empty range."
            }
        ]
    },
    {
        "name": "Generate 'get' and 'set' accessors",
        "description": "Generate 'get' and 'set' accessors",
        "actions": [
            {
                "name": "Generate 'get' and 'set' accessors",
                "description": "Generate 'get' and 'set' accessors",
                "kind": "refactor.rewrite.property.generateAccessors",
                "notApplicableReason": "Could not find property for which to generate accessor"
            }
        ]
    }
]
@AlvinTao0

This comment has been minimized.

@mjbvz mjbvz transferred this issue from microsoft/vscode Jul 11, 2024
@mjbvz mjbvz removed their assignment Jul 11, 2024
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Jul 11, 2024
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.6.0 milestone Jul 11, 2024
@itsMapleLeaf
Copy link

itsMapleLeaf commented Jul 11, 2024

I managed to reproduce this error minimally (repo). It occurs on namespace accesses from a module with export * as name from 'mod'

Example:

// mod.ts
export * as Mod from "./mod.js"
export type A = string

// index.ts
import { Mod } from "./mod"

type B = Mod.A

Doing the "Move to file" or "Move to a new file" refactors on type B produces this error:

Perf 152  [17:42:39.175] 40::getCodeFixes: elapsed time (in milliseconds) 0.6996
Info 153  [17:42:39.175] response:
    {"seq":0,"type":"response","command":"getCodeFixes","request_seq":40,"success":true,"body":[{"fixName":"unusedIdentifier","description":"Remove unused declaration for: 'B'","changes":[{"fileName":"c:/dev/demo/ts-move-debug-failure/index.ts","textChanges":[{"start":{"line":3,"offset":1},"end":{"line":3,"offset":16},"newText":""}]}]}]}
Info 154  [17:42:41.133] request:
    {
      "seq": 41,
      "type": "request",
      "command": "getEditsForRefactor",
      "arguments": {
        "file": "c:\\dev\\demo\\ts-move-debug-failure\\index.ts",
        "startLine": 3,
        "startOffset": 6,
        "endLine": 3,
        "endOffset": 6,
        "refactor": "Move to a new file",
        "action": "Move to a new file"
      }
    }
Err 155   [17:42:41.151] Exception on executing command {
  "seq": 41,
  "type": "request",
  "command": "getEditsForRefactor",
  "arguments": {
    "file": "c:\\dev\\demo\\ts-move-debug-failure\\index.ts",
    "startLine": 3,
    "startOffset": 6,
    "endLine": 3,
    "endOffset": 6,
    "refactor": "Move to a new file",
    "action": "Move to a new file",
    "startPosition": 34,
    "endPosition": 34
  }
}:

    Debug Failure.

    Error: Debug Failure.
        at Object.addImportFromExportedSymbol (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:154475:32)
        at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144415:19
        at Map.forEach (<anonymous>)
        at addTargetFileImports (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144409:17)
        at getNewStatementsAndRemoveFromOldFile (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:143630:3)
        at doChange4 (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144615:3)
        at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144604:77
        at _ChangeTracker.with (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:174571:5)
        at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:144604:60)
        at Object.getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:142721:31)
        at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:150173:32)
        at IpcIOSession.getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191260:49)
        at getEditsForRefactor (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:189429:43)
        at c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191679:15
        at IpcIOSession.executeWithRequestId (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191668:14)
        at IpcIOSession.executeCommand (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191677:29)
        at IpcIOSession.onMessage (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\typescript.js:191725:68)
        at process.<anonymous> (c:\dev\demo\ts-move-debug-failure\node_modules\typescript\lib\tsserver.js:525:14)
        at process.emit (node:events:514:28)
        at emit (node:internal/child_process:951:14)
        at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

File text of c:\dev\demo\ts-move-debug-failure\index.ts:
    import { Mod } from "./mod"
    
    type B = Mod.A

Although this might hint at where the problem actually is, it's probably broader than this, because I'm seemingly hitting other cases that don't involve this 🤔

@iisaduan
Copy link
Member

iisaduan commented Oct 24, 2024

Minimal repro of the original issue:

/// <reference path='fourslash.ts' />
 
// @allowjs: true
 
// @Filename: /start.js
//// // @ts-check
////
//// [|const startServer = require('./server.js');
////
//// startServer();|]
 
 
// @Filename: /server.js
//// // @ts-check
////
//// function startServer() {
//// }
//// module.exports = startServer;

verify.moveToNewFile({
    newFileContents: {
        "/start.js":
``,

        "/startServer.js":
`<div>a</div>;
`,
    }
});

@itsMapleLeaf #59240 (comment) should be fixed after #60333. I think the case you repro-ed is similar to #58897, and is included in my PR.

@iisaduan iisaduan reopened this Nov 1, 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: Refactorings e.g. extract to constant or function, rename symbol Fix Available A PR has been opened for this issue
Projects
None yet
9 participants