Skip to content

Commit e4dc78a

Browse files
authored
Fixed crash on class member completions with auto imports from merged ambient modules (#60340)
1 parent 48f2ada commit e4dc78a

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,10 @@ function getAllExportInfoForSymbol(importingFile: SourceFile | FutureSourceFile,
891891
const moduleSymbolExcluded = moduleSourceFile && isFileExcluded(moduleSourceFile as SourceFile);
892892
return getExportInfoMap(importingFile, host, program, preferences, cancellationToken)
893893
.search(importingFile.path, preferCapitalized, name => name === symbolName, info => {
894+
const checker = getChecker(info[0].isFromPackageJson);
894895
if (
895-
getChecker(info[0].isFromPackageJson).getMergedSymbol(skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson))) === symbol
896-
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol))
896+
checker.getMergedSymbol(skipAlias(info[0].symbol, checker)) === symbol
897+
&& (moduleSymbolExcluded || info.some(i => checker.getMergedSymbol(i.moduleSymbol) === moduleSymbol || i.symbol.parent === moduleSymbol))
897898
) {
898899
return info;
899900
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
// @module: commonjs
5+
6+
// @filename: /node_modules/@types/vscode/index.d.ts
7+
//// declare module "vscode" {
8+
//// export class Position {
9+
//// readonly line: number;
10+
//// readonly character: number;
11+
//// }
12+
//// }
13+
14+
// @filename: src/motion.ts
15+
//// import { Position } from "vscode";
16+
////
17+
//// export abstract class MoveQuoteMatch {
18+
//// public override async execActionWithCount(
19+
//// position: Position,
20+
//// ): Promise<void> {}
21+
//// }
22+
////
23+
//// declare module "vscode" {
24+
//// interface Position {
25+
//// toString(): string;
26+
//// }
27+
//// }
28+
29+
// @filename: src/smartQuotes.ts
30+
//// import { MoveQuoteMatch } from "./motion";
31+
////
32+
//// export class MoveInsideNextQuote extends MoveQuoteMatch {/*1*/
33+
//// keys = ["i", "n", "q"];
34+
//// }
35+
36+
const preferences = {
37+
includeCompletionsWithInsertText: true,
38+
includeCompletionsWithClassMemberSnippets: true,
39+
};
40+
41+
verify.completions({
42+
marker: "1",
43+
includes: [
44+
{
45+
name: "execActionWithCount",
46+
insertText: "public execActionWithCount(position: Position): Promise<void> {\n}",
47+
filterText: "execActionWithCount",
48+
hasAction: true,
49+
source: "ClassMemberSnippet/",
50+
},
51+
],
52+
preferences,
53+
isNewIdentifierLocation: true,
54+
});
55+
56+
verify.applyCodeActionFromCompletion("1", {
57+
name: "execActionWithCount",
58+
source: "ClassMemberSnippet/",
59+
description: `Includes imports of types referenced by 'execActionWithCount'`,
60+
newFileContent: `import { Position } from "vscode";
61+
import { MoveQuoteMatch } from "./motion";
62+
63+
export class MoveInsideNextQuote extends MoveQuoteMatch {
64+
keys = ["i", "n", "q"];
65+
}`,
66+
preferences,
67+
});

0 commit comments

Comments
 (0)