@@ -1157,14 +1157,17 @@ namespace ts.server {
1157
1157
this . projectService . getScriptInfoEnsuringProjectsUptoDate ( args . file ) :
1158
1158
this . projectService . getScriptInfo ( args . file ) ;
1159
1159
if ( ! scriptInfo ) {
1160
- return ignoreNoProjectError ? emptyArray : Errors . ThrowNoProject ( ) ;
1160
+ if ( ignoreNoProjectError ) return emptyArray ;
1161
+ this . projectService . logErrorForScriptInfoNotFound ( args . file ) ;
1162
+ return Errors . ThrowNoProject ( ) ;
1161
1163
}
1162
1164
projects = scriptInfo . containingProjects ;
1163
1165
symLinkedProjects = this . projectService . getSymlinkedProjects ( scriptInfo ) ;
1164
1166
}
1165
1167
// filter handles case when 'projects' is undefined
1166
1168
projects = filter ( projects , p => p . languageServiceEnabled && ! p . isOrphan ( ) ) ;
1167
1169
if ( ! ignoreNoProjectError && ( ! projects || ! projects . length ) && ! symLinkedProjects ) {
1170
+ this . projectService . logErrorForScriptInfoNotFound ( args . file ) ;
1168
1171
return Errors . ThrowNoProject ( ) ;
1169
1172
}
1170
1173
return symLinkedProjects ? { projects : projects ! , symLinkedProjects } : projects ! ; // TODO: GH#18217
@@ -1908,8 +1911,17 @@ namespace ts.server {
1908
1911
return textChanges . map ( change => this . mapTextChangeToCodeEdit ( change ) ) ;
1909
1912
}
1910
1913
1911
- private mapTextChangeToCodeEdit ( change : FileTextChanges ) : protocol . FileCodeEdits {
1912
- return mapTextChangesToCodeEdits ( change , this . projectService . getScriptInfoOrConfig ( change . fileName ) ) ;
1914
+ private mapTextChangeToCodeEdit ( textChanges : FileTextChanges ) : protocol . FileCodeEdits {
1915
+ const scriptInfo = this . projectService . getScriptInfoOrConfig ( textChanges . fileName ) ;
1916
+ if ( ! ! textChanges . isNewFile === ! ! scriptInfo ) {
1917
+ if ( ! scriptInfo ) { // and !isNewFile
1918
+ this . projectService . logErrorForScriptInfoNotFound ( textChanges . fileName ) ;
1919
+ }
1920
+ Debug . fail ( "Expected isNewFile for (only) new files. " + JSON . stringify ( { isNewFile : ! ! textChanges . isNewFile , hasScriptInfo : ! ! scriptInfo } ) ) ;
1921
+ }
1922
+ return scriptInfo
1923
+ ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) }
1924
+ : convertNewFileTextChangeToCodeEdit ( textChanges ) ;
1913
1925
}
1914
1926
1915
1927
private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -2431,13 +2443,6 @@ namespace ts.server {
2431
2443
return { file : fileName , start : scriptInfo . positionToLineOffset ( textSpan . start ) , end : scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) ) } ;
2432
2444
}
2433
2445
2434
- function mapTextChangesToCodeEdits ( textChanges : FileTextChanges , scriptInfo : ScriptInfoOrConfig | undefined ) : protocol . FileCodeEdits {
2435
- Debug . assert ( ! ! textChanges . isNewFile === ! scriptInfo , "Expected isNewFile for (only) new files" , ( ) => JSON . stringify ( { isNewFile : ! ! textChanges . isNewFile , hasScriptInfo : ! ! scriptInfo } ) ) ;
2436
- return scriptInfo
2437
- ? { fileName : textChanges . fileName , textChanges : textChanges . textChanges . map ( textChange => convertTextChangeToCodeEdit ( textChange , scriptInfo ) ) }
2438
- : convertNewFileTextChangeToCodeEdit ( textChanges ) ;
2439
- }
2440
-
2441
2446
function convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfoOrConfig ) : protocol . CodeEdit {
2442
2447
return { start : positionToLineOffset ( scriptInfo , change . span . start ) , end : positionToLineOffset ( scriptInfo , textSpanEnd ( change . span ) ) , newText : change . newText } ;
2443
2448
}
0 commit comments