@@ -1909,4 +1909,45 @@ namespace ts.projectSystem {
19091909 checkProjectActualFiles ( projectService . configuredProjects [ 0 ] , [ f1 . path , barTypings . path ] ) ;
19101910 } ) ;
19111911 } ) ;
1912+
1913+ describe ( "format settings" , ( ) => {
1914+ it ( "can be set globally" , ( ) => {
1915+ const f1 = {
1916+ path : "/a/b/app.ts" ,
1917+ content : "let x;"
1918+ } ;
1919+ const host = createServerHost ( [ f1 ] ) ;
1920+ const projectService = createProjectService ( host ) ;
1921+ projectService . openClientFile ( f1 . path ) ;
1922+
1923+ const defaultSettings = projectService . getFormatCodeOptions ( ) ;
1924+
1925+ // set global settings
1926+ const newGlobalSettings1 = clone ( defaultSettings ) ;
1927+ newGlobalSettings1 . placeOpenBraceOnNewLineForControlBlocks = ! newGlobalSettings1 . placeOpenBraceOnNewLineForControlBlocks ;
1928+ projectService . setHostConfiguration ( { formatOptions : newGlobalSettings1 } ) ;
1929+
1930+ // get format options for file - should be equal to new global settings
1931+ const s1 = projectService . getFormatCodeOptions ( server . toNormalizedPath ( f1 . path ) ) ;
1932+ assert . deepEqual ( s1 , newGlobalSettings1 , "file settings should be the same with global settings" ) ;
1933+
1934+ // set per file format options
1935+ const newPerFileSettings = clone ( defaultSettings ) ;
1936+ newPerFileSettings . insertSpaceAfterCommaDelimiter = ! newPerFileSettings . insertSpaceAfterCommaDelimiter ;
1937+ projectService . setHostConfiguration ( { formatOptions : newPerFileSettings , file : f1 . path } ) ;
1938+
1939+ // get format options for file - should be equal to new per-file settings
1940+ const s2 = projectService . getFormatCodeOptions ( server . toNormalizedPath ( f1 . path ) ) ;
1941+ assert . deepEqual ( s2 , newPerFileSettings , "file settings should be the same with per-file settings" ) ;
1942+
1943+ // set new global settings - they should not affect ones that were set per-file
1944+ const newGlobalSettings2 = clone ( defaultSettings ) ;
1945+ newGlobalSettings2 . insertSpaceAfterSemicolonInForStatements = ! newGlobalSettings2 . insertSpaceAfterSemicolonInForStatements ;
1946+ projectService . setHostConfiguration ( { formatOptions : newGlobalSettings2 } ) ;
1947+
1948+ // get format options for file - should be equal to new per-file settings
1949+ const s3 = projectService . getFormatCodeOptions ( server . toNormalizedPath ( f1 . path ) ) ;
1950+ assert . deepEqual ( s3 , newPerFileSettings , "file settings should still be the same with per-file settings" ) ;
1951+ } ) ;
1952+ } ) ;
19121953}
0 commit comments