@@ -304,7 +304,7 @@ namespace ts.server {
304
304
projects ,
305
305
defaultProject ,
306
306
/*initialLocation*/ undefined ,
307
- ( { project } , tryAddToTodo ) => {
307
+ ( project , _ , tryAddToTodo ) => {
308
308
for ( const output of action ( project ) ) {
309
309
if ( ! contains ( outputs , output , resultsEqual ) && ! tryAddToTodo ( project , getLocation ( output ) ) ) {
310
310
outputs . push ( output ) ;
@@ -329,7 +329,7 @@ namespace ts.server {
329
329
projects ,
330
330
defaultProject ,
331
331
initialLocation ,
332
- ( { project, location } , tryAddToTodo ) => {
332
+ ( project , location , tryAddToTodo ) => {
333
333
for ( const output of project . getLanguageService ( ) . findRenameLocations ( location . fileName , location . pos , findInStrings , findInComments , hostPreferences . providePrefixAndSuffixTextForRename ) || emptyArray ) {
334
334
if ( ! contains ( outputs , output , documentSpansEqual ) && ! tryAddToTodo ( project , documentSpanLocation ( output ) ) ) {
335
335
outputs . push ( output ) ;
@@ -358,7 +358,7 @@ namespace ts.server {
358
358
projects ,
359
359
defaultProject ,
360
360
initialLocation ,
361
- ( { project, location } , getMappedLocation ) => {
361
+ ( project , location , getMappedLocation ) => {
362
362
for ( const outputReferencedSymbol of project . getLanguageService ( ) . findReferences ( location . fileName , location . pos ) || emptyArray ) {
363
363
const mappedDefinitionFile = getMappedLocation ( project , documentSpanLocation ( outputReferencedSymbol . definition ) ) ;
364
364
const definition : ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ?
@@ -408,7 +408,8 @@ namespace ts.server {
408
408
}
409
409
410
410
type CombineProjectOutputCallback < TLocation extends DocumentPosition | undefined > = (
411
- where : ProjectAndLocation < TLocation > ,
411
+ project : Project ,
412
+ location : TLocation ,
412
413
getMappedLocation : ( project : Project , location : DocumentPosition ) => DocumentPosition | undefined ,
413
414
) => void ;
414
415
@@ -422,9 +423,9 @@ namespace ts.server {
422
423
let toDo : ProjectAndLocation < TLocation > [ ] | undefined ;
423
424
const seenProjects = createMap < true > ( ) ;
424
425
forEachProjectInProjects ( projects , initialLocation && initialLocation . fileName , ( project , path ) => {
425
- // TLocation shoud be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
426
+ // TLocation should be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
426
427
const location = ( initialLocation ? { fileName : path , pos : initialLocation . pos } : undefined ) as TLocation ;
427
- toDo = callbackProjectAndLocation ( { project, location } , projectService , toDo , seenProjects , cb ) ;
428
+ toDo = callbackProjectAndLocation ( project , location , projectService , toDo , seenProjects , cb ) ;
428
429
} ) ;
429
430
430
431
// After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
@@ -442,14 +443,16 @@ namespace ts.server {
442
443
if ( ! addToSeen ( seenProjects , project ) ) return ;
443
444
const definition = mapDefinitionInProject ( defaultDefinition , project , getGeneratedDefinition , getSourceDefinition ) ;
444
445
if ( definition ) {
445
- toDo = callbackProjectAndLocation < TLocation > ( { project, location : definition as TLocation } , projectService , toDo , seenProjects , cb ) ;
446
+ toDo = callbackProjectAndLocation < TLocation > ( project , definition as TLocation , projectService , toDo , seenProjects , cb ) ;
446
447
}
447
448
} ) ;
448
449
}
449
450
}
450
451
451
452
while ( toDo && toDo . length ) {
452
- toDo = callbackProjectAndLocation ( Debug . checkDefined ( toDo . pop ( ) ) , projectService , toDo , seenProjects , cb ) ;
453
+ const next = toDo . pop ( ) ;
454
+ Debug . assertIsDefined ( next ) ;
455
+ toDo = callbackProjectAndLocation ( next . project , next . location , projectService , toDo , seenProjects , cb ) ;
453
456
}
454
457
}
455
458
@@ -487,40 +490,42 @@ namespace ts.server {
487
490
}
488
491
489
492
function callbackProjectAndLocation < TLocation extends DocumentPosition | undefined > (
490
- projectAndLocation : ProjectAndLocation < TLocation > ,
493
+ project : Project ,
494
+ location : TLocation ,
491
495
projectService : ProjectService ,
492
496
toDo : ProjectAndLocation < TLocation > [ ] | undefined ,
493
497
seenProjects : Map < true > ,
494
498
cb : CombineProjectOutputCallback < TLocation > ,
495
499
) : ProjectAndLocation < TLocation > [ ] | undefined {
496
- const { project, location } = projectAndLocation ;
497
500
if ( project . getCancellationToken ( ) . isCancellationRequested ( ) ) return undefined ; // Skip rest of toDo if cancelled
498
501
// If this is not the file we were actually looking, return rest of the toDo
499
502
if ( isLocationProjectReferenceRedirect ( project , location ) ) return toDo ;
500
- cb ( projectAndLocation , ( project , location ) => {
501
- addToSeen ( seenProjects , projectAndLocation . project ) ;
502
- const originalLocation = projectService . getOriginalLocationEnsuringConfiguredProject ( project , location ) ;
503
+ cb ( project , location , ( innerProject , location ) => {
504
+ addToSeen ( seenProjects , project ) ;
505
+ const originalLocation = projectService . getOriginalLocationEnsuringConfiguredProject ( innerProject , location ) ;
503
506
if ( ! originalLocation ) return undefined ;
504
507
505
508
const originalScriptInfo = projectService . getScriptInfo ( originalLocation . fileName ) ! ;
506
509
toDo = toDo || [ ] ;
507
510
508
511
for ( const project of originalScriptInfo . containingProjects ) {
509
- addToTodo ( { project, location : originalLocation as TLocation } , toDo , seenProjects ) ;
512
+ addToTodo ( project , originalLocation as TLocation , toDo , seenProjects ) ;
510
513
}
511
514
const symlinkedProjectsMap = projectService . getSymlinkedProjects ( originalScriptInfo ) ;
512
515
if ( symlinkedProjectsMap ) {
513
516
symlinkedProjectsMap . forEach ( ( symlinkedProjects , symlinkedPath ) => {
514
- for ( const symlinkedProject of symlinkedProjects ) addToTodo ( { project : symlinkedProject , location : { fileName : symlinkedPath , pos : originalLocation . pos } as TLocation } , toDo ! , seenProjects ) ;
517
+ for ( const symlinkedProject of symlinkedProjects ) {
518
+ addToTodo ( symlinkedProject , { fileName : symlinkedPath , pos : originalLocation . pos } as TLocation , toDo ! , seenProjects ) ;
519
+ }
515
520
} ) ;
516
521
}
517
522
return originalLocation === location ? undefined : originalLocation ;
518
523
} ) ;
519
524
return toDo ;
520
525
}
521
526
522
- function addToTodo < TLocation extends DocumentPosition | undefined > ( projectAndLocation : ProjectAndLocation < TLocation > , toDo : Push < ProjectAndLocation < TLocation > > , seenProjects : Map < true > ) : void {
523
- if ( addToSeen ( seenProjects , projectAndLocation . project ) ) toDo . push ( projectAndLocation ) ;
527
+ function addToTodo < TLocation extends DocumentPosition | undefined > ( project : Project , location : TLocation , toDo : Push < ProjectAndLocation < TLocation > > , seenProjects : Map < true > ) : void {
528
+ if ( addToSeen ( seenProjects , project ) ) toDo . push ( { project , location } ) ;
524
529
}
525
530
526
531
function addToSeen ( seenProjects : Map < true > , project : Project ) {
@@ -1323,7 +1328,7 @@ namespace ts.server {
1323
1328
// filter handles case when 'projects' is undefined
1324
1329
projects = filter ( projects , p => p . languageServiceEnabled && ! p . isOrphan ( ) ) ;
1325
1330
if ( ! ignoreNoProjectError && ( ! projects || ! projects . length ) && ! symLinkedProjects ) {
1326
- this . projectService . logErrorForScriptInfoNotFound ( args . file ) ;
1331
+ this . projectService . logErrorForScriptInfoNotFound ( args . file ?? args . projectFileName ) ;
1327
1332
return Errors . ThrowNoProject ( ) ;
1328
1333
}
1329
1334
return symLinkedProjects ? { projects : projects ! , symLinkedProjects } : projects ! ; // TODO: GH#18217
@@ -1335,6 +1340,9 @@ namespace ts.server {
1335
1340
if ( project ) {
1336
1341
return project ;
1337
1342
}
1343
+ if ( ! args . file ) {
1344
+ return Errors . ThrowNoProject ( ) ;
1345
+ }
1338
1346
}
1339
1347
const info = this . projectService . getScriptInfo ( args . file ) ! ;
1340
1348
return info . getDefaultProject ( ) ;
@@ -1894,20 +1902,25 @@ namespace ts.server {
1894
1902
}
1895
1903
1896
1904
private getFullNavigateToItems ( args : protocol . NavtoRequestArgs ) : readonly NavigateToItem [ ] {
1897
- const { currentFileOnly, searchValue, maxResultCount } = args ;
1905
+ const { currentFileOnly, searchValue, maxResultCount, projectFileName } = args ;
1898
1906
if ( currentFileOnly ) {
1899
- const { file, project } = this . getFileAndProject ( args ) ;
1907
+ Debug . assertDefined ( args . file ) ;
1908
+ const { file, project } = this . getFileAndProject ( args as protocol . FileRequestArgs ) ;
1900
1909
return project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , file ) ;
1901
1910
}
1902
- else {
1903
- return combineProjectOutputWhileOpeningReferencedProjects < NavigateToItem > (
1904
- this . getProjects ( args ) ,
1905
- this . getDefaultProject ( args ) ,
1906
- project =>
1907
- project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , /*fileName*/ undefined , /*excludeDts*/ project . isNonTsProject ( ) ) ,
1908
- documentSpanLocation ,
1911
+ else if ( ! args . file && ! projectFileName ) {
1912
+ return combineProjectOutputFromEveryProject (
1913
+ this . projectService ,
1914
+ project => project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , /*filename*/ undefined , /*excludeDts*/ project . isNonTsProject ( ) ) ,
1909
1915
navigateToItemIsEqualTo ) ;
1910
1916
}
1917
+ const fileArgs = args as protocol . FileRequestArgs ;
1918
+ return combineProjectOutputWhileOpeningReferencedProjects < NavigateToItem > (
1919
+ this . getProjects ( fileArgs ) ,
1920
+ this . getDefaultProject ( fileArgs ) ,
1921
+ project => project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , /*fileName*/ undefined , /*excludeDts*/ project . isNonTsProject ( ) ) ,
1922
+ documentSpanLocation ,
1923
+ navigateToItemIsEqualTo ) ;
1911
1924
1912
1925
function navigateToItemIsEqualTo ( a : NavigateToItem , b : NavigateToItem ) : boolean {
1913
1926
if ( a === b ) {
0 commit comments