3
3
4
4
namespace ts . projectSystem {
5
5
import TI = server . typingsInstaller ;
6
+ import protocol = server . protocol ;
7
+ import CommandNames = server . CommandNames ;
6
8
7
9
const safeList = {
8
10
path : < Path > "/safeList.json" ,
@@ -128,7 +130,7 @@ namespace ts.projectSystem {
128
130
return combinePaths ( getDirectoryPath ( libFile . path ) , "tsc.js" ) ;
129
131
}
130
132
131
- export function toExternalFile ( fileName : string ) : server . protocol . ExternalFile {
133
+ export function toExternalFile ( fileName : string ) : protocol . ExternalFile {
132
134
return { fileName } ;
133
135
}
134
136
@@ -527,7 +529,7 @@ namespace ts.projectSystem {
527
529
}
528
530
529
531
export function makeSessionRequest < T > ( command : string , args : T ) {
530
- const newRequest : server . protocol . Request = {
532
+ const newRequest : protocol . Request = {
531
533
seq : 0 ,
532
534
type : "request" ,
533
535
command,
@@ -538,7 +540,7 @@ namespace ts.projectSystem {
538
540
539
541
export function openFilesForSession ( files : FileOrFolder [ ] , session : server . Session ) {
540
542
for ( const file of files ) {
541
- const request = makeSessionRequest < server . protocol . OpenRequestArgs > ( server . CommandNames . Open , { file : file . path } ) ;
543
+ const request = makeSessionRequest < protocol . OpenRequestArgs > ( CommandNames . Open , { file : file . path } ) ;
542
544
session . executeCommand ( request ) ;
543
545
}
544
546
}
@@ -1751,7 +1753,7 @@ namespace ts.projectSystem {
1751
1753
} ) ;
1752
1754
1753
1755
describe ( "navigate-to for javascript project" , ( ) => {
1754
- function containsNavToItem ( items : server . protocol . NavtoItem [ ] , itemName : string , itemKind : string ) {
1756
+ function containsNavToItem ( items : protocol . NavtoItem [ ] , itemName : string , itemKind : string ) {
1755
1757
return find ( items , item => item . name === itemName && item . kind === itemKind ) !== undefined ;
1756
1758
}
1757
1759
@@ -1769,12 +1771,12 @@ namespace ts.projectSystem {
1769
1771
openFilesForSession ( [ file1 ] , session ) ;
1770
1772
1771
1773
// Try to find some interface type defined in lib.d.ts
1772
- const libTypeNavToRequest = makeSessionRequest < server . protocol . NavtoRequestArgs > ( server . CommandNames . Navto , { searchValue : "Document" , file : file1 . path , projectFileName : configFile . path } ) ;
1773
- const items : server . protocol . NavtoItem [ ] = session . executeCommand ( libTypeNavToRequest ) . response ;
1774
+ const libTypeNavToRequest = makeSessionRequest < protocol . NavtoRequestArgs > ( CommandNames . Navto , { searchValue : "Document" , file : file1 . path , projectFileName : configFile . path } ) ;
1775
+ const items : protocol . NavtoItem [ ] = session . executeCommand ( libTypeNavToRequest ) . response ;
1774
1776
assert . isFalse ( containsNavToItem ( items , "Document" , "interface" ) , `Found lib.d.ts symbol in JavaScript project nav to request result.` ) ;
1775
1777
1776
- const localFunctionNavToRequst = makeSessionRequest < server . protocol . NavtoRequestArgs > ( server . CommandNames . Navto , { searchValue : "foo" , file : file1 . path , projectFileName : configFile . path } ) ;
1777
- const items2 : server . protocol . NavtoItem [ ] = session . executeCommand ( localFunctionNavToRequst ) . response ;
1778
+ const localFunctionNavToRequst = makeSessionRequest < protocol . NavtoRequestArgs > ( CommandNames . Navto , { searchValue : "foo" , file : file1 . path , projectFileName : configFile . path } ) ;
1779
+ const items2 : protocol . NavtoItem [ ] = session . executeCommand ( localFunctionNavToRequst ) . response ;
1778
1780
assert . isTrue ( containsNavToItem ( items2 , "foo" , "function" ) , `Cannot find function symbol "foo".` ) ;
1779
1781
} ) ;
1780
1782
} ) ;
@@ -2309,4 +2311,80 @@ namespace ts.projectSystem {
2309
2311
serverEventManager . checkEventCountOfType ( "configFileDiag" , 1 ) ;
2310
2312
} ) ;
2311
2313
} ) ;
2314
+
2315
+ describe ( "skipLibCheck" , ( ) => {
2316
+ it ( "should be turned on for js-only inferred projects" , ( ) => {
2317
+ const file1 = {
2318
+ path : "/a/b/file1.js" ,
2319
+ content : `
2320
+ /// <reference path="file2.d.ts" />
2321
+ var x = 1;`
2322
+ } ;
2323
+ const file2 = {
2324
+ path : "/a/b/file2.d.ts" ,
2325
+ content : `
2326
+ interface T {
2327
+ name: string;
2328
+ };
2329
+ interface T {
2330
+ name: number;
2331
+ };`
2332
+ } ;
2333
+ const host = createServerHost ( [ file1 , file2 ] ) ;
2334
+ const session = createSession ( host ) ;
2335
+ openFilesForSession ( [ file1 , file2 ] , session ) ;
2336
+
2337
+ const file2GetErrRequest = makeSessionRequest < protocol . SemanticDiagnosticsSyncRequestArgs > (
2338
+ CommandNames . SemanticDiagnosticsSync ,
2339
+ { file : file2 . path }
2340
+ ) ;
2341
+ let errorResult = < protocol . Diagnostic [ ] > session . executeCommand ( file2GetErrRequest ) . response ;
2342
+ assert . isTrue ( errorResult . length === 0 ) ;
2343
+
2344
+ const closeFileRequest = makeSessionRequest < protocol . FileRequestArgs > ( CommandNames . Close , { file : file1 . path } ) ;
2345
+ session . executeCommand ( closeFileRequest ) ;
2346
+ errorResult = < protocol . Diagnostic [ ] > session . executeCommand ( file2GetErrRequest ) . response ;
2347
+ assert . isTrue ( errorResult . length !== 0 ) ;
2348
+
2349
+ openFilesForSession ( [ file1 ] , session ) ;
2350
+ errorResult = < protocol . Diagnostic [ ] > session . executeCommand ( file2GetErrRequest ) . response ;
2351
+ assert . isTrue ( errorResult . length === 0 ) ;
2352
+ } ) ;
2353
+
2354
+ it ( "should be turned on for js-only external projects" , ( ) => {
2355
+ const jsFile = {
2356
+ path : "/a/b/file1.js" ,
2357
+ content : "let x =1;"
2358
+ } ;
2359
+ const dTsFile = {
2360
+ path : "/a/b/file2.d.ts" ,
2361
+ content : `
2362
+ interface T {
2363
+ name: string;
2364
+ };
2365
+ interface T {
2366
+ name: number;
2367
+ };`
2368
+ } ;
2369
+ const host = createServerHost ( [ jsFile , dTsFile ] ) ;
2370
+ const session = createSession ( host ) ;
2371
+
2372
+ const openExternalProjectRequest = makeSessionRequest < protocol . OpenExternalProjectArgs > (
2373
+ CommandNames . OpenExternalProject ,
2374
+ {
2375
+ projectFileName : "project1" ,
2376
+ rootFiles : toExternalFiles ( [ jsFile . path , dTsFile . path ] ) ,
2377
+ options : { }
2378
+ }
2379
+ ) ;
2380
+ session . executeCommand ( openExternalProjectRequest ) ;
2381
+
2382
+ const dTsFileGetErrRequest = makeSessionRequest < protocol . SemanticDiagnosticsSyncRequestArgs > (
2383
+ CommandNames . SemanticDiagnosticsSync ,
2384
+ { file : dTsFile . path }
2385
+ ) ;
2386
+ const errorResult = < protocol . Diagnostic [ ] > session . executeCommand ( dTsFileGetErrRequest ) . response ;
2387
+ assert . isTrue ( errorResult . length === 0 ) ;
2388
+ } ) ;
2389
+ } ) ;
2312
2390
}
0 commit comments