Skip to content

Commit 37d8499

Browse files
committed
Fix the completion entry for __proto
Fixes #850
1 parent 4c28e73 commit 37d8499

File tree

5 files changed

+138
-8
lines changed

5 files changed

+138
-8
lines changed

src/services/services.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ module ts {
23852385

23862386

23872387
if (isValid) {
2388-
return displayName;
2388+
return unescapeIdentifier(displayName);
23892389
}
23902390
}
23912391

@@ -2561,9 +2561,12 @@ module ts {
25612561
var start = new Date().getTime();
25622562
forEach(symbols, symbol => {
25632563
var entry = createCompletionEntry(symbol, session.typeChecker, location);
2564-
if (entry && !lookUp(session.symbols, entry.name)) {
2565-
session.entries.push(entry);
2566-
session.symbols[entry.name] = symbol;
2564+
if (entry) {
2565+
var id = escapeIdentifier(entry.name);
2566+
if (!lookUp(session.symbols, id)) {
2567+
session.entries.push(entry);
2568+
session.symbols[id] = symbol;
2569+
}
25672570
}
25682571
});
25692572
host.log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start));
@@ -2771,7 +2774,7 @@ module ts {
27712774
return undefined;
27722775
}
27732776

2774-
var symbol = lookUp(activeCompletionSession.symbols, entryName);
2777+
var symbol = lookUp(activeCompletionSession.symbols, escapeIdentifier(entryName));
27752778
if (symbol) {
27762779
var location = getTouchingPropertyName(sourceFile, position);
27772780
var completionEntry = createCompletionEntry(symbol, session.typeChecker, location);

tests/cases/fourslash/proto.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ verify.quickInfoIs("interface M.__proto__", "");
1212
goTo.marker('2');
1313
verify.quickInfoIs("(var) __proto__: M.__proto__", "");
1414
goTo.marker('3');
15-
//verify.completionListContains("__proto__", "(var) __proto__: M.__proto__", "");
15+
verify.completionListContains("__proto__", "(var) __proto__: M.__proto__", "");
1616
edit.insert("__proto__");
17-
//goTo.definition();
18-
//verify.caretAtMarker('2');
17+
goTo.definition();
18+
verify.caretAtMarker('2');
1919
goTo.marker('4');
2020
verify.quickInfoIs("(var) fun: (__proto__: any) => boolean", "");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////var o1 = {
4+
//// "__proto__": 10
5+
////};
6+
////var o2 = {
7+
//// __proto__: 10
8+
////};
9+
////o1./*1*/
10+
////o2./*2*/
11+
12+
goTo.marker('1');
13+
verify.completionListContains("__proto__", '(property) "__proto__": number');
14+
edit.insert("__proto__ = 10;");
15+
goTo.marker('1');
16+
verify.quickInfoIs('(property) "__proto__": number');
17+
goTo.marker('2');
18+
verify.completionListContains("__proto__", '(property) __proto__: number');
19+
edit.insert("__proto__ = 10;");
20+
goTo.marker('2');
21+
verify.quickInfoIs('(property) __proto__: number');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////var o1 : {
4+
//// __proto__: number;
5+
//// p: number;
6+
////} = {
7+
//// /*1*/
8+
//// };
9+
////var o2: {
10+
//// __proto__: number;
11+
//// p: number;
12+
////} = {
13+
//// /*2*/
14+
//// };
15+
////var o3: {
16+
//// "__proto__": number;
17+
//// p: number;
18+
////} = {
19+
//// /*3*/
20+
//// };
21+
////var o4: {
22+
//// "__proto__": number;
23+
//// p: number;
24+
////} = {
25+
//// /*4*/
26+
//// };
27+
////var o5: {
28+
//// __proto__: number;
29+
//// ___proto__: string;
30+
//// p: number;
31+
////} = {
32+
//// /*5*/
33+
//// };
34+
////var o6: {
35+
//// __proto__: number;
36+
//// ___proto__: string;
37+
//// p: number;
38+
////} = {
39+
//// /*6*/
40+
//// };
41+
42+
goTo.marker('1');
43+
verify.completionListContains("__proto__", '(property) __proto__: number');
44+
verify.completionListContains("p", '(property) p: number');
45+
edit.insert('__proto__: 10,');
46+
verify.not.completionListContains("__proto__", '(property) __proto__: number');
47+
verify.completionListContains("p", '(property) p: number');
48+
49+
goTo.marker('2');
50+
verify.completionListContains("__proto__", '(property) __proto__: number');
51+
verify.completionListContains("p", '(property) p: number');
52+
edit.insert('"__proto__": 10,');
53+
verify.not.completionListContains("__proto__", '(property) __proto__: number');
54+
verify.completionListContains("p", '(property) p: number');
55+
56+
goTo.marker('3');
57+
verify.completionListContains("__proto__", '(property) "__proto__": number');
58+
verify.completionListContains("p", '(property) p: number');
59+
edit.insert('__proto__: 10,');
60+
verify.not.completionListContains("__proto__", '(property) "__proto__": number');
61+
verify.completionListContains("p", '(property) p: number');
62+
63+
goTo.marker('4');
64+
verify.completionListContains("__proto__", '(property) "__proto__": number');
65+
verify.completionListContains("p", '(property) p: number');
66+
edit.insert('"__proto__": 10,');
67+
verify.not.completionListContains("__proto__", '(property) "__proto__": number');
68+
verify.completionListContains("p", '(property) p: number');
69+
70+
goTo.marker('5');
71+
verify.completionListContains("___proto__", '(property) ___proto__: string');
72+
verify.completionListContains("__proto__", '(property) __proto__: number');
73+
verify.completionListContains("p", '(property) p: number');
74+
edit.insert('__proto__: 10,');
75+
verify.not.completionListContains("__proto__", '(property) __proto__: number');
76+
verify.completionListContains("___proto__", '(property) ___proto__: string');
77+
verify.completionListContains("p", '(property) p: number');
78+
edit.insert('"___proto__": "10",');
79+
verify.not.completionListContains("__proto__", '(property) __proto__: number');
80+
verify.not.completionListContains("___proto__", '(property) ___proto__: string');
81+
verify.completionListContains("p", '(property) p: number');
82+
83+
goTo.marker('6');
84+
verify.completionListContains("___proto__", '(property) ___proto__: string');
85+
verify.completionListContains("__proto__", '(property) __proto__: number');
86+
verify.completionListContains("p", '(property) p: number');
87+
edit.insert('___proto__: "10",');
88+
verify.completionListContains("__proto__", '(property) __proto__: number');
89+
verify.not.completionListContains("___proto__", '(property) ___proto__: string');
90+
verify.completionListContains("p", '(property) p: number');
91+
edit.insert('"__proto__": 10,');
92+
verify.not.completionListContains("__proto__", '(property) __proto__: number');
93+
verify.not.completionListContains("___proto__", '(property) ___proto__: string');
94+
verify.completionListContains("p", '(property) p: number');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////// outer
4+
////var ___proto__ = 10;
5+
////function foo() {
6+
//// var __proto__ = "hello";
7+
//// /**/
8+
////}
9+
10+
goTo.marker('');
11+
verify.completionListContains("__proto__", '(local var) __proto__: string');
12+
verify.completionListContains("___proto__", '(var) ___proto__: number');

0 commit comments

Comments
 (0)