Skip to content

Commit 6f338b9

Browse files
authored
fix(52274): Suggestion code action adds another JSDoc (#52276)
1 parent ddac387 commit 6f338b9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/services/codefixes/fixUnmatchedParameter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
factory,
88
firstDefined,
99
getHostSignatureFromJSDoc,
10+
getJSDocHost,
1011
getJSDocTags,
1112
getTokenAtPosition,
13+
HasJSDoc,
1214
Identifier,
1315
isIdentifier,
1416
isJSDocParameterTag,
@@ -69,9 +71,9 @@ registerCodeFix({
6971
}
7072
});
7173

72-
function getDeleteAction(context: CodeFixContext, { name, signature, jsDocParameterTag }: Info) {
74+
function getDeleteAction(context: CodeFixContext, { name, jsDocHost, jsDocParameterTag }: Info) {
7375
const changes = textChanges.ChangeTracker.with(context, changeTracker =>
74-
changeTracker.filterJSDocTags(context.sourceFile, signature, t => t !== jsDocParameterTag));
76+
changeTracker.filterJSDocTags(context.sourceFile, jsDocHost, t => t !== jsDocParameterTag));
7577
return createCodeFixAction(
7678
deleteUnmatchedParameter,
7779
changes,
@@ -113,6 +115,7 @@ function getRenameAction(context: CodeFixContext, { name, signature, jsDocParame
113115
}
114116

115117
interface Info {
118+
readonly jsDocHost: HasJSDoc;
116119
readonly signature: SignatureDeclaration;
117120
readonly jsDocParameterTag: JSDocParameterTag;
118121
readonly name: Identifier;
@@ -122,9 +125,10 @@ function getInfo(sourceFile: SourceFile, pos: number): Info | undefined {
122125
const token = getTokenAtPosition(sourceFile, pos);
123126
if (token.parent && isJSDocParameterTag(token.parent) && isIdentifier(token.parent.name)) {
124127
const jsDocParameterTag = token.parent;
128+
const jsDocHost = getJSDocHost(jsDocParameterTag);
125129
const signature = getHostSignatureFromJSDoc(jsDocParameterTag);
126-
if (signature) {
127-
return { signature, name: token.parent.name, jsDocParameterTag };
130+
if (jsDocHost && signature) {
131+
return { jsDocHost, signature, name: token.parent.name, jsDocParameterTag };
128132
}
129133
}
130134
return undefined;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @filename: a.ts
4+
/////**
5+
//// * @param {number} n
6+
//// * @returns
7+
//// */
8+
////export const foo = (z: number) => 0;
9+
10+
verify.codeFix({
11+
description: [ts.Diagnostics.Delete_unused_param_tag_0.message, "n"],
12+
index: 0,
13+
newFileContent:
14+
`/**
15+
* @returns
16+
*/
17+
export const foo = (z: number) => 0;`
18+
});

0 commit comments

Comments
 (0)