@@ -1766,11 +1766,17 @@ namespace ts.server {
1766
1766
return textChanges . map ( change => this . mapTextChangesToCodeEditsUsingScriptinfo ( change , project . getScriptInfoForNormalizedPath ( toNormalizedPath ( change . fileName ) ) ) ) ;
1767
1767
}
1768
1768
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
+ }
1774
1780
}
1775
1781
1776
1782
private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -1781,6 +1787,13 @@ namespace ts.server {
1781
1787
} ;
1782
1788
}
1783
1789
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
+
1784
1797
private getBraceMatching ( args : protocol . FileLocationRequestArgs , simplifiedResult : boolean ) : protocol . TextSpan [ ] | TextSpan [ ] {
1785
1798
const { file, languageService } = this . getFileAndLanguageServiceForSyntacticOperation ( args ) ;
1786
1799
const scriptInfo = this . projectService . getScriptInfoForNormalizedPath ( file ) ;
0 commit comments