@@ -173,6 +173,18 @@ namespace ts.Completions {
173
173
// var y = require("/*completion position*/");
174
174
return getStringLiteralCompletionEntriesFromModuleNames ( < StringLiteral > node , compilerOptions , host , typeChecker ) ;
175
175
}
176
+ else if ( isEqualityExpression ( node . parent ) ) {
177
+ // Get completions from the type of the other operand
178
+ // i.e. switch (a) {
179
+ // case '/*completion position*/'
180
+ // }
181
+ return getStringLiteralCompletionEntriesFromType ( typeChecker . getTypeAtLocation ( node . parent . left === node ? node . parent . right : node . parent . left ) , typeChecker ) ;
182
+ }
183
+ else if ( isCaseOrDefaultClause ( node . parent ) ) {
184
+ // Get completions from the type of the switch expression
185
+ // i.e. x === '/*completion position'
186
+ return getStringLiteralCompletionEntriesFromType ( typeChecker . getTypeAtLocation ( ( < SwitchStatement > node . parent . parent . parent ) . expression ) , typeChecker ) ;
187
+ }
176
188
else {
177
189
const argumentInfo = SignatureHelp . getImmediatelyContainingArgumentInfo ( node , position , sourceFile ) ;
178
190
if ( argumentInfo ) {
@@ -184,7 +196,7 @@ namespace ts.Completions {
184
196
185
197
// Get completion for string literal from string literal type
186
198
// i.e. var x: "hi" | "hello" = "/*completion position*/"
187
- return getStringLiteralCompletionEntriesFromContextualType ( < StringLiteral > node , typeChecker ) ;
199
+ return getStringLiteralCompletionEntriesFromType ( typeChecker . getContextualType ( < StringLiteral > node ) , typeChecker ) ;
188
200
}
189
201
}
190
202
@@ -228,8 +240,7 @@ namespace ts.Completions {
228
240
return undefined ;
229
241
}
230
242
231
- function getStringLiteralCompletionEntriesFromContextualType ( node : StringLiteral , typeChecker : TypeChecker ) : CompletionInfo | undefined {
232
- const type = typeChecker . getContextualType ( node ) ;
243
+ function getStringLiteralCompletionEntriesFromType ( type : Type , typeChecker : TypeChecker ) : CompletionInfo | undefined {
233
244
if ( type ) {
234
245
const entries : CompletionEntry [ ] = [ ] ;
235
246
addStringLiteralCompletionsFromType ( type , entries , typeChecker ) ;
@@ -1756,4 +1767,15 @@ namespace ts.Completions {
1756
1767
catch ( e ) { }
1757
1768
return undefined ;
1758
1769
}
1770
+
1771
+ function isEqualityExpression ( node : Node ) : node is BinaryExpression {
1772
+ return isBinaryExpression ( node ) && isEqualityOperatorKind ( node . operatorToken . kind ) ;
1773
+ }
1774
+
1775
+ function isEqualityOperatorKind ( kind : SyntaxKind ) {
1776
+ return kind == SyntaxKind . EqualsEqualsToken ||
1777
+ kind === SyntaxKind . ExclamationEqualsToken ||
1778
+ kind === SyntaxKind . EqualsEqualsEqualsToken ||
1779
+ kind === SyntaxKind . ExclamationEqualsEqualsToken ;
1780
+ }
1759
1781
}
0 commit comments