Skip to content

Commit

Permalink
Support completions that require changing from dot to bracket access
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Dec 7, 2017
1 parent 5e5b770 commit 27bec0d
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 197 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ namespace ts {
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
// Symbol instance.
function isReservedMemberName(name: __String) {
function isReservedMemberName(name: __String) { //!
return (name as string).charCodeAt(0) === CharacterCodes._ &&
(name as string).charCodeAt(1) === CharacterCodes._ &&
(name as string).charCodeAt(2) !== CharacterCodes._ &&
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3890,5 +3890,9 @@
"Install '{0}'": {
"category": "Message",
"code": 95014
},
"Use bracket notation instead of dot notation": {
"category": "Message",
"code": 95015
}
}
257 changes: 154 additions & 103 deletions src/services/completions.ts

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions tests/cases/fourslash/completionListInvalidMemberNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
//// "\u0031\u0062": "invalid unicode identifer name (1b)"
////};
////
////x./*a*/;
////[|x./*a*/;|]
////x["/*b*/"];

verify.completionsAt("a", ["bar", "break", "any", "$", "b"]);
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "\u0031\u0062"]);
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"]);

verify.completionsAt("a", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"]);
verify.applyCodeActionFromCompletion("a", {
name: "foo ",
description: "Use bracket notation instead of dot notation",
newRangeContent: 'x[""];',
});
21 changes: 15 additions & 6 deletions tests/cases/fourslash/completionListInvalidMemberNames2.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
/// <reference path='fourslash.ts' />

////enum Foo {
//// X, Y, '☆'
// TODO: we should probably support this like we do in completionListInvalidMemberNames.ts

////declare var Symbol: SymbolConstructor;
////interface SymbolConstructor {
//// readonly hasInstance: symbol;
////}
////interface Function {
//// [Symbol.hasInstance](value: any): boolean;
////}
////interface SomeInterface {
//// (value: number): any;
////}
////Foo./*a*/;
////Foo["/*b*/"];
////var _ : SomeInterface;
////_./**/

verify.completionsAt("a", ["X", "Y"]);
verify.completionsAt("b", ["X", "Y", "☆"]);
goTo.marker();
verify.not.completionListContains("[Symbol.hasInstance]");
71 changes: 0 additions & 71 deletions tests/cases/fourslash/completionListInvalidMemberNames3.ts

This file was deleted.

This file was deleted.

0 comments on commit 27bec0d

Please sign in to comment.