diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0a835aaa4b5..60eda2dfbf7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -596,6 +596,29 @@ module FourSlash { } } + public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { + this.taoInvalidReason = 'verifyReferencesAtPositionListContains NYI'; + + var references = this.getReferencesAtCaret(); + + if (!references || references.length === 0) { + throw new Error('verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.'); + } + + for (var i = 0; i < references.length; i++) { + var reference = references[i]; + if (reference && reference.fileName === fileName && reference.minChar === start && reference.limChar === end) { + if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) { + throw new Error('verifyReferencesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.'); + } + return; + } + } + + var missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; + throw new Error('verifyReferencesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(references) + ')'); + } + public verifyReferencesCountIs(count: number, localFilesOnly: boolean = true) { this.taoInvalidReason = 'verifyReferences NYI'; diff --git a/src/services/services.ts b/src/services/services.ts index fff35031f66..12a0b3a8cc6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2466,8 +2466,8 @@ module ts { function getReferenceEntry(node: Node): ReferenceEntry { return { fileName: node.getSourceFile().filename, - minChar: node.getStart(), - limChar: node.getEnd(), + minChar: node.kind === SyntaxKind.StringLiteral ? node.getStart() + 1 : node.getStart(), + limChar: node.kind === SyntaxKind.StringLiteral ? node.getEnd() - 1 : node.getEnd(), isWriteAccess: isWriteAccess(node) }; } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index e394fd8f7ed..b4080d12e2f 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -183,6 +183,10 @@ module FourSlashInterface { FourSlash.currentTestState.verifyReferencesCountIs(count, /*localFilesOnly*/ false); } + public referencesAtPositionContains(range: Range, isWriteAccess?: boolean) { + FourSlash.currentTestState.verifyReferencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess); + } + public implementorsCountIs(count: number) { FourSlash.currentTestState.verifyImplementorsCountIs(count); } diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts new file mode 100644 index 00000000000..8c6292143ab --- /dev/null +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts @@ -0,0 +1,8 @@ +/// + +////var x = { "[|someProperty|]": 0 } +////x["[|someProperty|]"] = 3; +////x./*1*/[|someProperty|] = 5; + +goTo.marker("1"); +test.ranges().forEach(r => verify.referencesAtPositionContains(r)); \ No newline at end of file