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

Fixed crash on class member completions with auto imports from merged ambient modules #60340

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,10 @@ function getAllExportInfoForSymbol(importingFile: SourceFile | FutureSourceFile,
const moduleSymbolExcluded = moduleSourceFile && isFileExcluded(moduleSourceFile as SourceFile);
return getExportInfoMap(importingFile, host, program, preferences, cancellationToken)
.search(importingFile.path, preferCapitalized, name => name === symbolName, info => {
const checker = getChecker(info[0].isFromPackageJson);
if (
getChecker(info[0].isFromPackageJson).getMergedSymbol(skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson))) === symbol
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol))
checker.getMergedSymbol(skipAlias(info[0].symbol, checker)) === symbol
&& (moduleSymbolExcluded || info.some(i => checker.getMergedSymbol(i.moduleSymbol) === moduleSymbol || i.symbol.parent === moduleSymbol))
) {
return info;
}
Expand Down
67 changes: 67 additions & 0 deletions tests/cases/fourslash/autoImportCompletionAmbientMergedModule1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @module: commonjs

// @filename: /node_modules/@types/vscode/index.d.ts
//// declare module "vscode" {
//// export class Position {
//// readonly line: number;
//// readonly character: number;
//// }
//// }

// @filename: src/motion.ts
//// import { Position } from "vscode";
////
//// export abstract class MoveQuoteMatch {
//// public override async execActionWithCount(
//// position: Position,
//// ): Promise<void> {}
//// }
////
//// declare module "vscode" {
//// interface Position {
//// toString(): string;
//// }
//// }

// @filename: src/smartQuotes.ts
//// import { MoveQuoteMatch } from "./motion";
////
//// export class MoveInsideNextQuote extends MoveQuoteMatch {/*1*/
//// keys = ["i", "n", "q"];
//// }

const preferences = {
includeCompletionsWithInsertText: true,
includeCompletionsWithClassMemberSnippets: true,
};

verify.completions({
marker: "1",
includes: [
{
name: "execActionWithCount",
insertText: "public execActionWithCount(position: Position): Promise<void> {\n}",
filterText: "execActionWithCount",
hasAction: true,
source: "ClassMemberSnippet/",
},
],
preferences,
isNewIdentifierLocation: true,
});

verify.applyCodeActionFromCompletion("1", {
name: "execActionWithCount",
source: "ClassMemberSnippet/",
description: `Includes imports of types referenced by 'execActionWithCount'`,
newFileContent: `import { Position } from "vscode";
import { MoveQuoteMatch } from "./motion";

export class MoveInsideNextQuote extends MoveQuoteMatch {
keys = ["i", "n", "q"];
}`,
preferences,
});