@@ -19,7 +19,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
1919 return ;
2020 }
2121 // get text before the position of the completion
22- let word = model . getValueInRange ( {
22+ const word = model . getValueInRange ( {
2323 startLineNumber : 1 ,
2424 startColumn : 1 ,
2525 endLineNumber : position . lineNumber ,
@@ -38,22 +38,26 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
3838 return ;
3939 }
4040
41- word = word . split ( '\n' )
42- if ( ! word . length ) return
43- const ask = word [ word . length - 2 ] . trimStart ( )
44- if ( word [ word . length - 1 ] === '' && ask . startsWith ( '///' ) ) {
45- // use the code generation model
46- const { data} = await axios . post ( 'https://gpt-chat.remixproject.org/infer' , { comment : ask . replace ( '///' , '' } )
47- const parsedData = JSON . parse ( data ) . trimStart ( )
48- console . log ( 'parsedData' , parsedData )
49- const item : monacoTypes . languages . InlineCompletion = {
50- insertText : parsedData
51- } ;
52- return {
53- items : [ item ] ,
54- enableForwardStability : true
41+ try {
42+ const split = word . split ( '\n' )
43+ if ( ! split . length ) return
44+ const ask = split [ split . length - 2 ] . trimStart ( )
45+ if ( split [ split . length - 1 ] . trim ( ) === '' && ask . startsWith ( '///' ) ) {
46+ // use the code generation model
47+ const { data} = await axios . post ( 'https://gpt-chat.remixproject.org/infer' , { comment : ask . replace ( '///' , '' ) } )
48+ const parsedData = JSON . parse ( data ) . trimStart ( )
49+ console . log ( 'parsedData' , parsedData )
50+ const item : monacoTypes . languages . InlineCompletion = {
51+ insertText : parsedData
52+ } ;
53+ return {
54+ items : [ item ] ,
55+ enableForwardStability : true
56+ }
5557 }
56- }
58+ } catch ( e ) {
59+ console . error ( e )
60+ }
5761
5862 // abort if there is a signal
5963 if ( token . isCancellationRequested ) {
0 commit comments