Skip to content

Commit fcce15e

Browse files
authored
Fix bug where an interface definition had a conflicting symbol with a const in the same file (#206)
* Reproduce issue with conflicting const/interface * Fix the bug Verified on https://sourcegraph.com/github.com/microsoft/vscode@9984da1/-/blob/src/vs/workbench/services/workspaces/common/workspaceEditing.ts?L13:18#tab=implementations_typescript * Document why we have commented out code * Add comment explaining why we avoid ambiguous results at definitions
1 parent bbbd09b commit fcce15e

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

Development.md

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ npm run update-snapshots
2020

2121
Generate snapshots and update.
2222

23+
## Skipping files/test for local development
24+
25+
Search for the query `"Uncomment below if you want to skip` to find places where
26+
you can uncomment code to skip tests/files for a faster edit/test/debug feedback
27+
loop during local development.
28+
2329
## Snapshotting arbitrary projects
2430

2531
```sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const ConflictingConst = 42
2+
export interface ConflictingConst {}
3+
export class ImplementsConflictingConst implements ConflictingConst {}

snapshots/output/pure-js/src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
if (forever()) {
107107
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
108108
var k = 1
109-
// ^ definition local 14
109+
// ^ definition local 17
110110
// documentation ```ts\nvar k: number\n```
111111
}
112112
print_fib(k)

snapshots/output/syntax/src/accessors.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#_length.
1414
}
1515
set length(value: number) {
16-
// ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`<get>length`().
16+
// ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`<set>length`().
1717
// documentation ```ts\nget length: number\n```
1818
// ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`<set>length`().(value)
1919
// documentation ```ts\n(parameter) value: number\n```
@@ -46,7 +46,7 @@
4646
// ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_length.
4747
}
4848
public set length(value: number) {
49-
// ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<get>length`().
49+
// ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<set>length`().
5050
// documentation ```ts\nget length: number\n```
5151
// ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<set>length`().(value)
5252
// documentation ```ts\n(parameter) value: number\n```
@@ -65,7 +65,7 @@
6565
// ^^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_capacity.
6666
}
6767
private set capacity(value: number) {
68-
// ^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<get>capacity`().
68+
// ^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<set>capacity`().
6969
// documentation ```ts\nget capacity: number\n```
7070
// ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`<set>capacity`().(value)
7171
// documentation ```ts\n(parameter) value: number\n```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const ConflictingConst = 42
2+
// definition syntax 1.0.0 src/`conflicting-const-interface.ts`/
3+
//documentation ```ts\nmodule "conflicting-const-interface.ts"\n```
4+
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst.
5+
// documentation ```ts\ninterface ConflictingConst\n```
6+
export interface ConflictingConst {}
7+
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst#
8+
// documentation ```ts\ninterface ConflictingConst\n```
9+
export class ImplementsConflictingConst implements ConflictingConst {}
10+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ImplementsConflictingConst#
11+
// documentation ```ts\nclass ImplementsConflictingConst\n```
12+
// relationship implementation scip-typescript npm syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst#
13+
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst.
14+
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst#
15+

src/FileIndexer.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class FileIndexer {
3737
this.workingDirectoryRegExp = new RegExp(options.cwd, 'g')
3838
}
3939
public index(): void {
40+
// Uncomment below if you want to skip certain files for local development.
41+
// if (!this.sourceFile.fileName.includes('conflicting-const')) {
42+
// return
43+
// }
4044
this.emitSourceFileOccurrence()
4145
this.visit(this.sourceFile)
4246
}
@@ -104,7 +108,17 @@ export class FileIndexer {
104108
if (isDefinitionNode) {
105109
role |= scip.scip.SymbolRole.Definition
106110
}
107-
for (const declaration of sym?.declarations || []) {
111+
const declarations = isDefinitionNode
112+
? // Don't emit ambiguous definition at definition-site. You can reproduce
113+
// ambiguous results by triggering "Go to definition" in VS Code on `Conflict`
114+
// in the example below:
115+
// export const Conflict = 42
116+
// export interface Conflict {}
117+
// ^^^^^^^^ "Go to definition" shows two results: const and interface.
118+
// See https://github.com/sourcegraph/scip-typescript/pull/206 for more details.
119+
[node.parent]
120+
: sym?.declarations || []
121+
for (const declaration of declarations) {
108122
const scipSymbol = this.scipSymbol(declaration)
109123

110124
if (scipSymbol.isEmpty()) {

src/main.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ interface PackageJson {
3333
workspaces: string[]
3434
}
3535
for (const snapshotDirectory of snapshotDirectories) {
36+
// Uncomment below if you want to skip certain tests for local development.
37+
// if (!snapshotDirectory.includes('syntax')) {
38+
// continue
39+
// }
3640
const inputRoot = join(inputDirectory, snapshotDirectory)
3741
const outputRoot = join(outputDirectory, snapshotDirectory)
3842
if (!fs.statSync(inputRoot).isDirectory()) {

0 commit comments

Comments
 (0)