Skip to content

Commit 5b8ecaf

Browse files
committed
Don't show globals (e.g. snippets) in JSX positions
1 parent a31415d commit 5b8ecaf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/services/completions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ namespace ts.Completions {
904904
}
905905
isMemberCompletion = true;
906906
isNewIdentifierLocation = false;
907+
isGlobalCompletion = false;
907908
}
908909
else if (isStartingCloseTag) {
909910
const tagName = (<JsxElement>contextToken.parent.parent).openingElement.tagName;
@@ -914,6 +915,7 @@ namespace ts.Completions {
914915
}
915916
isMemberCompletion = true;
916917
isNewIdentifierLocation = false;
918+
isGlobalCompletion = false;
917919
}
918920
else {
919921
// For JavaScript or TypeScript, if we're not after a dot, then just try to get the
@@ -1001,6 +1003,7 @@ namespace ts.Completions {
10011003
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
10021004
// Cursor is inside a JSX self-closing element or opening element
10031005
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningLikeElement>jsxContainer);
1006+
isGlobalCompletion = false;
10041007

10051008
if (attrsType) {
10061009
symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), (<JsxOpeningLikeElement>jsxContainer).attributes);

tests/cases/fourslash/completionListIsGlobalCompletion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path='fourslash.ts'/>
22

3+
//@Filename: file.tsx
34
/////// <reference path="/*1*/..\services\services.ts" /> // no globals in reference paths
45
////import { /*2*/ } from "./file.ts"; // no globals in imports
56
////var test = "/*3*/"; // no globals in strings
@@ -20,6 +21,7 @@
2021
//// /*9*/ // insert globals
2122
////}
2223
/////*10*/ // insert globals
24+
////const y = <div /*11*/ />;
2325
goTo.marker("1");
2426
verify.completionListIsGlobal(false);
2527
goTo.marker("2");
@@ -40,3 +42,5 @@ goTo.marker("9");
4042
verify.completionListIsGlobal(true);
4143
goTo.marker("10");
4244
verify.completionListIsGlobal(true);
45+
goTo.marker("11");
46+
verify.completionListIsGlobal(false);

0 commit comments

Comments
 (0)