Skip to content

Commit 65bf850

Browse files
authored
Fix #51437 Duplicate "Duplicate identifier" errors (#51594)
* retroactive approach to remove duplicate diagnostics * use code instead of messageText, update test * use existing de-dupe function * rename test and baselines * add fourslash test for better assertion of fix * review feedback: move deduplicate to getDiagnosticsHelper * accept baseline with sorted diagnostics * remove newline
1 parent e087992 commit 65bf850

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
26392639
getDiagnostics: (sourceFile: SourceFile, cancellationToken: CancellationToken | undefined) => readonly T[],
26402640
cancellationToken: CancellationToken | undefined): readonly T[] {
26412641
if (sourceFile) {
2642-
return getDiagnostics(sourceFile, cancellationToken);
2642+
return sortAndDeduplicateDiagnostics(getDiagnostics(sourceFile, cancellationToken));
26432643
}
26442644
return sortAndDeduplicateDiagnostics(flatMap(program.getSourceFiles(), sourceFile => {
26452645
if (cancellationToken) {

tests/baselines/reference/tsserver/projects/handles-the-missing-files-added-with-tripleslash-ref.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,28 @@ Info 15 [00:00:34.000] response:
120120
"response": [
121121
{
122122
"start": {
123-
"line": 2,
124-
"offset": 29
123+
"line": 1,
124+
"offset": 22
125125
},
126126
"end": {
127-
"line": 2,
128-
"offset": 30
127+
"line": 1,
128+
"offset": 36
129129
},
130-
"text": "Cannot find name 'y'.",
131-
"code": 2304,
130+
"text": "File '/a/b/commonFile2.ts' not found.",
131+
"code": 6053,
132132
"category": "error"
133133
},
134134
{
135135
"start": {
136-
"line": 1,
137-
"offset": 22
136+
"line": 2,
137+
"offset": 29
138138
},
139139
"end": {
140-
"line": 1,
141-
"offset": 36
140+
"line": 2,
141+
"offset": 30
142142
},
143-
"text": "File '/a/b/commonFile2.ts' not found.",
144-
"code": 6053,
143+
"text": "Cannot find name 'y'.",
144+
"code": 2304,
145145
"category": "error"
146146
}
147147
],

tests/cases/fourslash/codeFixInferFromUsageMultipleParametersJS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
verify.codeFix({
1313
description: "Infer parameter types from usage",
14-
index: 4,
14+
index: 3,
1515
newFileContent:
1616
`/**
1717
* @param {number} a
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="./fourslash.ts" />
2+
3+
//// class X {
4+
//// foo() {
5+
//// return 1;
6+
//// }
7+
//// get foo() {
8+
//// return 1;
9+
//// }
10+
//// }
11+
12+
verify.numberOfErrorsInCurrentFile(2);

0 commit comments

Comments
 (0)