Skip to content

Commit ab4d003

Browse files
Merge branch 'master' into transitiveExports
2 parents 54e1928 + 631a9d8 commit ab4d003

19 files changed

+190
-34
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,6 +3865,7 @@ module ts {
38653865
let expandingFlags: number;
38663866
let depth = 0;
38673867
let overflow = false;
3868+
let elaborateErrors = false;
38683869

38693870
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
38703871

@@ -3879,7 +3880,8 @@ module ts {
38793880
// where errors were being reported.
38803881
if (errorInfo.next === undefined) {
38813882
errorInfo = undefined;
3882-
isRelatedTo(source, target, errorNode !== undefined, headMessage, /* elaborateErrors */ true);
3883+
elaborateErrors = true;
3884+
isRelatedTo(source, target, errorNode !== undefined, headMessage);
38833885
}
38843886
if (containingMessageChain) {
38853887
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
@@ -3897,7 +3899,7 @@ module ts {
38973899
// Ternary.True if they are related with no assumptions,
38983900
// Ternary.Maybe if they are related with assumptions of other relationships, or
38993901
// Ternary.False if they are not related.
3900-
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, elaborateErrors = false): Ternary {
3902+
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
39013903
let result: Ternary;
39023904
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
39033905
if (source === target) return Ternary.True;
@@ -3964,7 +3966,7 @@ module ts {
39643966
// identity relation does not use apparent type
39653967
let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
39663968
if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType &&
3967-
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors, elaborateErrors))) {
3969+
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors))) {
39683970
errorInfo = saveErrorInfo;
39693971
return result;
39703972
}
@@ -4061,7 +4063,7 @@ module ts {
40614063
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
40624064
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
40634065
// and issue an error. Otherwise, actually compare the structure of the two types.
4064-
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean, elaborateErrors = false): Ternary {
4066+
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
40654067
if (overflow) {
40664068
return Ternary.False;
40674069
}

src/server/editorServices.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path="..\compiler\commandLineParser.ts" />
22
/// <reference path="..\services\services.ts" />
3+
/// <reference path="protocol.d.ts" />
4+
/// <reference path="session.ts" />
35
/// <reference path="node.d.ts" />
46

57
module ts.server {
@@ -16,6 +18,16 @@ module ts.server {
1618

1719
var lineCollectionCapacity = 4;
1820

21+
function mergeFormatOptions(formatCodeOptions: FormatCodeOptions, formatOptions: protocol.FormatOptions): void {
22+
var hasOwnProperty = Object.prototype.hasOwnProperty;
23+
Object.keys(formatOptions).forEach((key) => {
24+
var codeKey = key.charAt(0).toUpperCase() + key.substring(1);
25+
if (hasOwnProperty.call(formatCodeOptions, codeKey)) {
26+
formatCodeOptions[codeKey] = formatOptions[key];
27+
}
28+
});
29+
}
30+
1931
class ScriptInfo {
2032
svc: ScriptVersionCache;
2133
children: ScriptInfo[] = []; // files referenced by this file
@@ -27,12 +39,9 @@ module ts.server {
2739
this.svc = ScriptVersionCache.fromString(content);
2840
}
2941

30-
setFormatOptions(tabSize?: number, indentSize?: number) {
31-
if (tabSize) {
32-
this.formatCodeOptions.TabSize = tabSize;
33-
}
34-
if (indentSize) {
35-
this.formatCodeOptions.IndentSize = indentSize;
42+
setFormatOptions(formatOptions: protocol.FormatOptions): void {
43+
if (formatOptions) {
44+
mergeFormatOptions(this.formatCodeOptions, formatOptions);
3645
}
3746
}
3847

@@ -448,15 +457,19 @@ module ts.server {
448457
if (args.file) {
449458
var info = this.filenameToScriptInfo[args.file];
450459
if (info) {
451-
info.setFormatOptions(args.tabSize, args.indentSize);
452-
this.log("Host configuration update for file " + args.file + " tab size " + args.tabSize);
460+
info.setFormatOptions(args.formatOptions);
461+
this.log("Host configuration update for file " + args.file);
453462
}
454463
}
455464
else {
456-
this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize;
457-
this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize;
458-
this.hostConfiguration.hostInfo = args.hostInfo;
459-
this.log("Host information " + args.hostInfo, "Info");
465+
if (args.hostInfo !== undefined) {
466+
this.hostConfiguration.hostInfo = args.hostInfo;
467+
this.log("Host information " + args.hostInfo, "Info");
468+
}
469+
if (args.formatOptions) {
470+
mergeFormatOptions(this.hostConfiguration.formatCodeOptions, args.formatOptions);
471+
this.log("Format host information updated", "Info");
472+
}
460473
}
461474
}
462475

src/server/protocol.d.ts

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,77 @@ declare module ts.server.protocol {
299299
body?: RenameResponseBody;
300300
}
301301

302+
/**
303+
* Editor options
304+
*/
305+
export interface EditorOptions {
306+
307+
/** Number of spaces for each tab. Default value is 4. */
308+
tabSize?: number;
309+
310+
/** Number of spaces to indent during formatting. Default value is 4. */
311+
indentSize?: number;
312+
313+
/** The new line character to be used. Default value is the OS line delimiter. */
314+
newLineCharacter?: string;
315+
316+
/** Whether tabs should be converted to spaces. Default value is true. */
317+
convertTabsToSpaces?: boolean;
318+
}
319+
320+
/**
321+
* Format options
322+
*/
323+
export interface FormatOptions extends EditorOptions {
324+
325+
/** Defines space handling after a comma delimiter. Default value is true. */
326+
insertSpaceAfterCommaDelimiter?: boolean;
327+
328+
/** Defines space handling after a semicolon in a for statemen. Default value is true */
329+
insertSpaceAfterSemicolonInForStatements?: boolean;
330+
331+
/** Defines space handling after a binary operator. Default value is true. */
332+
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
333+
334+
/** Defines space handling after keywords in control flow statement. Default value is true. */
335+
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
336+
337+
/** Defines space handling after function keyword for anonymous functions. Default value is false. */
338+
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
339+
340+
/** Defines space handling after opening and before closing non empty parenthesis. Default value is false. */
341+
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
342+
343+
/** Defines whether an open brace is put onto a new line for functions or not. Default value is false. */
344+
placeOpenBraceOnNewLineForFunctions?: boolean;
345+
346+
/** Defines whether an open brace is put onto a new line for control blocks or not. Default value is false. */
347+
placeOpenBraceOnNewLineForControlBlocks?: boolean;
348+
349+
/** Index operator */
350+
[key:string] : string | number | boolean;
351+
}
352+
302353
/**
303354
* Information found in a configure request.
304355
*/
305356
export interface ConfigureRequestArguments {
306-
/** Number of spaces for each tab */
307-
tabSize: number;
308-
/** Number of spaces to indent during formatting */
309-
indentSize: number;
357+
310358
/**
311359
* Information about the host, for example 'Emacs 24.4' or
312360
* 'Sublime Text version 3075'
313361
*/
314-
hostInfo: string;
362+
hostInfo?: string;
363+
315364
/**
316365
* If present, tab settings apply only to this file.
317366
*/
318367
file?: string;
368+
369+
/**
370+
* The format options to use during formatting and other code editing features.
371+
*/
372+
formatOptions?: FormatOptions;
319373
}
320374

321375
/**
@@ -337,10 +391,6 @@ declare module ts.server.protocol {
337391
* Information found in an "open" request.
338392
*/
339393
export interface OpenRequestArgs extends FileRequestArgs {
340-
/** Initial tab size of file. */
341-
tabSize?: number;
342-
/** Number of spaces to indent during formatting */
343-
indentSize?: number;
344394
}
345395

346396
/**

src/server/session.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,9 @@ module ts.server {
398398
};
399399
}
400400

401-
openClientFile(fileName: string, tabSize?: number, indentSize?: number) {
401+
openClientFile(fileName: string) {
402402
var file = ts.normalizePath(fileName);
403-
var info = this.projectService.openClientFile(file);
404-
if (info) {
405-
info.setFormatOptions(tabSize, indentSize);
406-
}
403+
this.projectService.openClientFile(file);
407404
}
408405

409406
getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
@@ -789,7 +786,7 @@ module ts.server {
789786
}
790787
case CommandNames.Open: {
791788
var openArgs = <protocol.OpenRequestArgs>request.arguments;
792-
this.openClientFile(openArgs.file,openArgs.tabSize, openArgs.indentSize);
789+
this.openClientFile(openArgs.file);
793790
responseRequired = false;
794791
break;
795792
}

tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,59): error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
22
Type 'B' is not assignable to type 'C'.
3+
Property 'z' is missing in type 'B'.
34

45

56
==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (1 errors) ====
@@ -24,4 +25,5 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete
2425
(new Chain(new A)).then(a => new B).then(b => new C).then(c => new B).then(b => new A);
2526
~~~~~~~~~~
2627
!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
27-
!!! error TS2345: Type 'B' is not assignable to type 'C'.
28+
!!! error TS2345: Type 'B' is not assignable to type 'C'.
29+
!!! error TS2345: Property 'z' is missing in type 'B'.

tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(16,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
22
Type 'string' is not assignable to type 'Date'.
3+
Property 'toDateString' is missing in type 'String'.
34
tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
45
Type 'string' is not assignable to type 'Date'.
56

@@ -24,6 +25,7 @@ tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32):
2425
~
2526
!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
2627
!!! error TS2345: Type 'string' is not assignable to type 'Date'.
28+
!!! error TS2345: Property 'toDateString' is missing in type 'String'.
2729
var r6 = _.forEach<number>(c2, (x) => { return x.toFixed() });
2830
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2931
!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.

tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen
55
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
66
Types of parameters 'a' and 'x' are incompatible.
77
Type 'T' is not assignable to type 'Date'.
8+
Property 'toDateString' is missing in type 'RegExp'.
89
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
910
Type 'F' is not assignable to type 'E'.
1011
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
@@ -53,6 +54,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen
5354
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
5455
!!! error TS2345: Types of parameters 'a' and 'x' are incompatible.
5556
!!! error TS2345: Type 'T' is not assignable to type 'Date'.
57+
!!! error TS2345: Property 'toDateString' is missing in type 'RegExp'.
5658
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
5759
}
5860

tests/baselines/reference/genericCombinators2.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/compiler/genericCombinators2.ts(15,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
22
Type 'string' is not assignable to type 'Date'.
3+
Property 'toDateString' is missing in type 'String'.
34
tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
45
Type 'string' is not assignable to type 'Date'.
56

@@ -23,6 +24,7 @@ tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of ty
2324
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2425
!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.
2526
!!! error TS2345: Type 'string' is not assignable to type 'Date'.
27+
!!! error TS2345: Property 'toDateString' is missing in type 'String'.
2628
var r5b = _.map<number, string, Date>(c2, rf1);
2729
~~~
2830
!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'.

tests/baselines/reference/incompatibleTypes.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tests/cases/compiler/incompatibleTypes.ts(33,7): error TS2420: Class 'C4' incorr
1717
tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
1818
Types of property 'p1' are incompatible.
1919
Type '() => string' is not assignable to type '(s: string) => number'.
20+
Type 'string' is not assignable to type 'number'.
2021
tests/cases/compiler/incompatibleTypes.ts(49,5): error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'.
2122
Property 'c' is missing in type '{ e: number; f: number; }'.
2223
tests/cases/compiler/incompatibleTypes.ts(66,5): error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
@@ -92,6 +93,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
9293
!!! error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
9394
!!! error TS2345: Types of property 'p1' are incompatible.
9495
!!! error TS2345: Type '() => string' is not assignable to type '(s: string) => number'.
96+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
9597

9698

9799
function of1(n: { a: { a: string; }; b: string; }): number;

tests/baselines/reference/interfaceAssignmentCompat.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tests/cases/compiler/interfaceAssignmentCompat.ts(32,18): error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'.
22
Types of parameters 'a' and 'a' are incompatible.
33
Type 'IFrenchEye' is not assignable to type 'IEye'.
4+
Property 'color' is missing in type 'IFrenchEye'.
45
tests/cases/compiler/interfaceAssignmentCompat.ts(37,29): error TS2339: Property '_map' does not exist on type 'typeof Color'.
56
tests/cases/compiler/interfaceAssignmentCompat.ts(42,13): error TS2322: Type 'IEye' is not assignable to type 'IFrenchEye'.
67
Property 'coleur' is missing in type 'IEye'.
@@ -45,6 +46,7 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2322: Type 'IEy
4546
!!! error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'.
4647
!!! error TS2345: Types of parameters 'a' and 'a' are incompatible.
4748
!!! error TS2345: Type 'IFrenchEye' is not assignable to type 'IEye'.
49+
!!! error TS2345: Property 'color' is missing in type 'IFrenchEye'.
4850
// type of z inferred from specialized array type
4951
var z=x.sort(CompareEyes); // ok
5052

0 commit comments

Comments
 (0)