@@ -1766,11 +1766,17 @@ namespace ts.server {
17661766 return textChanges . map ( change => this . mapTextChangesToCodeEditsUsingScriptinfo ( change , project . getScriptInfoForNormalizedPath ( toNormalizedPath ( change . fileName ) ) ) ) ;
17671767 }
17681768
1769- private mapTextChangesToCodeEditsUsingScriptinfo ( textChanges : FileTextChanges , scriptInfo : ScriptInfo ) : protocol . FileCodeEdits {
1770- return {
1771- fileName : textChanges . fileName ,
1772- textChanges : textChanges . textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) )
1773- } ;
1769+ private mapTextChangesToCodeEditsUsingScriptinfo ( textChanges : FileTextChanges , scriptInfo : ScriptInfo | undefined ) : protocol . FileCodeEdits {
1770+ Debug . assert ( ! ! textChanges . isNewFile === ! scriptInfo ) ;
1771+ if ( scriptInfo ) {
1772+ return {
1773+ fileName : textChanges . fileName ,
1774+ textChanges : textChanges . textChanges . map ( textChange => this . convertTextChangeToCodeEdit ( textChange , scriptInfo ) )
1775+ } ;
1776+ }
1777+ else {
1778+ return this . convertNewFileTextChangeToCodeEdit ( textChanges ) ;
1779+ }
17741780 }
17751781
17761782 private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -1781,6 +1787,13 @@ namespace ts.server {
17811787 } ;
17821788 }
17831789
1790+ private convertNewFileTextChangeToCodeEdit ( textChanges : FileTextChanges ) : protocol . FileCodeEdits {
1791+ Debug . assert ( textChanges . textChanges . length === 1 ) ;
1792+ const change = first ( textChanges . textChanges ) ;
1793+ Debug . assert ( change . span . start === 0 && change . span . length === 0 ) ;
1794+ return { fileName : textChanges . fileName , textChanges : [ { start : { line : 0 , offset : 0 } , end : { line : 0 , offset : 0 } , newText : change . newText } ] } ;
1795+ }
1796+
17841797 private getBraceMatching ( args : protocol . FileLocationRequestArgs , simplifiedResult : boolean ) : protocol . TextSpan [ ] | TextSpan [ ] {
17851798 const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
17861799 const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ;
0 commit comments