Skip to content

Commit

Permalink
31304 - Autocomplete for enum values fails when typing "/" (#31362)
Browse files Browse the repository at this point in the history
31304 - Autocomplete for enum values fails when typing "/"
  • Loading branch information
DanielRosenwasser committed May 24, 2019
2 parents b724c13 + 8965650 commit 38f3b05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/services/completions.ts
Expand Up @@ -49,7 +49,9 @@ namespace ts.Completions {
const compilerOptions = program.getCompilerOptions();

const contextToken = findPrecedingToken(position, sourceFile);
if (triggerCharacter && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)) return undefined;
if (triggerCharacter && !isInString(sourceFile, position, contextToken) && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)) {
return undefined;
}

const stringCompletions = StringCompletions.getStringLiteralCompletions(sourceFile, position, contextToken, typeChecker, compilerOptions, host, log, preferences);
if (stringCompletions) {
Expand Down
30 changes: 30 additions & 0 deletions tests/cases/fourslash/completionsStringsWithTriggerCharacter.ts
@@ -0,0 +1,30 @@
/// <reference path="fourslash.ts" />

//// type A = "a/b" | "b/a";
//// const a: A = "a/*1*/";
////
//// type B = "a@b" | "b@a";
//// const a: B = "a@/*2*/";
////
//// type C = "a.b" | "b.a";
//// const c: C = "a./*3*/";
////
//// type D = "a'b" | "b'a";
//// const d: D = "a'/*4*/";
////
//// type E = "a`b" | "b`a";
//// const e: E = "a`/*5*/";
////
//// type F = 'a"b' | 'b"a';
//// const f: F = 'a"/*6*/';
////
//// type G = "a<b" | "b<a";
//// const g: G = 'a</*7*/';

verify.completions({ marker: '1', exact: ["a/b", "b/a"], triggerCharacter: "/" });
verify.completions({ marker: "2", exact: ["a@b", "b@a"], triggerCharacter: "@" });
verify.completions({ marker: "3", exact: ["a.b", "b.a"], triggerCharacter: "." });
verify.completions({ marker: "4", exact: ["a'b", "b'a"], triggerCharacter: "'" });
verify.completions({ marker: "5", exact: ["a`b", "b`a"], triggerCharacter: "`" });
verify.completions({ marker: "6", exact: ['a"b', 'b"a'], triggerCharacter: '"' });
verify.completions({ marker: "7", exact: ["a<b", "b<a"], triggerCharacter: '<' });

0 comments on commit 38f3b05

Please sign in to comment.