@@ -1506,4 +1506,43 @@ export const value = content;`,
15061506 assert .Equal (t , sourceFile .Text (), `const greeting: string = "hello";` )
15071507 })
15081508 })
1509+
1510+ t .Run ("jsconfig.json used for JS files when tsconfig.json exists in same directory" , func (t * testing.T ) {
1511+ t .Parallel ()
1512+ files := map [string ]any {
1513+ "/home/projects/TS/p1/tsconfig.json" : `{
1514+ "compilerOptions": {
1515+ "noLib": true,
1516+ "strict": true
1517+ }
1518+ }` ,
1519+ "/home/projects/TS/p1/jsconfig.json" : `{
1520+ "compilerOptions": {
1521+ "noLib": true,
1522+ "checkJs": true
1523+ }
1524+ }` ,
1525+ "/home/projects/TS/p1/index.ts" : `export const x: number = 1;` ,
1526+ "/home/projects/TS/p1/app.js" : `/** @type {number} */ var y = "not a number";` ,
1527+ }
1528+ session , _ := projecttestutil .Setup (files )
1529+
1530+ // Open the JS file - it should be assigned to the jsconfig.json project, not tsconfig.json
1531+ session .DidOpenFile (context .Background (), "file:///home/projects/TS/p1/app.js" , 1 , files ["/home/projects/TS/p1/app.js" ].(string ), lsproto .LanguageKindJavaScript )
1532+
1533+ snapshot := session .Snapshot ()
1534+ jsURI := lsproto .DocumentUri ("file:///home/projects/TS/p1/app.js" )
1535+ defaultProject := snapshot .GetDefaultProject (jsURI )
1536+ assert .Assert (t , defaultProject != nil , "JS file should have a default project" )
1537+ assert .Equal (t , defaultProject .Name (), "/home/projects/TS/p1/jsconfig.json" , "JS file should belong to jsconfig.json project, not tsconfig.json" )
1538+
1539+ // Open the TS file - it should be assigned to tsconfig.json project
1540+ session .DidOpenFile (context .Background (), "file:///home/projects/TS/p1/index.ts" , 1 , files ["/home/projects/TS/p1/index.ts" ].(string ), lsproto .LanguageKindTypeScript )
1541+
1542+ snapshot = session .Snapshot ()
1543+ tsURI := lsproto .DocumentUri ("file:///home/projects/TS/p1/index.ts" )
1544+ defaultTSProject := snapshot .GetDefaultProject (tsURI )
1545+ assert .Assert (t , defaultTSProject != nil , "TS file should have a default project" )
1546+ assert .Equal (t , defaultTSProject .Name (), "/home/projects/TS/p1/tsconfig.json" , "TS file should belong to tsconfig.json project" )
1547+ })
15091548}
0 commit comments