mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(52274): Suggestion code action adds another JSDoc (#52276)
This commit is contained in:
parent
ddac387c3e
commit
6f338b9936
@ -7,8 +7,10 @@ import {
|
||||
factory,
|
||||
firstDefined,
|
||||
getHostSignatureFromJSDoc,
|
||||
getJSDocHost,
|
||||
getJSDocTags,
|
||||
getTokenAtPosition,
|
||||
HasJSDoc,
|
||||
Identifier,
|
||||
isIdentifier,
|
||||
isJSDocParameterTag,
|
||||
@ -69,9 +71,9 @@ registerCodeFix({
|
||||
}
|
||||
});
|
||||
|
||||
function getDeleteAction(context: CodeFixContext, { name, signature, jsDocParameterTag }: Info) {
|
||||
function getDeleteAction(context: CodeFixContext, { name, jsDocHost, jsDocParameterTag }: Info) {
|
||||
const changes = textChanges.ChangeTracker.with(context, changeTracker =>
|
||||
changeTracker.filterJSDocTags(context.sourceFile, signature, t => t !== jsDocParameterTag));
|
||||
changeTracker.filterJSDocTags(context.sourceFile, jsDocHost, t => t !== jsDocParameterTag));
|
||||
return createCodeFixAction(
|
||||
deleteUnmatchedParameter,
|
||||
changes,
|
||||
@ -113,6 +115,7 @@ function getRenameAction(context: CodeFixContext, { name, signature, jsDocParame
|
||||
}
|
||||
|
||||
interface Info {
|
||||
readonly jsDocHost: HasJSDoc;
|
||||
readonly signature: SignatureDeclaration;
|
||||
readonly jsDocParameterTag: JSDocParameterTag;
|
||||
readonly name: Identifier;
|
||||
@ -122,9 +125,10 @@ function getInfo(sourceFile: SourceFile, pos: number): Info | undefined {
|
||||
const token = getTokenAtPosition(sourceFile, pos);
|
||||
if (token.parent && isJSDocParameterTag(token.parent) && isIdentifier(token.parent.name)) {
|
||||
const jsDocParameterTag = token.parent;
|
||||
const jsDocHost = getJSDocHost(jsDocParameterTag);
|
||||
const signature = getHostSignatureFromJSDoc(jsDocParameterTag);
|
||||
if (signature) {
|
||||
return { signature, name: token.parent.name, jsDocParameterTag };
|
||||
if (jsDocHost && signature) {
|
||||
return { jsDocHost, signature, name: token.parent.name, jsDocParameterTag };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
18
tests/cases/fourslash/codeFixDeleteUnmatchedParameter5.ts
Normal file
18
tests/cases/fourslash/codeFixDeleteUnmatchedParameter5.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @filename: a.ts
|
||||
/////**
|
||||
//// * @param {number} n
|
||||
//// * @returns
|
||||
//// */
|
||||
////export const foo = (z: number) => 0;
|
||||
|
||||
verify.codeFix({
|
||||
description: [ts.Diagnostics.Delete_unused_param_tag_0.message, "n"],
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`/**
|
||||
* @returns
|
||||
*/
|
||||
export const foo = (z: number) => 0;`
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user