Merge pull request #29785 from jessetrinity/add-auto-quotepreference

Add explicit "auto" quotePreference
This commit is contained in:
Mine Starks 2019-02-06 15:43:41 -08:00 committed by GitHub
commit c03af51186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 9 deletions

View File

@ -5864,7 +5864,7 @@ namespace ts {
export interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly quotePreference?: "auto" | "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
readonly importModuleSpecifierPreference?: "relative" | "non-relative";

View File

@ -2891,7 +2891,7 @@ namespace ts.server.protocol {
export interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly quotePreference?: "auto" | "double" | "single";
/**
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
* This affects lone identifier completions but not completions on the right hand side of `obj.`.

View File

@ -264,6 +264,7 @@ namespace ts.codefix {
createNew(
createIdentifier("Error"),
/*typeArguments*/ undefined,
// TODO Handle auto quote preference.
[createLiteral("Method not implemented.", /*isSingleQuote*/ preferences.quotePreference === "single")]))],
/*multiline*/ true);
}

View File

@ -1315,7 +1315,7 @@ namespace ts {
}
export function getQuotePreference(sourceFile: SourceFile, preferences: UserPreferences): QuotePreference {
if (preferences.quotePreference) {
if (preferences.quotePreference && preferences.quotePreference !== "auto") {
return preferences.quotePreference === "single" ? QuotePreference.Single : QuotePreference.Double;
}
else {
@ -1868,15 +1868,18 @@ namespace ts {
if (/^\d+$/.test(text)) {
return text;
}
// Editors can pass in undefined or empty string - we want to infer the preference in those cases.
const quotePreference = preferences.quotePreference || "auto";
const quoted = JSON.stringify(text);
switch (preferences.quotePreference) {
case undefined:
switch (quotePreference) {
// TODO use getQuotePreference to infer the actual quote style.
case "auto":
case "double":
return quoted;
case "single":
return `'${stripQuotes(quoted).replace("'", "\\'").replace('\\"', '"')}'`;
default:
return Debug.assertNever(preferences.quotePreference);
return Debug.assertNever(quotePreference);
}
}

View File

@ -3010,7 +3010,7 @@ declare namespace ts {
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly quotePreference?: "auto" | "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
readonly importModuleSpecifierPreference?: "relative" | "non-relative";
@ -7927,7 +7927,7 @@ declare namespace ts.server.protocol {
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly quotePreference?: "auto" | "double" | "single";
/**
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
* This affects lone identifier completions but not completions on the right hand side of `obj.`.

View File

@ -3010,7 +3010,7 @@ declare namespace ts {
}
interface UserPreferences {
readonly disableSuggestions?: boolean;
readonly quotePreference?: "double" | "single";
readonly quotePreference?: "auto" | "double" | "single";
readonly includeCompletionsForModuleExports?: boolean;
readonly includeCompletionsWithInsertText?: boolean;
readonly importModuleSpecifierPreference?: "relative" | "non-relative";