@@ -175,42 +175,42 @@ export class Session {
175
175
conn . onSignatureHelp ( p => this . onSignatureHelp ( p ) ) ;
176
176
}
177
177
178
- private isInAngularProject ( params : IsInAngularProjectParams ) : boolean | undefined {
178
+ private isInAngularProject ( params : IsInAngularProjectParams ) : boolean | null {
179
179
const filePath = uriToFilePath ( params . textDocument . uri ) ;
180
180
if ( ! filePath ) {
181
181
return false ;
182
182
}
183
183
const lsAndScriptInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
184
184
if ( ! lsAndScriptInfo ) {
185
- // If we cannot get language service / script info, return undefined to indicate we don't know
185
+ // If we cannot get language service / script info, return null to indicate we don't know
186
186
// the answer definitively.
187
- return undefined ;
187
+ return null ;
188
188
}
189
189
const project = this . getDefaultProjectForScriptInfo ( lsAndScriptInfo . scriptInfo ) ;
190
190
if ( ! project ) {
191
- // If we cannot get project, return undefined to indicate we don't know
191
+ // If we cannot get project, return null to indicate we don't know
192
192
// the answer definitively.
193
- return undefined ;
193
+ return null ;
194
194
}
195
195
const angularCore = project . getFileNames ( ) . find ( isAngularCore ) ;
196
196
return angularCore !== undefined ;
197
197
}
198
198
199
- private onGetTcb ( params : GetTcbParams ) : GetTcbResponse | undefined {
199
+ private onGetTcb ( params : GetTcbParams ) : GetTcbResponse | null {
200
200
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
201
- if ( lsInfo === undefined ) {
202
- return undefined ;
201
+ if ( lsInfo === null ) {
202
+ return null ;
203
203
}
204
204
const { languageService, scriptInfo} = lsInfo ;
205
205
const offset = lspPositionToTsPosition ( scriptInfo , params . position ) ;
206
206
const response = languageService . getTcb ( scriptInfo . fileName , offset ) ;
207
207
if ( response === undefined ) {
208
- return undefined ;
208
+ return null ;
209
209
}
210
210
const { fileName : tcfName } = response ;
211
211
const tcfScriptInfo = this . projectService . getScriptInfo ( tcfName ) ;
212
212
if ( ! tcfScriptInfo ) {
213
- return undefined ;
213
+ return null ;
214
214
}
215
215
return {
216
216
uri : filePathToUri ( tcfName ) ,
@@ -219,10 +219,10 @@ export class Session {
219
219
} ;
220
220
}
221
221
222
- private onGetComponentsWithTemplateFile ( params : any ) : lsp . Location [ ] | undefined {
222
+ private onGetComponentsWithTemplateFile ( params : any ) : lsp . Location [ ] | null {
223
223
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
224
- if ( lsInfo === undefined ) {
225
- return undefined ;
224
+ if ( lsInfo === null ) {
225
+ return null ;
226
226
}
227
227
const { languageService, scriptInfo} = lsInfo ;
228
228
const documentSpans = languageService . getComponentLocationsForTemplate ( scriptInfo . fileName ) ;
@@ -238,18 +238,18 @@ export class Session {
238
238
return results ;
239
239
}
240
240
241
- private onSignatureHelp ( params : lsp . SignatureHelpParams ) : lsp . SignatureHelp | undefined {
241
+ private onSignatureHelp ( params : lsp . SignatureHelpParams ) : lsp . SignatureHelp | null {
242
242
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
243
- if ( lsInfo === undefined ) {
244
- return undefined ;
243
+ if ( lsInfo === null ) {
244
+ return null ;
245
245
}
246
246
247
247
const { languageService, scriptInfo} = lsInfo ;
248
248
const offset = lspPositionToTsPosition ( scriptInfo , params . position ) ;
249
249
250
250
const help = languageService . getSignatureHelpItems ( scriptInfo . fileName , offset , undefined ) ;
251
251
if ( help === undefined ) {
252
- return undefined ;
252
+ return null ;
253
253
}
254
254
255
255
return {
@@ -289,9 +289,9 @@ export class Session {
289
289
} ;
290
290
}
291
291
292
- private onCodeLens ( params : lsp . CodeLensParams ) : lsp . CodeLens [ ] | undefined {
292
+ private onCodeLens ( params : lsp . CodeLensParams ) : lsp . CodeLens [ ] | null {
293
293
if ( ! params . textDocument . uri . endsWith ( '.html' ) || ! this . isInAngularProject ( params ) ) {
294
- return undefined ;
294
+ return null ;
295
295
}
296
296
const position = lsp . Position . create ( 0 , 0 ) ;
297
297
const topOfDocument = lsp . Range . create ( position , position ) ;
@@ -307,7 +307,7 @@ export class Session {
307
307
308
308
private onCodeLensResolve ( params : lsp . CodeLens ) : lsp . CodeLens {
309
309
const components = this . onGetComponentsWithTemplateFile ( { textDocument : params . data } ) ;
310
- if ( components === undefined || components . length === 0 ) {
310
+ if ( components === null || components . length === 0 ) {
311
311
// While the command is supposed to be optional, vscode will show `!!MISSING: command!!` that
312
312
// fails if you click on it when a command is not provided. Instead, throwing an error will
313
313
// make vscode show the text "no commands" (and it's not a link).
@@ -752,7 +752,7 @@ export class Session {
752
752
753
753
private onDefinition ( params : lsp . TextDocumentPositionParams ) : lsp . LocationLink [ ] | undefined {
754
754
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
755
- if ( lsInfo === undefined ) {
755
+ if ( lsInfo === null ) {
756
756
return ;
757
757
}
758
758
const { languageService, scriptInfo} = lsInfo ;
@@ -767,7 +767,7 @@ export class Session {
767
767
768
768
private onTypeDefinition ( params : lsp . TextDocumentPositionParams ) : lsp . LocationLink [ ] | undefined {
769
769
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
770
- if ( lsInfo === undefined ) {
770
+ if ( lsInfo === null ) {
771
771
return ;
772
772
}
773
773
const { languageService, scriptInfo} = lsInfo ;
@@ -781,7 +781,7 @@ export class Session {
781
781
782
782
private onRenameRequest ( params : lsp . RenameParams ) : lsp . WorkspaceEdit | undefined {
783
783
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
784
- if ( lsInfo === undefined ) {
784
+ if ( lsInfo === null ) {
785
785
return ;
786
786
}
787
787
const { languageService, scriptInfo} = lsInfo ;
@@ -810,7 +810,7 @@ export class Session {
810
810
const fileEdits = changes [ location . fileName ] ;
811
811
812
812
const lsInfo = this . getLSAndScriptInfo ( location . fileName ) ;
813
- if ( lsInfo === undefined ) {
813
+ if ( lsInfo === null ) {
814
814
return changes ;
815
815
}
816
816
const range = tsTextSpanToLspRange ( lsInfo . scriptInfo , location . textSpan ) ;
@@ -822,10 +822,10 @@ export class Session {
822
822
}
823
823
824
824
private onPrepareRename ( params : lsp . PrepareRenameParams ) :
825
- { range : lsp . Range , placeholder : string } | undefined {
825
+ { range : lsp . Range , placeholder : string } | null {
826
826
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
827
- if ( lsInfo === undefined ) {
828
- return ;
827
+ if ( lsInfo === null ) {
828
+ return null ;
829
829
}
830
830
const { languageService, scriptInfo} = lsInfo ;
831
831
if ( scriptInfo . scriptKind === ts . ScriptKind . TS ) {
@@ -836,13 +836,13 @@ export class Session {
836
836
}
837
837
const project = this . getDefaultProjectForScriptInfo ( scriptInfo ) ;
838
838
if ( project === undefined || this . renameDisabledProjects . has ( project ) ) {
839
- return ;
839
+ return null ;
840
840
}
841
841
842
842
const offset = lspPositionToTsPosition ( scriptInfo , params . position ) ;
843
843
const renameInfo = languageService . getRenameInfo ( scriptInfo . fileName , offset ) ;
844
844
if ( ! renameInfo . canRename ) {
845
- return undefined ;
845
+ return null ;
846
846
}
847
847
const range = tsTextSpanToLspRange ( scriptInfo , renameInfo . triggerSpan ) ;
848
848
return {
@@ -853,7 +853,7 @@ export class Session {
853
853
854
854
private onReferences ( params : lsp . TextDocumentPositionParams ) : lsp . Location [ ] | undefined {
855
855
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
856
- if ( lsInfo === undefined ) {
856
+ if ( lsInfo === null ) {
857
857
return ;
858
858
}
859
859
const { languageService, scriptInfo} = lsInfo ;
@@ -899,28 +899,28 @@ export class Session {
899
899
}
900
900
901
901
private getLSAndScriptInfo ( textDocumentOrFileName : lsp . TextDocumentIdentifier | string ) :
902
- { languageService : NgLanguageService , scriptInfo : ts . server . ScriptInfo } | undefined {
902
+ { languageService : NgLanguageService , scriptInfo : ts . server . ScriptInfo } | null {
903
903
const filePath = lsp . TextDocumentIdentifier . is ( textDocumentOrFileName ) ?
904
904
uriToFilePath ( textDocumentOrFileName . uri ) :
905
905
textDocumentOrFileName ;
906
906
const scriptInfo = this . projectService . getScriptInfo ( filePath ) ;
907
907
if ( ! scriptInfo ) {
908
908
this . error ( `Script info not found for ${ filePath } ` ) ;
909
- return ;
909
+ return null ;
910
910
}
911
911
912
912
const project = this . getDefaultProjectForScriptInfo ( scriptInfo ) ;
913
913
if ( ! project ?. languageServiceEnabled ) {
914
- return ;
914
+ return null ;
915
915
}
916
916
if ( project . isClosed ( ) ) {
917
917
scriptInfo . detachFromProject ( project ) ;
918
918
this . logger . info ( `Failed to get language service for closed project ${ project . projectName } .` ) ;
919
- return undefined ;
919
+ return null ;
920
920
}
921
921
const languageService = project . getLanguageService ( ) ;
922
922
if ( ! isNgLanguageService ( languageService ) ) {
923
- return undefined ;
923
+ return null ;
924
924
}
925
925
return {
926
926
languageService,
@@ -930,7 +930,7 @@ export class Session {
930
930
931
931
private onHover ( params : lsp . TextDocumentPositionParams ) {
932
932
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
933
- if ( lsInfo === undefined ) {
933
+ if ( lsInfo === null ) {
934
934
return ;
935
935
}
936
936
const { languageService, scriptInfo} = lsInfo ;
@@ -965,7 +965,7 @@ export class Session {
965
965
966
966
private onCompletion ( params : lsp . CompletionParams ) {
967
967
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
968
- if ( lsInfo === undefined ) {
968
+ if ( lsInfo === null ) {
969
969
return ;
970
970
}
971
971
const { languageService, scriptInfo} = lsInfo ;
@@ -992,7 +992,7 @@ export class Session {
992
992
993
993
const { filePath, position} = data ;
994
994
const lsInfo = this . getLSAndScriptInfo ( filePath ) ;
995
- if ( lsInfo === undefined ) {
995
+ if ( lsInfo === null ) {
996
996
return item ;
997
997
}
998
998
const { languageService, scriptInfo} = lsInfo ;
@@ -1068,25 +1068,25 @@ export class Session {
1068
1068
*
1069
1069
* @returns main declaration file in `@angular/core`.
1070
1070
*/
1071
- private findAngularCore ( project : ts . server . Project ) : string | undefined {
1071
+ private findAngularCore ( project : ts . server . Project ) : string | null {
1072
1072
const { projectName} = project ;
1073
1073
if ( ! project . languageServiceEnabled ) {
1074
1074
this . info (
1075
1075
`Language service is already disabled for ${ projectName } . ` +
1076
1076
`This could be due to non-TS files that exceeded the size limit (${
1077
1077
ts . server . maxProgramSizeForNonTsFiles } bytes).` +
1078
1078
`Please check log file for details.` ) ;
1079
- return ;
1079
+ return null ;
1080
1080
}
1081
1081
if ( ! project . hasRoots ( ) || project . isNonTsProject ( ) ) {
1082
- return undefined ;
1082
+ return null ;
1083
1083
}
1084
1084
const angularCore = project . getFileNames ( ) . find ( isAngularCore ) ;
1085
1085
if ( angularCore === undefined && project . getExcludedFiles ( ) . some ( isAngularCore ) ) {
1086
1086
this . info (
1087
1087
`Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.` ) ;
1088
1088
}
1089
- return angularCore ;
1089
+ return angularCore ?? null ;
1090
1090
}
1091
1091
1092
1092
/**
0 commit comments