@@ -111,6 +111,8 @@ namespace ts.server {
111111 export const Formatonkey = "formatonkey" ;
112112 export const Geterr = "geterr" ;
113113 export const GeterrForProject = "geterrForProject" ;
114+ export const SemanticDiagnosticsSync = "semanticDiagnosticsFull" ;
115+ export const SyntacticDiagnosticsSync = "syntacticDiagnosticsFull" ;
114116 export const NavBar = "navbar" ;
115117 export const Navto = "navto" ;
116118 export const Occurrences = "occurrences" ;
@@ -130,6 +132,7 @@ namespace ts.server {
130132
131133 namespace Errors {
132134 export const NoProject = new Error ( "No Project." ) ;
135+ export const ProjectLanguageServiceDisabled = new Error ( "The project's language service is disabled." ) ;
133136 }
134137
135138 export interface ServerHost extends ts . System {
@@ -384,6 +387,27 @@ namespace ts.server {
384387 } ) ;
385388 }
386389
390+ private getDiagnosticsWorker ( args : protocol . FileRequestArgs , selector : ( project : Project , file : string ) => Diagnostic [ ] ) {
391+ const file = normalizePath ( args . file ) ;
392+ const project = this . projectService . getProjectForFile ( file ) ;
393+ if ( ! project ) {
394+ throw Errors . NoProject ;
395+ }
396+ if ( project . languageServiceDiabled ) {
397+ throw Errors . ProjectLanguageServiceDisabled ;
398+ }
399+ const diagnostics = selector ( project , file ) ;
400+ return ts . map ( diagnostics , originalDiagnostic => formatDiag ( file , project , originalDiagnostic ) ) ;
401+ }
402+
403+ private getSyntacticDiagnosticsSync ( args : protocol . FileRequestArgs ) : protocol . Diagnostic [ ] {
404+ return this . getDiagnosticsWorker ( args , ( project , file ) => project . compilerService . languageService . getSyntacticDiagnostics ( file ) ) ;
405+ }
406+
407+ private getSemanticDiagnosticsSync ( args : protocol . FileRequestArgs ) : protocol . Diagnostic [ ] {
408+ return this . getDiagnosticsWorker ( args , ( project , file ) => project . compilerService . languageService . getSemanticDiagnostics ( file ) ) ;
409+ }
410+
387411 private getDocumentHighlights ( line : number , offset : number , fileName : string , filesToSearch : string [ ] ) : protocol . DocumentHighlightsItem [ ] {
388412 fileName = ts . normalizePath ( fileName ) ;
389413 const project = this . projectService . getProjectForFile ( fileName ) ;
@@ -1032,6 +1056,10 @@ namespace ts.server {
10321056 exit ( ) {
10331057 }
10341058
1059+ private requiredResponse ( response : any ) {
1060+ return { response, responseRequired : true } ;
1061+ }
1062+
10351063 private handlers : Map < ( request : protocol . Request ) => { response ?: any , responseRequired ?: boolean } > = {
10361064 [ CommandNames . Exit ] : ( ) => {
10371065 this . exit ( ) ;
@@ -1100,6 +1128,12 @@ namespace ts.server {
11001128 const signatureHelpArgs = < protocol . SignatureHelpRequestArgs > request . arguments ;
11011129 return { response : this . getSignatureHelpItems ( signatureHelpArgs . line , signatureHelpArgs . offset , signatureHelpArgs . file ) , responseRequired : true } ;
11021130 } ,
1131+ [ CommandNames . SemanticDiagnosticsSync ] : ( request : protocol . FileRequest ) => {
1132+ return this . requiredResponse ( this . getSemanticDiagnosticsSync ( request . arguments ) ) ;
1133+ } ,
1134+ [ CommandNames . SyntacticDiagnosticsSync ] : ( request : protocol . FileRequest ) => {
1135+ return this . requiredResponse ( this . getSyntacticDiagnosticsSync ( request . arguments ) ) ;
1136+ } ,
11031137 [ CommandNames . Geterr ] : ( request : protocol . Request ) => {
11041138 const geterrArgs = < protocol . GeterrRequestArgs > request . arguments ;
11051139 return { response : this . getDiagnostics ( geterrArgs . delay , geterrArgs . files ) , responseRequired : false } ;
0 commit comments