Skip to content

Commit 8101dc8

Browse files
authored
Merge pull request #16529 from Microsoft/completionWithMeaningReleaseBranch
[release-2.4] Filter completion list according to meaning of the location
2 parents 6c29472 + 20515ce commit 8101dc8

File tree

40 files changed

+1005
-285
lines changed

40 files changed

+1005
-285
lines changed

Gulpfile.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14590,12 +14590,31 @@ namespace ts {
1459014590
? (<PropertyAccessExpression>node).expression
1459114591
: (<QualifiedName>node).left;
1459214592

14593-
const type = checkExpression(left);
14593+
return isValidPropertyAccessWithType(node, left, propertyName, getWidenedType(checkExpression(left)));
14594+
}
14595+
14596+
function isValidPropertyAccessWithType(
14597+
node: PropertyAccessExpression | QualifiedName,
14598+
left: LeftHandSideExpression | QualifiedName,
14599+
propertyName: string,
14600+
type: Type): boolean {
14601+
1459414602
if (type !== unknownType && !isTypeAny(type)) {
14595-
const prop = getPropertyOfType(getWidenedType(type), propertyName);
14603+
const prop = getPropertyOfType(type, propertyName);
1459614604
if (prop) {
1459714605
return checkPropertyAccessibility(node, left, type, prop);
1459814606
}
14607+
14608+
// In js files properties of unions are allowed in completion
14609+
if (isInJavaScriptFile(left) && (type.flags & TypeFlags.Union)) {
14610+
for (const elementType of (<UnionType>type).types) {
14611+
if (isValidPropertyAccessWithType(node, left, propertyName, elementType)) {
14612+
return true;
14613+
}
14614+
}
14615+
}
14616+
14617+
return false;
1459914618
}
1460014619
return true;
1460114620
}

src/harness/fourslash.ts

Lines changed: 5 additions & 2 deletions
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

Lines changed: 129 additions & 43 deletions
Large diffs are not rendered by default.

src/services/utilities.ts

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 1 deletion
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-

0 commit comments

Comments
 (0)