@@ -112,6 +112,9 @@ namespace ts.server {
112112 export const Exit = "exit" ;
113113 export const Format = "format" ;
114114 export const Formatonkey = "formatonkey" ;
115+ export const FormatFull = "format-full" ;
116+ export const FormatonkeyFull = "formatonkey-full" ;
117+ export const FormatRangeFull = "formatRange-full" ;
115118 export const Geterr = "geterr" ;
116119 export const GeterrForProject = "geterrForProject" ;
117120 export const SemanticDiagnosticsFull = "semanticDiagnostics-full" ;
@@ -720,6 +723,36 @@ namespace ts.server {
720723 } ) ;
721724 }
722725
726+ private getFormattingEditsForRangeFull ( args : protocol . FormatRequestArgs ) {
727+ const file = ts . normalizePath ( args . file ) ;
728+ const project = this . projectService . getProjectForFile ( file ) ;
729+ if ( ! project ) {
730+ throw Errors . NoProject ;
731+ }
732+
733+ return project . languageService . getFormattingEditsForRange ( file , args . position , args . endPosition , args . options ) ;
734+ }
735+
736+ private getFormattingEditsForDocumentFull ( args : protocol . FormatRequestArgs ) {
737+ const file = ts . normalizePath ( args . file ) ;
738+ const project = this . projectService . getProjectForFile ( file ) ;
739+ if ( ! project ) {
740+ throw Errors . NoProject ;
741+ }
742+
743+ return project . languageService . getFormattingEditsForDocument ( file , args . options ) ;
744+ }
745+
746+ private getFormattingEditsAfterKeystrokeFull ( args : protocol . FormatOnKeyRequestArgs ) {
747+ const file = ts . normalizePath ( args . file ) ;
748+ const project = this . projectService . getProjectForFile ( file ) ;
749+ if ( ! project ) {
750+ throw Errors . NoProject ;
751+ }
752+
753+ return project . languageService . getFormattingEditsAfterKeystroke ( file , args . position , args . key , args . options ) ;
754+ }
755+
723756 private getFormattingEditsAfterKeystroke ( line : number , offset : number , key : string , fileName : string ) : protocol . CodeEdit [ ] {
724757 const file = ts . normalizePath ( fileName ) ;
725758
@@ -1180,11 +1213,20 @@ namespace ts.server {
11801213 } ,
11811214 [ CommandNames . Format ] : ( request : protocol . Request ) => {
11821215 const formatArgs = < protocol . FormatRequestArgs > request . arguments ;
1183- return { response : this . getFormattingEditsForRange ( formatArgs . line , formatArgs . offset , formatArgs . endLine , formatArgs . endOffset , formatArgs . file ) , responseRequired : true } ;
1216+ return this . requiredResponse ( this . getFormattingEditsForRange ( formatArgs . line , formatArgs . offset , formatArgs . endLine , formatArgs . endOffset , formatArgs . file ) ) ;
11841217 } ,
11851218 [ CommandNames . Formatonkey ] : ( request : protocol . Request ) => {
11861219 const formatOnKeyArgs = < protocol . FormatOnKeyRequestArgs > request . arguments ;
1187- return { response : this . getFormattingEditsAfterKeystroke ( formatOnKeyArgs . line , formatOnKeyArgs . offset , formatOnKeyArgs . key , formatOnKeyArgs . file ) , responseRequired : true } ;
1220+ return this . requiredResponse ( this . getFormattingEditsAfterKeystroke ( formatOnKeyArgs . line , formatOnKeyArgs . offset , formatOnKeyArgs . key , formatOnKeyArgs . file ) ) ;
1221+ } ,
1222+ [ CommandNames . FormatFull ] : ( request : protocol . FormatRequest ) => {
1223+ return this . requiredResponse ( this . getFormattingEditsForDocumentFull ( request . arguments ) ) ;
1224+ } ,
1225+ [ CommandNames . FormatonkeyFull ] : ( request : protocol . FormatOnKeyRequest ) => {
1226+ return this . requiredResponse ( this . getFormattingEditsAfterKeystrokeFull ( request . arguments ) ) ;
1227+ } ,
1228+ [ CommandNames . FormatRangeFull ] : ( request : protocol . FormatRequest ) => {
1229+ return this . requiredResponse ( this . getFormattingEditsForRangeFull ( request . arguments ) ) ;
11881230 } ,
11891231 [ CommandNames . Completions ] : ( request : protocol . CompletionDetailsRequest ) => {
11901232 return this . requiredResponse ( this . getCompletions ( request . arguments , /*simplifiedResult*/ true ) ) ;
0 commit comments