Skip to content

Commit 6800891

Browse files
committed
Merge branch 'completionWithMeaning'
2 parents 9611e58 + 3532875 commit 6800891

File tree

40 files changed

+1005
-284
lines changed

40 files changed

+1005
-284
lines changed

Gulpfile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ declare module "convert-source-map" {
747747
export function fromSource(source: string, largeSource?: boolean): SourceMapConverter;
748748
}
749749

750-
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => {
750+
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile, run], (done) => {
751751
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "../../built/local/bundle.js" }, /*useBuiltCompiler*/ true));
752752
return testProject.src()
753753
.pipe(newer("built/local/bundle.js"))

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ var nodeServerInFile = "tests/webTestServer.ts";
959959
compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, { noOutFile: true, lib: "es6" });
960960

961961
desc("Runs browserify on run.js to produce a file suitable for running tests in the browser");
962-
task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() {
962+
task("browserify", ["tests", run, builtLocalDirectory, nodeServerOutFile], function() {
963963
var cmd = 'browserify built/local/run.js -t ./scripts/browserify-optional -d -o built/local/bundle.js';
964964
exec(cmd);
965965
}, { async: true });

src/compiler/checker.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -14593,12 +14593,31 @@ namespace ts {
1459314593
? (<PropertyAccessExpression>node).expression
1459414594
: (<QualifiedName>node).left;
1459514595

14596-
const type = checkExpression(left);
14596+
return isValidPropertyAccessWithType(node, left, propertyName, getWidenedType(checkExpression(left)));
14597+
}
14598+
14599+
function isValidPropertyAccessWithType(
14600+
node: PropertyAccessExpression | QualifiedName,
14601+
left: LeftHandSideExpression | QualifiedName,
14602+
propertyName: string,
14603+
type: Type): boolean {
14604+
1459714605
if (type !== unknownType && !isTypeAny(type)) {
14598-
const prop = getPropertyOfType(getWidenedType(type), propertyName);
14606+
const prop = getPropertyOfType(type, propertyName);
1459914607
if (prop) {
1460014608
return checkPropertyAccessibility(node, left, type, prop);
1460114609
}
14610+
14611+
// In js files properties of unions are allowed in completion
14612+
if (isInJavaScriptFile(left) && (type.flags & TypeFlags.Union)) {
14613+
for (const elementType of (<UnionType>type).types) {
14614+
if (isValidPropertyAccessWithType(node, left, propertyName, elementType)) {
14615+
return true;
14616+
}
14617+
}
14618+
}
14619+
14620+
return false;
1460214621
}
1460314622
return true;
1460414623
}

src/harness/fourslash.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ namespace FourSlash {
814814

815815
function filterByTextOrDocumentation(entry: ts.CompletionEntry) {
816816
const details = that.getCompletionEntryDetails(entry.name);
817-
const documentation = ts.displayPartsToString(details.documentation);
818-
const text = ts.displayPartsToString(details.displayParts);
817+
const documentation = details && ts.displayPartsToString(details.documentation);
818+
const text = details && ts.displayPartsToString(details.displayParts);
819819

820820
// If any of the expected values are undefined, assume that users don't
821821
// care about them.
@@ -852,6 +852,9 @@ namespace FourSlash {
852852
if (expectedKind) {
853853
error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + ".";
854854
}
855+
else {
856+
error += "kind: " + filterCompletions[0].kind + ".";
857+
}
855858
if (replacementSpan) {
856859
const spanText = filterCompletions[0].replacementSpan ? stringify(filterCompletions[0].replacementSpan) : undefined;
857860
error += "Expected replacement span: " + stringify(replacementSpan) + " to equal: " + spanText + ".";

src/services/completions.ts

+129-42
Large diffs are not rendered by default.

src/services/utilities.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace ts {
8282
else if (node.parent.kind === SyntaxKind.ExportAssignment) {
8383
return SemanticMeaning.All;
8484
}
85-
else if (isInRightSideOfImport(node)) {
85+
else if (isInRightSideOfInternalImportEqualsDeclaration(node)) {
8686
return getMeaningFromRightHandSideOfImportEquals(node);
8787
}
8888
else if (isDeclarationName(node)) {
@@ -118,7 +118,7 @@ namespace ts {
118118
return SemanticMeaning.Namespace;
119119
}
120120

121-
function isInRightSideOfImport(node: Node) {
121+
export function isInRightSideOfInternalImportEqualsDeclaration(node: Node) {
122122
while (node.parent.kind === SyntaxKind.QualifiedName) {
123123
node = node.parent;
124124
}
@@ -745,7 +745,7 @@ namespace ts {
745745
// NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia).
746746
// if this is the case - then we should assume that token in question is located in previous child.
747747
if (position < child.end && (nodeHasTokens(child) || child.kind === SyntaxKind.JsxText)) {
748-
const start = (includeJsDoc && child.jsDoc ? child.jsDoc[0] : child).getStart(sourceFile);
748+
const start = child.getStart(sourceFile, includeJsDoc);
749749
const lookInPreviousChild =
750750
(start >= position) || // cursor in the leading trivia
751751
(child.kind === SyntaxKind.JsxText && start === child.end); // whitespace only JsxText

tests/cases/fourslash/commentsInheritance.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ verify.quickInfos({
346346
});
347347

348348
goTo.marker('16');
349-
verify.completionListContains("i1", "interface i1", "i1 is interface with properties");
349+
verify.not.completionListContains("i1", "interface i1", "i1 is interface with properties");
350350
verify.completionListContains("i1_i", "var i1_i: i1", "");
351351
verify.completionListContains("c1", "class c1", "");
352352
verify.completionListContains("c1_i", "var c1_i: c1", "");
@@ -603,9 +603,9 @@ verify.quickInfos({
603603
});
604604

605605
goTo.marker('51');
606-
verify.completionListContains("i2", "interface i2", "");
606+
verify.not.completionListContains("i2", "interface i2", "");
607607
verify.completionListContains("i2_i", "var i2_i: i2", "");
608-
verify.completionListContains("i3", "interface i3", "");
608+
verify.not.completionListContains("i3", "interface i3", "");
609609
verify.completionListContains("i3_i", "var i3_i: i3", "");
610610

611611
goTo.marker('51i');

tests/cases/fourslash/commentsInterface.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ verify.currentParameterHelpArgumentDocCommentIs("");
163163
verify.quickInfoAt("33q", "(method) i2.nc_fnfoo(b: number): string");
164164

165165
goTo.marker('34');
166-
verify.completionListContains("i1", "interface i1", "this is interface 1");
166+
verify.not.completionListContains("i1", "interface i1", "this is interface 1");
167167
verify.completionListContains("i1_i", "var i1_i: i1", "");
168-
verify.completionListContains("nc_i1", "interface nc_i1", "");
168+
verify.not.completionListContains("nc_i1", "interface nc_i1", "");
169169
verify.completionListContains("nc_i1_i", "var nc_i1_i: nc_i1", "");
170-
verify.completionListContains("i2", "interface i2", "this is interface 2 with memebers");
170+
verify.not.completionListContains("i2", "interface i2", "this is interface 2 with memebers");
171171
verify.completionListContains("i2_i", "var i2_i: i2", "");
172172
verify.completionListContains("i2_i_x", "var i2_i_x: number", "");
173173
verify.completionListContains("i2_i_foo", "var i2_i_foo: (b: number) => string", "");
@@ -194,7 +194,7 @@ verify.completionListContains("a", "(parameter) a: number", "i3_i a");
194194

195195
verify.quickInfoAt("40q", "var i3_i: i3");
196196
goTo.marker('40');
197-
verify.completionListContains("i3", "interface i3", "");
197+
verify.not.completionListContains("i3", "interface i3", "");
198198
verify.completionListContains("i3_i", "var i3_i: i3", "");
199199

200200
goTo.marker('41');

tests/cases/fourslash/commentsOverloads.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ verify.completionListContains('f3', 'function f3(a: number): number (+1 overload
295295
verify.completionListContains('f4', 'function f4(a: number): number (+1 overload)', 'this is signature 4 - with number parameter');
296296

297297
goTo.marker('18');
298-
verify.completionListContains('i1', 'interface i1', '');
298+
verify.not.completionListContains('i1', 'interface i1', '');
299299
verify.completionListContains('i1_i', 'var i1_i: new i1(b: number) => any (+1 overload)', '');
300-
verify.completionListContains('i2', 'interface i2', '');
300+
verify.not.completionListContains('i2', 'interface i2', '');
301301
verify.completionListContains('i2_i', 'var i2_i: new i2(a: string) => any (+1 overload)', '');
302-
verify.completionListContains('i3', 'interface i3', '');
302+
verify.not.completionListContains('i3', 'interface i3', '');
303303
verify.completionListContains('i3_i', 'var i3_i: new i3(a: string) => any (+1 overload)', 'new 1');
304-
verify.completionListContains('i4', 'interface i4', '');
304+
verify.not.completionListContains('i4', 'interface i4', '');
305305
verify.completionListContains('i4_i', 'var i4_i: new i4(a: string) => any (+1 overload)', '');
306306

307307
goTo.marker('19');

tests/cases/fourslash/completionListAfterFunction2.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ goTo.marker("1");
99
verify.not.completionListContains("a");
1010

1111
goTo.marker("2");
12+
verify.not.completionListContains("b");
13+
edit.insert("typeof ");
1214
verify.completionListContains("b");
13-

tests/cases/fourslash/completionListCladule.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//// export var x: number;
99
////}
1010
////Foo/*c1*/; // should get "x", "prototype"
11-
////var s: Foo/*c2*/; // should get "x" and "prototype"
11+
////var s: Foo/*c2*/; // no types, in Foo, so shouldnt have anything
1212
////var f = new Foo();
1313
////f/*c3*/;
1414

@@ -20,9 +20,7 @@ verify.completionListContains("staticMethod");
2020

2121
goTo.marker("c2");
2222
edit.insert(".");
23-
verify.completionListContains("x");
24-
verify.completionListContains("staticMethod");
25-
verify.completionListContains("prototype");
23+
verify.completionListIsEmpty();
2624

2725
goTo.marker("c3");
2826
edit.insert(".");

tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
///<reference path="fourslash.ts" />
1+
///<reference path="fourslash.ts" />
22

33
//// var x = class myClass <TypeParam> {
44
//// getClassName (){
55
//// /*0*/
6+
//// var tmp: /*0Type*/;
67
//// }
78
//// prop: Ty/*1*/
89
//// }
910

1011
goTo.marker("0");
12+
verify.not.completionListContains("TypeParam", "(type parameter) TypeParam in myClass<TypeParam>", /*documentation*/ undefined, "type parameter");
13+
goTo.marker("0Type");
1114
verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass<TypeParam>", /*documentation*/ undefined, "type parameter");
1215

1316
goTo.marker("1");

tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber");
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior?
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior?
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

tests/cases/fourslash/completionListInExtendsClause.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ goTo.marker("3");
2727
verify.completionListIsEmpty();
2828

2929
goTo.marker("4");
30-
verify.not.completionListIsEmpty();
30+
verify.completionListIsEmpty();

tests/cases/fourslash/completionListInScope.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ verify.completionListContains("exportedInterface");
8585
verify.completionListContains("localClass");
8686
verify.completionListContains("exportedClass");
8787

88-
verify.completionListContains("localModule");
89-
verify.completionListContains("exportedModule");
88+
verify.not.completionListContains("localModule");
89+
verify.not.completionListContains("exportedModule");
9090

9191
verify.completionListContains("exportedClass2");
92-
verify.completionListContains("exportedModule2");
92+
verify.not.completionListContains("exportedModule2");
9393

9494
goTo.marker("insideMethod");
9595
verify.not.completionListContains("property");

tests/cases/fourslash/completionListInTypeParameterOfTypeAlias1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path='fourslash.ts'/>
1+
/// <reference path='fourslash.ts'/>
22

33
////type List1</*0*/
44
////type List2</*1*/T> = T[];
@@ -8,7 +8,7 @@
88
goTo.marker("0");
99
verify.completionListIsEmpty();
1010
goTo.marker("1");
11-
verify.not.completionListIsEmpty();
11+
verify.completionListIsEmpty();
1212
goTo.marker("2");
1313
verify.completionListContains("T");
1414
goTo.marker("3");
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path='fourslash.ts'/>
1+
/// <reference path='fourslash.ts'/>
22

33
////type Map1<K, /*0*/
44
////type Map1<K, /*1*/V> = [];
@@ -8,12 +8,12 @@
88
goTo.marker("0");
99
verify.completionListIsEmpty();
1010
goTo.marker("1");
11-
verify.completionListContains("V");
11+
verify.completionListIsEmpty();
1212
goTo.marker("2");
1313
verify.completionListContains("K");
1414
verify.completionListContains("V");
1515
goTo.marker("3");
1616
verify.not.completionListContains("K");
1717
verify.not.completionListContains("V");
18-
verify.completionListContains("K1");
19-
verify.completionListContains("V1");
18+
verify.not.completionListContains("K1");
19+
verify.not.completionListContains("V1");
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/// <reference path='fourslash.ts'/>
1+
/// <reference path='fourslash.ts'/>
22

33
//// type constructorType<T1, T2> = new <T/*1*/, /*2*/
44

55
goTo.marker("1");
6-
verify.completionListContains("T");
7-
verify.completionListContains("T1");
8-
verify.completionListContains("T2");
6+
verify.not.completionListContains("T");
7+
verify.not.completionListContains("T1");
8+
verify.not.completionListContains("T2");
99

1010
goTo.marker("2");
11-
verify.completionListContains("T");
12-
verify.completionListContains("T1");
13-
verify.completionListContains("T2");
11+
verify.not.completionListContains("T");
12+
verify.not.completionListContains("T1");
13+
verify.not.completionListContains("T2");

tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
goTo.marker("1");
99
verify.completionListContains("C");
10-
verify.completionListContains("foo"); // ideally this shouldn't show up for a type
10+
verify.not.completionListContains("foo"); // ideally this shouldn't show up for a type
1111
edit.insert("typeof ");
1212
verify.completionListContains("C");
1313
verify.completionListContains("foo");

tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber");
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior?
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ verify.completionListContains("TString");
1414
verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior?
1515

1616
// Ideally the following shouldn't show up since they're not types.
17-
verify.completionListContains("foo");
18-
verify.completionListContains("obj");
17+
verify.not.completionListContains("foo");
18+
verify.not.completionListContains("obj");

0 commit comments

Comments
 (0)