typescript-go
typescript-go copied to clipboard
Crash for value usage of type-only import
// @allowImportingTsExtensions: true
// @module: preserve
// @filename: abc.ts
class Abcdef {}
// @filename: usage.ts
import { type Abcdef } from "./abc.ts";
new A/**/
Request completions and resolve the completion for Abcdef.
[error] panic handling requestcompletionItem/resolvesymbolOriginInfo: unknown data type for moduleSymbol(): *ls.symbolOriginInfoTypeOnlyAliasgoroutine 1038 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x4000120008, 0x4002318f00)
github.com/microsoft/typescript-go/internal/lsp/server.go:701 +0x40
panic({0x7ff6d7381c80?, 0x40033a1bf0?})
runtime/panic.go:783 +0x120
github.com/microsoft/typescript-go/internal/ls.(*symbolOriginInfo).moduleSymbol(...)
github.com/microsoft/typescript-go/internal/ls/completions.go:238
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionItemActions(0x4002b513b0, {0x7ff6d7868b88, 0x4002b51350}, 0x4001326608, 0x4001857208, 0x35, 0x4002338ac0, 0x400258d1c0)
github.com/microsoft/typescript-go/internal/ls/completions.go:5339 +0x458
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionItemDetails(0x4002b513b0, {0x7ff6d7868b88, 0x4002b51350}, 0x1?, 0x35, 0x4001857208, 0x40027d1d60, 0x4002338ac0)
github.com/microsoft/typescript-go/internal/ls/completions.go:5089 +0x48c
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ResolveCompletionItem(0x4002b513b0, {0x7ff6d7868b88, 0x4002b51350}, 0x40027d1d60, 0x4002338ac0)
github.com/microsoft/typescript-go/internal/ls/completions.go:5025 +0x68
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCompletionItemResolve(0x4000120008, {0x7ff6d7868b88, 0x4002b51350}, 0x40027d1d60, 0x4002318f00)
github.com/microsoft/typescript-go/internal/lsp/server.go:1026 +0xd8
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerRequestHandler[...].35({0x7ff6d7868b88, 0x4002b51350}, 0x4002318f00)
github.com/microsoft/typescript-go/internal/lsp/server.go:593 +0xc0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x4000120008, {0x7ff6d7868bc0?, 0x4002529c20?}, 0x4002318f00)
github.com/microsoft/typescript-go/internal/lsp/server.go:501 +0x128
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
github.com/microsoft/typescript-go/internal/lsp/server.go:404 +0x34
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
github.com/microsoft/typescript-go/internal/lsp/server.go:424 +0x7a0
Not sure—maybe rewrite this logic in Go? 🤔
https://github.com/microsoft/TypeScript/blob/9e8eaa1746b0d09c3cd29048126ef9cf24f29c03/src/services/completions.ts#L3115
function getCompletionEntryCodeActionsAndSourceDisplay(...): CodeActionsAndSourceDisplay {
...
if (originIsTypeOnlyAlias(origin)) {
const codeAction = codefix.getPromoteTypeOnlyCompletionAction(
sourceFile,
origin.declaration.name,
program,
host,
formatContext,
preferences,
);
Debug.assertIsDefined(codeAction, "Expected to have a code action for promoting type-only alias");
return { codeActions: [codeAction], sourceDisplay: undefined };
}
...
}
Or for now, we need to comment out
https://github.com/microsoft/typescript-go/blob/41e1964eb92efc3a00be4ac25396be3581b2d92a/internal/ls/completions.go#L2181-L2183
and leave a // !!!.
This will all be deleted soon