Skip to content

LS request crash when package.json bizarrely maps specifier to .ts file #2671

@DanielRosenwasser

Description

@DanielRosenwasser

Forgive me, this is the best repro I could find for this stack trace.

// @filename: src/a.ts
import * as b from "#/b./*$*/";

b.foo();

// @filename: src/b.ts
export {};

// @filename: package.json
{
    "imports": {
        "#/*": {
            "types": "./src/*ts",
            "default": "./dist/*js"
        }
    }
}

// @filename: tsconfig.json
{
    "compilerOptions": {
        "module": "nodenext",
        "moduleResolution": "nodenext",
        "rootDir": "src",
        "outDir": "dist",
    },
    "include": ["src"]
}

Request diagnostics for src/a.ts, and request completions at /*$*/.

[error] panic handling request textDocument/diagnostic: should be able to extract TS extension from string that passes IsDeclarationFileName
goroutine 2094 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x400022ce08, {0x7ff628c437c0?, 0x4000725340?}, 0x40035d52f0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:783 +0x40
panic({0x7ff629318b00?, 0x7ff62981c200?})
	runtime/panic.go:783 +0x120
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModule(0x4002ccf308, 0x40031ce2d0, {0x4000312136, 0x4}, 0x7ff629ebb7a0, 0x400362e480, 0x0)
	github.com/microsoft/typescript-go/internal/checker/checker.go:14825 +0x1b78
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModuleNameWorker(0x4002ccf308, 0x40031ce2d0, 0x400362e480, 0x7ff629ebb7a0, 0x0, 0x0)
	github.com/microsoft/typescript-go/internal/checker/checker.go:14727 +0x80
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveExternalModuleName(0x0?, 0x4000712e80?, 0x1?, 0xd8?)
	github.com/microsoft/typescript-go/internal/checker/checker.go:14722 +0x50
github.com/microsoft/typescript-go/internal/checker.(*Checker).getTargetOfNamespaceImport(0x4002ccf308, 0x40031ce2d0)
	github.com/microsoft/typescript-go/internal/checker/checker.go:14270 +0x3c
github.com/microsoft/typescript-go/internal/checker.(*Checker).getTargetOfAliasDeclaration(0x4002ccf308?, 0x7ff62937c280?)
	github.com/microsoft/typescript-go/internal/checker/checker.go:15334 +0x110
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveAlias(0x4002ccf308, 0x4002962150)
	github.com/microsoft/typescript-go/internal/checker/checker.go:15847 +0xf0
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkAliasSymbol(0x4002ccf308, 0x40031ce2d0)
	github.com/microsoft/typescript-go/internal/checker/checker.go:6533 +0x3c
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkImportBinding(0x4002ccf308, 0x40031ce2d0)
	github.com/microsoft/typescript-go/internal/checker/checker.go:5228 +0x48
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkImportDeclaration(0x4002ccf308, 0x4002a7e660)
	github.com/microsoft/typescript-go/internal/checker/checker.go:5157 +0x150
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElementWorker(0x4002ccf308, 0x4002a7e660)
	github.com/microsoft/typescript-go/internal/checker/checker.go:2297 +0x320
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElement(0x4002ccf308, 0x4000586780?)
	github.com/microsoft/typescript-go/internal/checker/checker.go:2168 +0x58
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElements(0x4002ccf308, {0x40031b2190, 0x2, 0x7ff6291fa210?})
	github.com/microsoft/typescript-go/internal/checker/checker.go:2158 +0x34
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceFile(0x4002ccf308, {0x7ff629826e08, 0x400339e210}, 0x40035fe388)
	github.com/microsoft/typescript-go/internal/checker/checker.go:2130 +0xf4
github.com/microsoft/typescript-go/internal/checker.(*Checker).getDiagnostics(0x4002ccf308, {0x7ff629826e08?, 0x400339e210?}, 0x40035fe388, 0x4002ccf500)
	github.com/microsoft/typescript-go/internal/checker/checker.go:13575 +0x3c
github.com/microsoft/typescript-go/internal/checker.(*Checker).GetDiagnostics(...)
	github.com/microsoft/typescript-go/internal/checker/checker.go:13564
github.com/microsoft/typescript-go/internal/compiler.(*Program).getBindAndCheckDiagnosticsForFile.func1(0x4001094248?, {0x7ff629826e08, 0x400339e210}, 0x40035fe388)
	github.com/microsoft/typescript-go/internal/compiler/program.go:1115 +0x80
github.com/microsoft/typescript-go/internal/compiler.(*Program).getBindAndCheckDiagnosticsForFile(0x4001094248, {0x7ff629826e08, 0x400339e210}, 0x40035fe388)
	github.com/microsoft/typescript-go/internal/compiler/program.go:1117 +0x70
github.com/microsoft/typescript-go/internal/compiler.(*Program).getSemanticDiagnosticsForFile(0x4001094248, {0x7ff629826e08?, 0x400339e210?}, 0x40035fe388)
	github.com/microsoft/typescript-go/internal/compiler/program.go:1095 +0x2c
github.com/microsoft/typescript-go/internal/compiler.(*Program).collectDiagnostics(0x4002c9bb80?, {0x7ff629826e08?, 0x400339e210?}, 0x40034e86c0?, 0x2c?, 0x0?)
	github.com/microsoft/typescript-go/internal/compiler/program.go:443 +0x6c
github.com/microsoft/typescript-go/internal/compiler.(*Program).GetSemanticDiagnostics(...)
	github.com/microsoft/typescript-go/internal/compiler/program.go:481
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDiagnostics(0x4002c9bb80, {0x7ff629826e08, 0x400339e210}, {0x40027c0000?, 0x36?})
	github.com/microsoft/typescript-go/internal/ls/diagnostics.go:16 +0xd4
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDocumentDiagnostic(0x4001917da8?, {0x7ff629826e08?, 0x400339e210?}, 0x40027c0000?, 0x30?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:1078 +0x30
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].12({0x7ff629826e08, 0x400339e210}, 0x40035d52f0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:665 +0xe8
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x400022ce08, {0x7ff629826e40?, 0x40031ce050?}, 0x40035d52f0)
	github.com/microsoft/typescript-go/internal/lsp/server.go:533 +0xc8
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:412 +0x34
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 23
	github.com/microsoft/typescript-go/internal/lsp/server.go:436 +0x7d8

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions