FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TypeScript/src/server/session.ts at master · java08800/TypeScript · GitHub
TypeScript/src/server/session.ts at master · java08800/TypeScript · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
Accelerator
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
java08800
/
TypeScript
Public
forked from
microsoft/TypeScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TypeScript
/
src
/
server
/
session.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
2582 lines (2319 loc) · 134 KB
Breadcrumbs
TypeScript
/
src
/
server
/
session.ts
Copy path
File metadata and controls
2582 lines (2319 loc) · 134 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
namespace
ts
.
server
{
interface
StackTraceError
extends
Error
{
stack
?:
string
;
}
export
interface
ServerCancellationToken
extends
HostCancellationToken
{
setRequest
(
requestId
:
number
)
:
void
;
resetRequest
(
requestId
:
number
)
:
void
;
}
export
const
nullCancellationToken
:
ServerCancellationToken
=
{
isCancellationRequested
:
(
)
=>
false
,
setRequest
:
(
)
=>
void
0
,
resetRequest
:
(
)
=>
void
0
}
;
function
hrTimeToMilliseconds
(
time
:
number
[
]
)
:
number
{
const
seconds
=
time
[
0
]
;
const
nanoseconds
=
time
[
1
]
;
return
(
(
1e9
*
seconds
)
+
nanoseconds
)
/
1000000.0
;
}
function
isDeclarationFileInJSOnlyNonConfiguredProject
(
project
:
Project
,
file
:
NormalizedPath
)
{
// Checking for semantic diagnostics is an expensive process. We want to avoid it if we
// know for sure it is not needed.
// For instance, .d.ts files injected by ATA automatically do not produce any relevant
// errors to a JS- only project.
//
// Note that configured projects can set skipLibCheck (on by default in jsconfig.json) to
// disable checking for declaration files. We only need to verify for inferred projects (e.g.
// miscellaneous context in VS) and external projects(e.g.VS.csproj project) with only JS
// files.
//
// We still want to check .js files in a JS-only inferred or external project (e.g. if the
// file has '// @ts-check').
if
(
(
project
.
projectKind
===
ProjectKind
.
Inferred
||
project
.
projectKind
===
ProjectKind
.
External
)
&&
project
.
isJsOnlyProject
(
)
)
{
const
scriptInfo
=
project
.
getScriptInfoForNormalizedPath
(
file
)
;
return
scriptInfo
&&
!
scriptInfo
.
isJavaScript
(
)
;
}
return
false
;
}
function
formatDiag
(
fileName
:
NormalizedPath
,
project
:
Project
,
diag
:
Diagnostic
)
:
protocol
.
Diagnostic
{
const
scriptInfo
=
project
.
getScriptInfoForNormalizedPath
(
fileName
)
!
;
// TODO: GH#18217
return
{
start
:
scriptInfo
.
positionToLineOffset
(
diag
.
start
!
)
,
end
:
scriptInfo
.
positionToLineOffset
(
diag
.
start
!
+
diag
.
length
!
)
,
// TODO: GH#18217
text
:
flattenDiagnosticMessageText
(
diag
.
messageText
,
"\n"
)
,
code
:
diag
.
code
,
category
:
diagnosticCategoryName
(
diag
)
,
reportsUnnecessary
:
diag
.
reportsUnnecessary
,
source
:
diag
.
source
,
relatedInformation
:
map
(
diag
.
relatedInformation
,
formatRelatedInformation
)
,
}
;
}
function
formatRelatedInformation
(
info
:
DiagnosticRelatedInformation
)
:
protocol
.
DiagnosticRelatedInformation
{
if
(
!
info
.
file
)
{
return
{
message
:
flattenDiagnosticMessageText
(
info
.
messageText
,
"\n"
)
,
category
:
diagnosticCategoryName
(
info
)
,
code
:
info
.
code
}
;
}
return
{
span
:
{
start
:
convertToLocation
(
getLineAndCharacterOfPosition
(
info
.
file
,
info
.
start
!
)
)
,
end
:
convertToLocation
(
getLineAndCharacterOfPosition
(
info
.
file
,
info
.
start
!
+
info
.
length
!
)
)
,
// TODO: GH#18217
file
:
info
.
file
.
fileName
}
,
message
:
flattenDiagnosticMessageText
(
info
.
messageText
,
"\n"
)
,
category
:
diagnosticCategoryName
(
info
)
,
code
:
info
.
code
}
;
}
function
convertToLocation
(
lineAndCharacter
:
LineAndCharacter
)
:
protocol
.
Location
{
return
{
line
:
lineAndCharacter
.
line
+
1
,
offset
:
lineAndCharacter
.
character
+
1
}
;
}
function
formatConfigFileDiag
(
diag
:
Diagnostic
,
includeFileName
:
true
)
:
protocol
.
DiagnosticWithFileName
;
function
formatConfigFileDiag
(
diag
:
Diagnostic
,
includeFileName
:
false
)
:
protocol
.
Diagnostic
;
function
formatConfigFileDiag
(
diag
:
Diagnostic
,
includeFileName
:
boolean
)
:
protocol
.
Diagnostic
|
protocol
.
DiagnosticWithFileName
{
const
start
=
(
diag
.
file
&&
convertToLocation
(
getLineAndCharacterOfPosition
(
diag
.
file
,
diag
.
start
!
)
)
)
!
;
// TODO: GH#18217
const
end
=
(
diag
.
file
&&
convertToLocation
(
getLineAndCharacterOfPosition
(
diag
.
file
,
diag
.
start
!
+
diag
.
length
!
)
)
)
!
;
// TODO: GH#18217
const
text
=
flattenDiagnosticMessageText
(
diag
.
messageText
,
"\n"
)
;
const
{
code
,
source
}
=
diag
;
const
category
=
diagnosticCategoryName
(
diag
)
;
const
common
=
{
start
,
end
,
text
,
code
,
category
,
reportsUnnecessary
:
diag
.
reportsUnnecessary
,
source
,
relatedInformation
:
map
(
diag
.
relatedInformation
,
formatRelatedInformation
)
,
}
;
return
includeFileName
?
{
...
common
,
fileName
:
diag
.
file
&&
diag
.
file
.
fileName
}
:
common
;
}
export
interface
PendingErrorCheck
{
fileName
:
NormalizedPath
;
project
:
Project
;
}
function
allEditsBeforePos
(
edits
:
ReadonlyArray
<
TextChange
>
,
pos
:
number
)
:
boolean
{
return
edits
.
every
(
edit
=>
textSpanEnd
(
edit
.
span
)
<
pos
)
;
}
// CommandNames used to be exposed before TS 2.4 as a namespace
// In TS 2.4 we switched to an enum, keep this for backward compatibility
// The var assignment ensures that even though CommandTypes are a const enum
// we want to ensure the value is maintained in the out since the file is
// built using --preseveConstEnum.
export
type
CommandNames
=
protocol
.
CommandTypes
;
export
const
CommandNames
=
(
<
any
>
protocol
)
.
CommandTypes
;
// tslint:disable-line variable-name
export
function
formatMessage
<
T
extends
protocol
.
Message
>
(
msg
:
T
,
logger
:
Logger
,
byteLength
:
(
s
:
string
,
encoding
:
string
)
=>
number
,
newLine
:
string
)
:
string
{
const
verboseLogging
=
logger
.
hasLevel
(
LogLevel
.
verbose
)
;
const
json
=
JSON
.
stringify
(
msg
)
;
if
(
verboseLogging
)
{
logger
.
info
(
`
${
msg
.
type
}
:
${
indent
(
json
)
}
`
)
;
}
const
len
=
byteLength
(
json
,
"utf8"
)
;
return
`Content-Length:
${
1
+
len
}
\r\n\r\n
${
json
}
${
newLine
}
`
;
}
/**
* Allows to schedule next step in multistep operation
*/
interface
NextStep
{
immediate
(
action
:
(
)
=>
void
)
:
void
;
delay
(
ms
:
number
,
action
:
(
)
=>
void
)
:
void
;
}
/**
* External capabilities used by multistep operation
*/
interface
MultistepOperationHost
{
getCurrentRequestId
(
)
:
number
;
sendRequestCompletedEvent
(
requestId
:
number
)
:
void
;
getServerHost
(
)
:
ServerHost
;
isCancellationRequested
(
)
:
boolean
;
executeWithRequestId
(
requestId
:
number
,
action
:
(
)
=>
void
)
:
void
;
logError
(
error
:
Error
,
message
:
string
)
:
void
;
}
/**
* Represents operation that can schedule its next step to be executed later.
* Scheduling is done via instance of NextStep. If on current step subsequent step was not scheduled - operation is assumed to be completed.
*/
class
MultistepOperation
implements
NextStep
{
private
requestId
:
number
|
undefined
;
private
timerHandle
:
any
;
private
immediateId
:
number
|
undefined
;
constructor
(
private
readonly
operationHost
:
MultistepOperationHost
)
{
}
public
startNew
(
action
:
(
next
:
NextStep
)
=>
void
)
{
this
.
complete
(
)
;
this
.
requestId
=
this
.
operationHost
.
getCurrentRequestId
(
)
;
this
.
executeAction
(
action
)
;
}
private
complete
(
)
{
if
(
this
.
requestId
!==
undefined
)
{
this
.
operationHost
.
sendRequestCompletedEvent
(
this
.
requestId
)
;
this
.
requestId
=
undefined
;
}
this
.
setTimerHandle
(
undefined
)
;
this
.
setImmediateId
(
undefined
)
;
}
public
immediate
(
action
:
(
)
=>
void
)
{
const
requestId
=
this
.
requestId
!
;
Debug
.
assert
(
requestId
===
this
.
operationHost
.
getCurrentRequestId
(
)
,
"immediate: incorrect request id"
)
;
this
.
setImmediateId
(
this
.
operationHost
.
getServerHost
(
)
.
setImmediate
(
(
)
=>
{
this
.
immediateId
=
undefined
;
this
.
operationHost
.
executeWithRequestId
(
requestId
,
(
)
=>
this
.
executeAction
(
action
)
)
;
}
)
)
;
}
public
delay
(
ms
:
number
,
action
:
(
)
=>
void
)
{
const
requestId
=
this
.
requestId
!
;
Debug
.
assert
(
requestId
===
this
.
operationHost
.
getCurrentRequestId
(
)
,
"delay: incorrect request id"
)
;
this
.
setTimerHandle
(
this
.
operationHost
.
getServerHost
(
)
.
setTimeout
(
(
)
=>
{
this
.
timerHandle
=
undefined
;
this
.
operationHost
.
executeWithRequestId
(
requestId
,
(
)
=>
this
.
executeAction
(
action
)
)
;
}
,
ms
)
)
;
}
private
executeAction
(
action
:
(
next
:
NextStep
)
=>
void
)
{
let
stop
=
false
;
try
{
if
(
this
.
operationHost
.
isCancellationRequested
(
)
)
{
stop
=
true
;
}
else
{
action
(
this
)
;
}
}
catch
(
e
)
{
stop
=
true
;
// ignore cancellation request
if
(
!
(
e
instanceof
OperationCanceledException
)
)
{
this
.
operationHost
.
logError
(
e
,
`delayed processing of request
${
this
.
requestId
}
`
)
;
}
}
if
(
stop
||
!
this
.
hasPendingWork
(
)
)
{
this
.
complete
(
)
;
}
}
private
setTimerHandle
(
timerHandle
:
any
)
{
if
(
this
.
timerHandle
!==
undefined
)
{
this
.
operationHost
.
getServerHost
(
)
.
clearTimeout
(
this
.
timerHandle
)
;
}
this
.
timerHandle
=
timerHandle
;
}
private
setImmediateId
(
immediateId
:
number
|
undefined
)
{
if
(
this
.
immediateId
!==
undefined
)
{
this
.
operationHost
.
getServerHost
(
)
.
clearImmediate
(
this
.
immediateId
)
;
}
this
.
immediateId
=
immediateId
;
}
private
hasPendingWork
(
)
{
return
!
!
this
.
timerHandle
||
!
!
this
.
immediateId
;
}
}
export
type
Event
=
<
T
extends
object
>
(
body
:
T
,
eventName
:
string
)
=>
void
;
export
interface
EventSender
{
event
:
Event
;
}
/**
@internal
*/
export
function
toEvent
(
eventName
:
string
,
body
:
object
)
:
protocol
.
Event
{
return
{
seq
:
0
,
type
:
"event"
,
event
:
eventName
,
body
}
;
}
type
Projects
=
ReadonlyArray
<
Project
>
|
{
readonly
projects
:
ReadonlyArray
<
Project
>
;
readonly
symLinkedProjects
:
MultiMap
<
Project
>
;
}
;
/**
* This helper function processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
*/
function
combineProjectOutput
<
T
,
U
>
(
defaultValue
:
T
,
getValue
:
(
path
:
Path
)
=>
T
,
projects
:
Projects
,
action
:
(
project
:
Project
,
value
:
T
)
=>
ReadonlyArray
<
U
>
|
U
|
undefined
,
)
:
U
[
]
{
const
outputs
=
flatMapToMutable
(
isArray
(
projects
)
?
projects
:
projects
.
projects
,
project
=>
action
(
project
,
defaultValue
)
)
;
if
(
!
isArray
(
projects
)
&&
projects
.
symLinkedProjects
)
{
projects
.
symLinkedProjects
.
forEach
(
(
projects
,
path
)
=>
{
const
value
=
getValue
(
path
as
Path
)
;
outputs
.
push
(
...
flatMap
(
projects
,
project
=>
action
(
project
,
value
)
)
)
;
}
)
;
}
return
deduplicate
(
outputs
,
equateValues
)
;
}
function
combineProjectOutputFromEveryProject
<
T
>
(
projectService
:
ProjectService
,
action
:
(
project
:
Project
)
=>
ReadonlyArray
<
T
>
,
areEqual
:
(
a
:
T
,
b
:
T
)
=>
boolean
)
{
const
outputs
:
T
[
]
=
[
]
;
projectService
.
forEachEnabledProject
(
project
=>
{
const
theseOutputs
=
action
(
project
)
;
outputs
.
push
(
...
theseOutputs
.
filter
(
output
=>
!
outputs
.
some
(
o
=>
areEqual
(
o
,
output
)
)
)
)
;
}
)
;
return
outputs
;
}
function
combineProjectOutputWhileOpeningReferencedProjects
<
T
>
(
projects
:
Projects
,
defaultProject
:
Project
,
action
:
(
project
:
Project
)
=>
ReadonlyArray
<
T
>
,
getLocation
:
(
t
:
T
)
=>
DocumentPosition
,
resultsEqual
:
(
a
:
T
,
b
:
T
)
=>
boolean
,
)
:
T
[
]
{
const
outputs
:
T
[
]
=
[
]
;
combineProjectOutputWorker
<
undefined
>
(
projects
,
defaultProject
,
/*initialLocation*/
undefined
,
(
{
project
}
,
tryAddToTodo
)
=>
{
for
(
const
output
of
action
(
project
)
)
{
if
(
!
contains
(
outputs
,
output
,
resultsEqual
)
&&
!
tryAddToTodo
(
project
,
getLocation
(
output
)
)
)
{
outputs
.
push
(
output
)
;
}
}
}
,
/*getDefinition*/
undefined
)
;
return
outputs
;
}
function
combineProjectOutputForRenameLocations
(
projects
:
Projects
,
defaultProject
:
Project
,
initialLocation
:
DocumentPosition
,
findInStrings
:
boolean
,
findInComments
:
boolean
,
hostPreferences
:
UserPreferences
)
:
ReadonlyArray
<
RenameLocation
>
{
const
outputs
:
RenameLocation
[
]
=
[
]
;
combineProjectOutputWorker
<
DocumentPosition
>
(
projects
,
defaultProject
,
initialLocation
,
(
{
project
,
location
}
,
tryAddToTodo
)
=>
{
for
(
const
output
of
project
.
getLanguageService
(
)
.
findRenameLocations
(
location
.
fileName
,
location
.
pos
,
findInStrings
,
findInComments
,
hostPreferences
.
providePrefixAndSuffixTextForRename
)
||
emptyArray
)
{
if
(
!
contains
(
outputs
,
output
,
documentSpansEqual
)
&&
!
tryAddToTodo
(
project
,
documentSpanLocation
(
output
)
)
)
{
outputs
.
push
(
output
)
;
}
}
}
,
(
)
=>
getDefinitionLocation
(
defaultProject
,
initialLocation
)
)
;
return
outputs
;
}
function
getDefinitionLocation
(
defaultProject
:
Project
,
initialLocation
:
DocumentPosition
)
:
DocumentPosition
|
undefined
{
const
infos
=
defaultProject
.
getLanguageService
(
)
.
getDefinitionAtPosition
(
initialLocation
.
fileName
,
initialLocation
.
pos
)
;
const
info
=
infos
&&
firstOrUndefined
(
infos
)
;
return
info
&&
{
fileName
:
info
.
fileName
,
pos
:
info
.
textSpan
.
start
}
;
}
function
combineProjectOutputForReferences
(
projects
:
Projects
,
defaultProject
:
Project
,
initialLocation
:
DocumentPosition
)
:
ReadonlyArray
<
ReferencedSymbol
>
{
const
outputs
:
ReferencedSymbol
[
]
=
[
]
;
combineProjectOutputWorker
<
DocumentPosition
>
(
projects
,
defaultProject
,
initialLocation
,
(
{
project
,
location
}
,
getMappedLocation
)
=>
{
for
(
const
outputReferencedSymbol
of
project
.
getLanguageService
(
)
.
findReferences
(
location
.
fileName
,
location
.
pos
)
||
emptyArray
)
{
const
mappedDefinitionFile
=
getMappedLocation
(
project
,
documentSpanLocation
(
outputReferencedSymbol
.
definition
)
)
;
const
definition
:
ReferencedSymbolDefinitionInfo
=
mappedDefinitionFile
===
undefined
?
outputReferencedSymbol
.
definition
:
{
...
outputReferencedSymbol
.
definition
,
textSpan
:
createTextSpan
(
mappedDefinitionFile
.
pos
,
outputReferencedSymbol
.
definition
.
textSpan
.
length
)
,
fileName
:
mappedDefinitionFile
.
fileName
,
}
;
let
symbolToAddTo
=
find
(
outputs
,
o
=>
documentSpansEqual
(
o
.
definition
,
definition
)
)
;
if
(
!
symbolToAddTo
)
{
symbolToAddTo
=
{
definition
,
references
:
[
]
}
;
outputs
.
push
(
symbolToAddTo
)
;
}
for
(
const
ref
of
outputReferencedSymbol
.
references
)
{
// If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
if
(
!
contains
(
symbolToAddTo
.
references
,
ref
,
documentSpansEqual
)
&&
!
getMappedLocation
(
project
,
documentSpanLocation
(
ref
)
)
)
{
symbolToAddTo
.
references
.
push
(
ref
)
;
}
}
}
}
,
(
)
=>
getDefinitionLocation
(
defaultProject
,
initialLocation
)
)
;
return
outputs
.
filter
(
o
=>
o
.
references
.
length
!==
0
)
;
}
interface
ProjectAndLocation
<
TLocation
extends
DocumentPosition
|
undefined
>
{
readonly
project
:
Project
;
readonly
location
:
TLocation
;
}
function
forEachProjectInProjects
(
projects
:
Projects
,
path
:
string
|
undefined
,
cb
:
(
project
:
Project
,
path
:
string
|
undefined
)
=>
void
)
:
void
{
for
(
const
project
of
isArray
(
projects
)
?
projects
:
projects
.
projects
)
{
cb
(
project
,
path
)
;
}
if
(
!
isArray
(
projects
)
&&
projects
.
symLinkedProjects
)
{
projects
.
symLinkedProjects
.
forEach
(
(
symlinkedProjects
,
symlinkedPath
)
=>
{
for
(
const
project
of
symlinkedProjects
)
{
cb
(
project
,
symlinkedPath
)
;
}
}
)
;
}
}
type
CombineProjectOutputCallback
<
TLocation
extends
DocumentPosition
|
undefined
>
=
(
where
:
ProjectAndLocation
<
TLocation
>
,
getMappedLocation
:
(
project
:
Project
,
location
:
DocumentPosition
)
=>
DocumentPosition
|
undefined
,
)
=>
void
;
function
combineProjectOutputWorker
<
TLocation
extends
DocumentPosition
|
undefined
>
(
projects
:
Projects
,
defaultProject
:
Project
,
initialLocation
:
TLocation
,
cb
:
CombineProjectOutputCallback
<
TLocation
>
,
getDefinition
:
(
(
)
=>
DocumentPosition
|
undefined
)
|
undefined
,
)
:
void
{
const
projectService
=
defaultProject
.
projectService
;
let
toDo
:
ProjectAndLocation
<
TLocation
>
[
]
|
undefined
;
const
seenProjects
=
createMap
<
true
>
(
)
;
forEachProjectInProjects
(
projects
,
initialLocation
&&
initialLocation
.
fileName
,
(
project
,
path
)
=>
{
// TLocation shoud be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
const
location
=
(
initialLocation
?
{
fileName
:
path
,
pos
:
initialLocation
.
pos
}
:
undefined
)
as
TLocation
;
toDo
=
callbackProjectAndLocation
(
{
project
,
location
}
,
projectService
,
toDo
,
seenProjects
,
cb
)
;
}
)
;
// After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
if
(
getDefinition
)
{
const
memGetDefinition
=
memoize
(
getDefinition
)
;
projectService
.
forEachEnabledProject
(
project
=>
{
if
(
!
addToSeen
(
seenProjects
,
project
.
projectName
)
)
return
;
const
definition
=
getDefinitionInProject
(
memGetDefinition
(
)
,
defaultProject
,
project
)
;
if
(
definition
)
{
toDo
=
callbackProjectAndLocation
<
TLocation
>
(
{
project
,
location
:
definition
as
TLocation
}
,
projectService
,
toDo
,
seenProjects
,
cb
)
;
}
}
)
;
}
while
(
toDo
&&
toDo
.
length
)
{
toDo
=
callbackProjectAndLocation
(
Debug
.
assertDefined
(
toDo
.
pop
(
)
)
,
projectService
,
toDo
,
seenProjects
,
cb
)
;
}
}
function
getDefinitionInProject
(
definition
:
DocumentPosition
|
undefined
,
definingProject
:
Project
,
project
:
Project
)
:
DocumentPosition
|
undefined
{
if
(
!
definition
||
project
.
containsFile
(
toNormalizedPath
(
definition
.
fileName
)
)
)
return
definition
;
const
mappedDefinition
=
definingProject
.
getLanguageService
(
)
.
getSourceMapper
(
)
.
tryGetGeneratedPosition
(
definition
)
;
return
mappedDefinition
&&
project
.
containsFile
(
toNormalizedPath
(
mappedDefinition
.
fileName
)
)
?
mappedDefinition
:
undefined
;
}
function
callbackProjectAndLocation
<
TLocation
extends
DocumentPosition
|
undefined
>
(
projectAndLocation
:
ProjectAndLocation
<
TLocation
>
,
projectService
:
ProjectService
,
toDo
:
ProjectAndLocation
<
TLocation
>
[
]
|
undefined
,
seenProjects
:
Map
<
true
>
,
cb
:
CombineProjectOutputCallback
<
TLocation
>
,
)
:
ProjectAndLocation
<
TLocation
>
[
]
|
undefined
{
if
(
projectAndLocation
.
project
.
getCancellationToken
(
)
.
isCancellationRequested
(
)
)
return
undefined
;
// Skip rest of toDo if cancelled
cb
(
projectAndLocation
,
(
project
,
location
)
=>
{
seenProjects
.
set
(
projectAndLocation
.
project
.
projectName
,
true
)
;
const
originalLocation
=
projectService
.
getOriginalLocationEnsuringConfiguredProject
(
project
,
location
)
;
if
(
!
originalLocation
)
return
undefined
;
const
originalScriptInfo
=
projectService
.
getScriptInfo
(
originalLocation
.
fileName
)
!
;
toDo
=
toDo
||
[
]
;
for
(
const
project
of
originalScriptInfo
.
containingProjects
)
{
addToTodo
(
{
project
,
location
:
originalLocation
as
TLocation
}
,
toDo
,
seenProjects
)
;
}
const
symlinkedProjectsMap
=
projectService
.
getSymlinkedProjects
(
originalScriptInfo
)
;
if
(
symlinkedProjectsMap
)
{
symlinkedProjectsMap
.
forEach
(
(
symlinkedProjects
)
=>
{
for
(
const
symlinkedProject
of
symlinkedProjects
)
addToTodo
(
{
project
:
symlinkedProject
,
location
:
originalLocation
as
TLocation
}
,
toDo
!
,
seenProjects
)
;
}
)
;
}
return
originalLocation
;
}
)
;
return
toDo
;
}
function
addToTodo
<
TLocation
extends
DocumentPosition
|
undefined
>
(
projectAndLocation
:
ProjectAndLocation
<
TLocation
>
,
toDo
:
Push
<
ProjectAndLocation
<
TLocation
>
>
,
seenProjects
:
Map
<
true
>
)
:
void
{
if
(
addToSeen
(
seenProjects
,
projectAndLocation
.
project
.
projectName
)
)
toDo
.
push
(
projectAndLocation
)
;
}
function
documentSpanLocation
(
{
fileName
,
textSpan
}
:
DocumentSpan
)
:
DocumentPosition
{
return
{
fileName
,
pos
:
textSpan
.
start
}
;
}
function
getMappedLocation
(
location
:
DocumentPosition
,
projectService
:
ProjectService
,
project
:
Project
)
:
DocumentPosition
|
undefined
{
const
mapsTo
=
project
.
getSourceMapper
(
)
.
tryGetSourcePosition
(
location
)
;
return
mapsTo
&&
projectService
.
fileExists
(
toNormalizedPath
(
mapsTo
.
fileName
)
)
?
mapsTo
:
undefined
;
}
export
interface
SessionOptions
{
host
:
ServerHost
;
cancellationToken
:
ServerCancellationToken
;
useSingleInferredProject
:
boolean
;
useInferredProjectPerProjectRoot
:
boolean
;
typingsInstaller
:
ITypingsInstaller
;
byteLength
:
(
buf
:
string
,
encoding
?:
string
)
=>
number
;
hrtime
:
(
start
?:
number
[
]
)
=>
number
[
]
;
logger
:
Logger
;
/**
* If falsy, all events are suppressed.
*/
canUseEvents
:
boolean
;
eventHandler
?:
ProjectServiceEventHandler
;
/** Has no effect if eventHandler is also specified. */
suppressDiagnosticEvents
?:
boolean
;
syntaxOnly
?:
boolean
;
throttleWaitMilliseconds
?:
number
;
noGetErrOnBackgroundUpdate
?:
boolean
;
globalPlugins
?:
ReadonlyArray
<
string
>
;
pluginProbeLocations
?:
ReadonlyArray
<
string
>
;
allowLocalPluginLoads
?:
boolean
;
typesMapLocation
?:
string
;
}
export
class
Session
implements
EventSender
{
private
readonly
gcTimer
:
GcTimer
;
protected
projectService
:
ProjectService
;
private
changeSeq
=
0
;
private
currentRequestId
!
:
number
;
private
errorCheck
:
MultistepOperation
;
protected
host
:
ServerHost
;
private
readonly
cancellationToken
:
ServerCancellationToken
;
protected
readonly
typingsInstaller
:
ITypingsInstaller
;
protected
byteLength
:
(
buf
:
string
,
encoding
?:
string
)
=>
number
;
private
hrtime
:
(
start
?:
number
[
]
)
=>
number
[
]
;
protected
logger
:
Logger
;
protected
canUseEvents
:
boolean
;
private
suppressDiagnosticEvents
?:
boolean
;
private
eventHandler
:
ProjectServiceEventHandler
|
undefined
;
private
readonly
noGetErrOnBackgroundUpdate
?:
boolean
;
constructor
(
opts
:
SessionOptions
)
{
this
.
host
=
opts
.
host
;
this
.
cancellationToken
=
opts
.
cancellationToken
;
this
.
typingsInstaller
=
opts
.
typingsInstaller
;
this
.
byteLength
=
opts
.
byteLength
;
this
.
hrtime
=
opts
.
hrtime
;
this
.
logger
=
opts
.
logger
;
this
.
canUseEvents
=
opts
.
canUseEvents
;
this
.
suppressDiagnosticEvents
=
opts
.
suppressDiagnosticEvents
;
this
.
noGetErrOnBackgroundUpdate
=
opts
.
noGetErrOnBackgroundUpdate
;
const
{
throttleWaitMilliseconds
}
=
opts
;
this
.
eventHandler
=
this
.
canUseEvents
?
opts
.
eventHandler
||
(
event
=>
this
.
defaultEventHandler
(
event
)
)
:
undefined
;
const
multistepOperationHost
:
MultistepOperationHost
=
{
executeWithRequestId
:
(
requestId
,
action
)
=>
this
.
executeWithRequestId
(
requestId
,
action
)
,
getCurrentRequestId
:
(
)
=>
this
.
currentRequestId
,
getServerHost
:
(
)
=>
this
.
host
,
logError
:
(
err
,
cmd
)
=>
this
.
logError
(
err
,
cmd
)
,
sendRequestCompletedEvent
:
requestId
=>
this
.
sendRequestCompletedEvent
(
requestId
)
,
isCancellationRequested
:
(
)
=>
this
.
cancellationToken
.
isCancellationRequested
(
)
}
;
this
.
errorCheck
=
new
MultistepOperation
(
multistepOperationHost
)
;
const
settings
:
ProjectServiceOptions
=
{
host
:
this
.
host
,
logger
:
this
.
logger
,
cancellationToken
:
this
.
cancellationToken
,
useSingleInferredProject
:
opts
.
useSingleInferredProject
,
useInferredProjectPerProjectRoot
:
opts
.
useInferredProjectPerProjectRoot
,
typingsInstaller
:
this
.
typingsInstaller
,
throttleWaitMilliseconds
,
eventHandler
:
this
.
eventHandler
,
suppressDiagnosticEvents
:
this
.
suppressDiagnosticEvents
,
globalPlugins
:
opts
.
globalPlugins
,
pluginProbeLocations
:
opts
.
pluginProbeLocations
,
allowLocalPluginLoads
:
opts
.
allowLocalPluginLoads
,
typesMapLocation
:
opts
.
typesMapLocation
,
syntaxOnly
:
opts
.
syntaxOnly
,
}
;
this
.
projectService
=
new
ProjectService
(
settings
)
;
this
.
gcTimer
=
new
GcTimer
(
this
.
host
,
/*delay*/
7000
,
this
.
logger
)
;
}
private
sendRequestCompletedEvent
(
requestId
:
number
)
:
void
{
this
.
event
<
protocol
.
RequestCompletedEventBody
>
(
{
request_seq
:
requestId
}
,
"requestCompleted"
)
;
}
private
defaultEventHandler
(
event
:
ProjectServiceEvent
)
{
switch
(
event
.
eventName
)
{
case
ProjectsUpdatedInBackgroundEvent
:
const
{
openFiles
}
=
event
.
data
;
this
.
projectsUpdatedInBackgroundEvent
(
openFiles
)
;
break
;
case
ProjectLoadingStartEvent
:
const
{
project
,
reason
}
=
event
.
data
;
this
.
event
<
protocol
.
ProjectLoadingStartEventBody
>
(
{
projectName
:
project
.
getProjectName
(
)
,
reason
}
,
ProjectLoadingStartEvent
)
;
break
;
case
ProjectLoadingFinishEvent
:
const
{
project
:
finishProject
}
=
event
.
data
;
this
.
event
<
protocol
.
ProjectLoadingFinishEventBody
>
(
{
projectName
:
finishProject
.
getProjectName
(
)
}
,
ProjectLoadingFinishEvent
)
;
break
;
case
LargeFileReferencedEvent
:
const
{
file
,
fileSize
,
maxFileSize
}
=
event
.
data
;
this
.
event
<
protocol
.
LargeFileReferencedEventBody
>
(
{
file
,
fileSize
,
maxFileSize
}
,
LargeFileReferencedEvent
)
;
break
;
case
ConfigFileDiagEvent
:
const
{
triggerFile
,
configFileName
:
configFile
,
diagnostics
}
=
event
.
data
;
const
bakedDiags
=
map
(
diagnostics
,
diagnostic
=>
formatConfigFileDiag
(
diagnostic
,
/*includeFileName*/
true
)
)
;
this
.
event
<
protocol
.
ConfigFileDiagnosticEventBody
>
(
{
triggerFile
,
configFile
,
diagnostics
:
bakedDiags
}
,
ConfigFileDiagEvent
)
;
break
;
case
ProjectLanguageServiceStateEvent
:
{
const
eventName
:
protocol
.
ProjectLanguageServiceStateEventName
=
ProjectLanguageServiceStateEvent
;
this
.
event
<
protocol
.
ProjectLanguageServiceStateEventBody
>
(
{
projectName
:
event
.
data
.
project
.
getProjectName
(
)
,
languageServiceEnabled
:
event
.
data
.
languageServiceEnabled
}
,
eventName
)
;
break
;
}
case
ProjectInfoTelemetryEvent
:
{
const
eventName
:
protocol
.
TelemetryEventName
=
"telemetry"
;
this
.
event
<
protocol
.
TelemetryEventBody
>
(
{
telemetryEventName
:
event
.
eventName
,
payload
:
event
.
data
,
}
,
eventName
)
;
break
;
}
}
}
private
projectsUpdatedInBackgroundEvent
(
openFiles
:
string
[
]
)
:
void
{
this
.
projectService
.
logger
.
info
(
`got projects updated in background, updating diagnostics for
${
openFiles
}
`
)
;
if
(
openFiles
.
length
)
{
if
(
!
this
.
suppressDiagnosticEvents
&&
!
this
.
noGetErrOnBackgroundUpdate
)
{
const
checkList
=
this
.
createCheckList
(
openFiles
)
;
// For now only queue error checking for open files. We can change this to include non open files as well
this
.
errorCheck
.
startNew
(
next
=>
this
.
updateErrorCheck
(
next
,
checkList
,
100
,
/*requireOpen*/
true
)
)
;
}
// Send project changed event
this
.
event
<
protocol
.
ProjectsUpdatedInBackgroundEventBody
>
(
{
openFiles
}
,
ProjectsUpdatedInBackgroundEvent
)
;
}
}
public
logError
(
err
:
Error
,
cmd
:
string
)
:
void
{
this
.
logErrorWorker
(
err
,
cmd
)
;
}
private
logErrorWorker
(
err
:
Error
,
cmd
:
string
,
fileRequest
?:
protocol
.
FileRequestArgs
)
:
void
{
let
msg
=
"Exception on executing command "
+
cmd
;
if
(
err
.
message
)
{
msg
+=
":\n"
+
indent
(
err
.
message
)
;
if
(
(
<
StackTraceError
>
err
)
.
stack
)
{
msg
+=
"\n"
+
indent
(
(
<
StackTraceError
>
err
)
.
stack
!
)
;
}
}
if
(
this
.
logger
.
hasLevel
(
LogLevel
.
verbose
)
)
{
if
(
fileRequest
)
{
try
{
const
{
file
,
project
}
=
this
.
getFileAndProject
(
fileRequest
)
;
const
scriptInfo
=
project
.
getScriptInfoForNormalizedPath
(
file
)
;
if
(
scriptInfo
)
{
const
text
=
getSnapshotText
(
scriptInfo
.
getSnapshot
(
)
)
;
msg
+=
`\n\nFile text of
${
fileRequest
.
file
}
:
${
indent
(
text
)
}
\n`
;
}
}
catch
{
}
// tslint:disable-line no-empty
}
if
(
err
.
message
&&
err
.
message
.
indexOf
(
`Could not find sourceFile:`
)
!==
-
1
)
{
msg
+=
`\n\nProjects::\n`
;
let
counter
=
0
;
const
addProjectInfo
=
(
project
:
Project
)
=>
{
msg
+=
`\nProject '
${
project
.
projectName
}
' (
${
ProjectKind
[
project
.
projectKind
]
}
)
${
counter
}
\n`
;
msg
+=
project
.
filesToString
(
/*writeProjectFileNames*/
true
)
;
msg
+=
"\n-----------------------------------------------\n"
;
counter
++
;
}
;
this
.
projectService
.
externalProjects
.
forEach
(
addProjectInfo
)
;
this
.
projectService
.
configuredProjects
.
forEach
(
addProjectInfo
)
;
this
.
projectService
.
inferredProjects
.
forEach
(
addProjectInfo
)
;
}
}
this
.
logger
.
msg
(
msg
,
Msg
.
Err
)
;
}
public
send
(
msg
:
protocol
.
Message
)
{
if
(
msg
.
type
===
"event"
&&
!
this
.
canUseEvents
)
{
if
(
this
.
logger
.
hasLevel
(
LogLevel
.
verbose
)
)
{
this
.
logger
.
info
(
`Session does not support events: ignored event:
${
JSON
.
stringify
(
msg
)
}
`
)
;
}
return
;
}
this
.
host
.
write
(
formatMessage
(
msg
,
this
.
logger
,
this
.
byteLength
,
this
.
host
.
newLine
)
)
;
}
public
event
<
T
extends
object
>
(
body
:
T
,
eventName
:
string
)
:
void
{
this
.
send
(
toEvent
(
eventName
,
body
)
)
;
}
// For backwards-compatibility only.
/**
@deprecated
*/
public
output
(
info
:
any
,
cmdName
:
string
,
reqSeq
?:
number
,
errorMsg
?:
string
)
:
void
{
this
.
doOutput
(
info
,
cmdName
,
reqSeq
!
,
/*success*/
!
errorMsg
,
errorMsg
)
;
// TODO: GH#18217
}
private
doOutput
(
info
:
{
}
|
undefined
,
cmdName
:
string
,
reqSeq
:
number
,
success
:
boolean
,
message
?:
string
)
:
void
{
const
res
:
protocol
.
Response
=
{
seq
:
0
,
type
:
"response"
,
command
:
cmdName
,
request_seq
:
reqSeq
,
success
,
}
;
if
(
success
)
{
let
metadata
:
unknown
;
if
(
isArray
(
info
)
)
{
res
.
body
=
info
;
metadata
=
(
info
as
WithMetadata
<
ReadonlyArray
<
any
>
>
)
.
metadata
;
delete
(
info
as
WithMetadata
<
ReadonlyArray
<
any
>
>
)
.
metadata
;
}
else
if
(
typeof
info
===
"object"
)
{
if
(
(
info
as
WithMetadata
<
{
}
>
)
.
metadata
)
{
const
{
metadata
:
infoMetadata
,
...
body
}
=
(
info
as
WithMetadata
<
{
}
>
)
;
res
.
body
=
body
;
metadata
=
infoMetadata
;
}
else
{
res
.
body
=
info
;
}
}
else
{
res
.
body
=
info
;
}
if
(
metadata
)
res
.
metadata
=
metadata
;
}
else
{
Debug
.
assert
(
info
===
undefined
)
;
}
if
(
message
)
{
res
.
message
=
message
;
}
this
.
send
(
res
)
;
}
private
semanticCheck
(
file
:
NormalizedPath
,
project
:
Project
)
{
const
diags
=
isDeclarationFileInJSOnlyNonConfiguredProject
(
project
,
file
)
?
emptyArray
:
project
.
getLanguageService
(
)
.
getSemanticDiagnostics
(
file
)
;
this
.
sendDiagnosticsEvent
(
file
,
project
,
diags
,
"semanticDiag"
)
;
}
private
syntacticCheck
(
file
:
NormalizedPath
,
project
:
Project
)
{
this
.
sendDiagnosticsEvent
(
file
,
project
,
project
.
getLanguageService
(
)
.
getSyntacticDiagnostics
(
file
)
,
"syntaxDiag"
)
;
}
private
suggestionCheck
(
file
:
NormalizedPath
,
project
:
Project
)
{
this
.
sendDiagnosticsEvent
(
file
,
project
,
project
.
getLanguageService
(
)
.
getSuggestionDiagnostics
(
file
)
,
"suggestionDiag"
)
;
}
private
sendDiagnosticsEvent
(
file
:
NormalizedPath
,
project
:
Project
,
diagnostics
:
ReadonlyArray
<
Diagnostic
>
,
kind
:
protocol
.
DiagnosticEventKind
)
:
void
{
try
{
this
.
event
<
protocol
.
DiagnosticEventBody
>
(
{
file
,
diagnostics
:
diagnostics
.
map
(
diag
=>
formatDiag
(
file
,
project
,
diag
)
)
}
,
kind
)
;
}
catch
(
err
)
{
this
.
logError
(
err
,
kind
)
;
}
}
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
private
updateErrorCheck
(
next
:
NextStep
,
checkList
:
PendingErrorCheck
[
]
,
ms
:
number
,
requireOpen
=
true
)
{
Debug
.
assert
(
!
this
.
suppressDiagnosticEvents
)
;
// Caller's responsibility
const
seq
=
this
.
changeSeq
;
const
followMs
=
Math
.
min
(
ms
,
200
)
;
let
index
=
0
;
const
checkOne
=
(
)
=>
{
if
(
this
.
changeSeq
!==
seq
)
{
return
;
}
const
{
fileName
,
project
}
=
checkList
[
index
]
;
index
++
;
// Ensure the project is upto date before checking if this file is present in the project
updateProjectIfDirty
(
project
)
;
if
(
!
project
.
containsFile
(
fileName
,
requireOpen
)
)
{
return
;
}
this
.
syntacticCheck
(
fileName
,
project
)
;
if
(
this
.
changeSeq
!==
seq
)
{
return
;
}
next
.
immediate
(
(
)
=>
{
this
.
semanticCheck
(
fileName
,
project
)
;
if
(
this
.
changeSeq
!==
seq
)
{
return
;
}
const
goNext
=
(
)
=>
{
if
(
checkList
.
length
>
index
)
{
next
.
delay
(
followMs
,
checkOne
)
;
}
}
;
if
(
this
.
getPreferences
(
fileName
)
.
disableSuggestions
)
{
goNext
(
)
;
}
else
{
next
.
immediate
(
(
)
=>
{
this
.
suggestionCheck
(
fileName
,
project
)
;
goNext
(
)
;
}
)
;
}
}
)
;
}
;
if
(
checkList
.
length
>
index
&&
this
.
changeSeq
===
seq
)
{
next
.
delay
(
ms
,
checkOne
)
;
}
}
private
cleanProjects
(
caption
:
string
,
projects
:
Project
[
]
)
{
if
(
!
projects
)
{
return
;
}
this
.
logger
.
info
(
`cleaning
${
caption
}
`
)
;
for
(
const
p
of
projects
)
{
p
.
getLanguageService
(
/*ensureSynchronized*/
false
)
.
cleanupSemanticCache
(
)
;
}
}
private
cleanup
(
)
{
this
.
cleanProjects
(
"inferred projects"
,
this
.
projectService
.
inferredProjects
)
;
this
.
cleanProjects
(
"configured projects"
,
arrayFrom
(
this
.
projectService
.
configuredProjects
.
values
(
)
)
)
;
this
.
cleanProjects
(
"external projects"
,
this
.
projectService
.
externalProjects
)
;
if
(
this
.
host
.
gc
)
{
this
.
logger
.
info
(
`host.gc()`
)
;
this
.
host
.
gc
(
)
;
}
}
private
getEncodedSemanticClassifications
(
args
:
protocol
.
EncodedSemanticClassificationsRequestArgs
)
{
const
{
file
,
project
}
=
this
.
getFileAndProject
(
args
)
;
return
project
.
getLanguageService
(
)
.
getEncodedSemanticClassifications
(
file
,
args
)
;
}
private
getProject
(
projectFileName
:
string
|
undefined
)
:
Project
|
undefined
{
return
projectFileName
===
undefined
?
undefined
:
this
.
projectService
.
findProject
(
projectFileName
)
;
}
private
getConfigFileAndProject
(
args
:
protocol
.
FileRequestArgs
)
:
{
configFile
:
NormalizedPath
|
undefined
,
project
:
Project
|
undefined
}
{
const
project
=
this
.
getProject
(
args
.
projectFileName
)
;
const
file
=
toNormalizedPath
(
args
.
file
)
;
return
{
configFile
:
project
&&
project
.
hasConfigFile
(
file
)
?
file
:
undefined
,
project
}
;
}
private
getConfigFileDiagnostics
(
configFile
:
NormalizedPath
,
project
:
Project
,
includeLinePosition
:
boolean
)
{
const
projectErrors
=
project
.
getAllProjectErrors
(
)
;
const
optionsErrors
=
project
.
getLanguageService
(
)
.
getCompilerOptionsDiagnostics
(
)
;
const
diagnosticsForConfigFile
=
filter
(
concatenate
(
projectErrors
,
optionsErrors
)
,
diagnostic
=>
!
!
diagnostic
.
file
&&
diagnostic
.
file
.
fileName
===
configFile
)
;
return
includeLinePosition
?
this
.
convertToDiagnosticsWithLinePositionFromDiagnosticFile
(
diagnosticsForConfigFile
)
:
map
(
diagnosticsForConfigFile
,
diagnostic
=>
formatConfigFileDiag
(
diagnostic
,
/*includeFileName*/
false
)
)
;
}
private
convertToDiagnosticsWithLinePositionFromDiagnosticFile
(
diagnostics
:
ReadonlyArray
<
Diagnostic
>
)
:
protocol
.
DiagnosticWithLinePosition
[
]
{
return
diagnostics
.
map
<
protocol
.
DiagnosticWithLinePosition
>
(
d
=>
(
{
message
:
flattenDiagnosticMessageText
(
d
.
messageText
,
this
.
host
.
newLine
)
,
start
:
d
.
start
!
,
// TODO: GH#18217
length
:
d
.
length
!
,
// TODO: GH#18217
category
:
diagnosticCategoryName
(
d
)
,
code
:
d
.
code
,
startLocation
:
(
d
.
file
&&
convertToLocation
(
getLineAndCharacterOfPosition
(
d
.
file
,
d
.
start
!
)
)
)
!
,
// TODO: GH#18217
endLocation
:
(
d
.
file
&&
convertToLocation
(
getLineAndCharacterOfPosition
(
d
.
file
,
d
.
start
!
+
d
.
length
!
)
)
)
!
,
// TODO: GH#18217
relatedInformation
:
map
(
d
.
relatedInformation
,
formatRelatedInformation
)
}
)
)
;
}
private
getCompilerOptionsDiagnostics
(
args
:
protocol
.
CompilerOptionsDiagnosticsRequestArgs
)
{
const
project
=
this
.
getProject
(
args
.
projectFileName
)
!
;
// Get diagnostics that dont have associated file with them
// The diagnostics which have file would be in config file and
// would be reported as part of configFileDiagnostics
return
this
.
convertToDiagnosticsWithLinePosition
(
filter
(
project
.
getLanguageService
(
)
.
getCompilerOptionsDiagnostics
(
)
,
diagnostic
=>
!
diagnostic
.
file
)
,
/*scriptInfo*/
undefined
)
;
}
private
convertToDiagnosticsWithLinePosition
(
diagnostics
:
ReadonlyArray
<
Diagnostic
>
,
scriptInfo
:
ScriptInfo
|
undefined
)
:
protocol
.
DiagnosticWithLinePosition
[
]
{
return
diagnostics
.
map
(
d
=>
<
protocol
.
DiagnosticWithLinePosition
>
{
message
:
flattenDiagnosticMessageText
(
d
.
messageText
,
this
.
host
.
newLine
)
,
start
:
d
.
start
,
length
:
d
.
length
,
category
:
diagnosticCategoryName
(
d
)
,
code
:
d
.
code
,
source
:
d
.
source
,
startLocation
:
scriptInfo
&&
scriptInfo
.
positionToLineOffset
(
d
.
start
!
)
,
// TODO: GH#18217
endLocation
:
scriptInfo
&&
scriptInfo
.
positionToLineOffset
(
d
.
start
!
+
d
.
length
!
)
,
reportsUnnecessary
:
d
.
reportsUnnecessary
,
relatedInformation
:
map
(
d
.
relatedInformation
,
formatRelatedInformation
)
,
}
)
;
}
private
getDiagnosticsWorker
(
args
:
protocol
.
FileRequestArgs
,
isSemantic
:
boolean
,
selector
:
(
project
:
Project
,
file
:
string
)
=>
ReadonlyArray
<
Diagnostic
>
,
includeLinePosition
:
boolean
)
:
ReadonlyArray
<
protocol
.
DiagnosticWithLinePosition
>
|
ReadonlyArray
<
protocol
.
Diagnostic
>
{
const
{
project
,
file
}
=
this
.
getFileAndProject
(
args
)
;
if
(
isSemantic
&&
isDeclarationFileInJSOnlyNonConfiguredProject
(
project
,
file
)
)
{
return
emptyArray
;
}
const
scriptInfo
=
project
.
getScriptInfoForNormalizedPath
(
file
)
;
const
diagnostics
=
selector
(
project
,
file
)
;
return
includeLinePosition
?
this
.
convertToDiagnosticsWithLinePosition
(
diagnostics
,
scriptInfo
)
:
diagnostics
.
map
(
d
=>
formatDiag
(
file
,
project
,
d
)
)
;
}
private
getDefinition
(
args
:
protocol
.
FileLocationRequestArgs
,
simplifiedResult
:
boolean
)
:
ReadonlyArray
<
protocol
.
FileSpan
>
|
ReadonlyArray
<
DefinitionInfo
>
{
const
{
file
,
project
}
=
this
.
getFileAndProject
(
args
)
;
const
position
=
this
.
getPositionInFile
(
args
,
file
)
;
const
definitions
=
this
.
mapDefinitionInfoLocations
(
project
.
getLanguageService
(
)
.
getDefinitionAtPosition
(
file
,
position
)
||
emptyArray
,
project
)
;
return
simplifiedResult
?
this
.
mapDefinitionInfo
(
definitions
,
project
)
:
definitions
.
map
(
Session
.
mapToOriginalLocation
)
;
}
private
mapDefinitionInfoLocations
(
definitions
:
ReadonlyArray
<
DefinitionInfo
>
,
project
:
Project
)
:
ReadonlyArray
<
DefinitionInfo
>
{
return
definitions
.
map
(
(
info
)
:
DefinitionInfo
=>
{
const
newLoc
=
getMappedLocation
(
documentSpanLocation
(
info
)
,
this
.
projectService
,
project
)
;
return
!
newLoc
?
info
:
{
containerKind
:
info
.
containerKind
,
containerName
:
info
.
containerName
,
fileName
:
newLoc
.
fileName
,
kind
:
info
.
kind
,
name
:
info
.
name
,
textSpan
:
{
start
:
newLoc
.
pos
,
length
:
info
.
textSpan
.
length
}
,
originalFileName
:
info
.
fileName
,
originalTextSpan
:
info
.
textSpan
,
}
;
}
)
;
}
private
getDefinitionAndBoundSpan
(
args
:
protocol
.
FileLocationRequestArgs
,
simplifiedResult
:
boolean
)
:
protocol
.
DefinitionInfoAndBoundSpan
|
DefinitionInfoAndBoundSpan
{
const
{
file
,
project
}
=
this
.
getFileAndProject
(
args
)
;
const
position
=
this
.
getPositionInFile
(
args
,
file
)
;
const
scriptInfo
=
Debug
.
assertDefined
(
project
.
getScriptInfo
(
file
)
)
;
const
unmappedDefinitionAndBoundSpan
=
project
.
getLanguageService
(
)
.
getDefinitionAndBoundSpan
(
file
,
position
)
;
if
(
!
unmappedDefinitionAndBoundSpan
||
!
unmappedDefinitionAndBoundSpan
.
definitions
)
{
return
{
definitions
:
emptyArray
,
textSpan
:
undefined
!
// TODO: GH#18217
}
;
}
const
definitions
=
this
.
mapDefinitionInfoLocations
(
unmappedDefinitionAndBoundSpan
.
definitions
,
project
)
;
const
{
textSpan
}
=
unmappedDefinitionAndBoundSpan
;
if
(
simplifiedResult
)
{
return
{
definitions
:
this
.
mapDefinitionInfo
(
definitions
,
project
)
,
textSpan
:
this
.
toLocationTextSpan
(
textSpan
,
scriptInfo
)
}
;
}
return
{
definitions
:
definitions
.
map
(
Session
.
mapToOriginalLocation
)
,
textSpan
,
}
;
}
private
getEmitOutput
(
args
:
protocol
.
FileRequestArgs
)
:
EmitOutput
{
const
{
file
,
project
}
=
this
.
getFileAndProject
(
args
)
;
return
project
.
getLanguageService
(
)
.
getEmitOutput
(
file
)
;
}
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL