Skip to content

Commit 2077e38

Browse files
authored
Merge pull request #29788 from minestarks/pick-auto-3.3
Port #29785 to release-3.3
2 parents 3d1e115 + a59bdf9 commit 2077e38

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5860,7 +5860,7 @@ namespace ts {
58605860

58615861
export interface UserPreferences {
58625862
readonly disableSuggestions?: boolean;
5863-
readonly quotePreference?: "double" | "single";
5863+
readonly quotePreference?: "auto" | "double" | "single";
58645864
readonly includeCompletionsForModuleExports?: boolean;
58655865
readonly includeCompletionsWithInsertText?: boolean;
58665866
readonly importModuleSpecifierPreference?: "relative" | "non-relative";

src/server/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ namespace ts.server.protocol {
28912891

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

src/services/codefixes/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ namespace ts.codefix {
264264
createNew(
265265
createIdentifier("Error"),
266266
/*typeArguments*/ undefined,
267+
// TODO Handle auto quote preference.
267268
[createLiteral("Method not implemented.", /*isSingleQuote*/ preferences.quotePreference === "single")]))],
268269
/*multiline*/ true);
269270
}

src/services/utilities.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ namespace ts {
13151315
}
13161316

13171317
export function getQuotePreference(sourceFile: SourceFile, preferences: UserPreferences): QuotePreference {
1318-
if (preferences.quotePreference) {
1318+
if (preferences.quotePreference && preferences.quotePreference !== "auto") {
13191319
return preferences.quotePreference === "single" ? QuotePreference.Single : QuotePreference.Double;
13201320
}
13211321
else {
@@ -1868,15 +1868,18 @@ namespace ts {
18681868
if (/^\d+$/.test(text)) {
18691869
return text;
18701870
}
1871+
// Editors can pass in undefined or empty string - we want to infer the preference in those cases.
1872+
const quotePreference = preferences.quotePreference || "auto";
18711873
const quoted = JSON.stringify(text);
1872-
switch (preferences.quotePreference) {
1873-
case undefined:
1874+
switch (quotePreference) {
1875+
// TODO use getQuotePreference to infer the actual quote style.
1876+
case "auto":
18741877
case "double":
18751878
return quoted;
18761879
case "single":
18771880
return `'${stripQuotes(quoted).replace("'", "\\'").replace('\\"', '"')}'`;
18781881
default:
1879-
return Debug.assertNever(preferences.quotePreference);
1882+
return Debug.assertNever(quotePreference);
18801883
}
18811884
}
18821885

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ declare namespace ts {
30093009
}
30103010
interface UserPreferences {
30113011
readonly disableSuggestions?: boolean;
3012-
readonly quotePreference?: "double" | "single";
3012+
readonly quotePreference?: "auto" | "double" | "single";
30133013
readonly includeCompletionsForModuleExports?: boolean;
30143014
readonly includeCompletionsWithInsertText?: boolean;
30153015
readonly importModuleSpecifierPreference?: "relative" | "non-relative";
@@ -7925,7 +7925,7 @@ declare namespace ts.server.protocol {
79257925
}
79267926
interface UserPreferences {
79277927
readonly disableSuggestions?: boolean;
7928-
readonly quotePreference?: "double" | "single";
7928+
readonly quotePreference?: "auto" | "double" | "single";
79297929
/**
79307930
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
79317931
* This affects lone identifier completions but not completions on the right hand side of `obj.`.

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ declare namespace ts {
30093009
}
30103010
interface UserPreferences {
30113011
readonly disableSuggestions?: boolean;
3012-
readonly quotePreference?: "double" | "single";
3012+
readonly quotePreference?: "auto" | "double" | "single";
30133013
readonly includeCompletionsForModuleExports?: boolean;
30143014
readonly includeCompletionsWithInsertText?: boolean;
30153015
readonly importModuleSpecifierPreference?: "relative" | "non-relative";

0 commit comments

Comments
 (0)