File tree Expand file tree Collapse file tree 2 files changed +44
-16
lines changed Expand file tree Collapse file tree 2 files changed +44
-16
lines changed Original file line number Diff line number Diff line change @@ -531,8 +531,25 @@ function createInterface(msg: p.RequestMessage): m.Message {
531
531
let resPartialPath = filePath . split ( projDir ) [ 1 ] ;
532
532
533
533
// The .cmi filename may have a namespace suffix appended.
534
- let namespace = utils . getNamespaceNameFromBsConfig ( projDir ) ;
535
- let suffixToAppend = namespace ? "-" + namespace : "" ;
534
+ let namespaceResult = utils . getNamespaceNameFromBsConfig ( projDir ) ;
535
+
536
+ if ( namespaceResult . kind === "error" ) {
537
+ let params : p . ShowMessageParams = {
538
+ type : p . MessageType . Error ,
539
+ message : `Error reading bsconfig file.` ,
540
+ } ;
541
+
542
+ let response : m . NotificationMessage = {
543
+ jsonrpc : c . jsonrpcVersion ,
544
+ method : "window/showMessage" ,
545
+ params,
546
+ } ;
547
+
548
+ return response ;
549
+ }
550
+
551
+ let namespace = namespaceResult . result
552
+ let suffixToAppend = namespace . length > 0 ? "-" + namespace : "" ;
536
553
537
554
let cmiPartialPath = path . join (
538
555
path . dirname ( resPartialPath ) ,
Original file line number Diff line number Diff line change @@ -188,20 +188,31 @@ export const toCamelCase = (text: string): string => {
188
188
189
189
export const getNamespaceNameFromBsConfig = (
190
190
projDir : p . DocumentUri
191
- ) : string | null => {
192
- let bsconfigFile = fs . readFileSync (
193
- path . join ( projDir , c . bsconfigPartialPath ) ,
194
- { encoding : "utf-8" }
195
- ) ;
196
-
197
- let bsconfig = JSON . parse ( bsconfigFile ) ;
198
-
199
- if ( bsconfig . namespace === true ) {
200
- return toCamelCase ( bsconfig . name ) ;
201
- } else if ( typeof bsconfig . namespace === "string" ) {
202
- return toCamelCase ( bsconfig . namespace ) ;
203
- } else {
204
- return null ;
191
+ ) : execResult => {
192
+ try {
193
+ let bsconfigFile = fs . readFileSync (
194
+ path . join ( projDir , c . bsconfigPartialPath ) ,
195
+ { encoding : "utf-8" }
196
+ ) ;
197
+
198
+ let bsconfig = JSON . parse ( bsconfigFile ) ;
199
+ let result = "" ;
200
+
201
+ if ( bsconfig . namespace === true ) {
202
+ result = toCamelCase ( bsconfig . name ) ;
203
+ } else if ( typeof bsconfig . namespace === "string" ) {
204
+ result = toCamelCase ( bsconfig . namespace ) ;
205
+ }
206
+
207
+ return {
208
+ kind : "success" ,
209
+ result,
210
+ } ;
211
+ } catch ( e ) {
212
+ return {
213
+ kind : "error" ,
214
+ error : e instanceof Error ? e . message : String ( e ) ,
215
+ } ;
205
216
}
206
217
} ;
207
218
You can’t perform that action at this time.
0 commit comments