@@ -46,7 +46,8 @@ export function YqlEditor({
4646} : YqlEditorProps ) {
4747 const input = useTypedSelector ( selectUserInput ) ;
4848 const dispatch = useTypedDispatch ( ) ;
49- const monacoGhostInstanceRef = React . useRef < ReturnType < typeof createMonacoGhostInstance > > ( ) ;
49+ const [ monacoGhostInstance , setMonacoGhostInstance ] =
50+ React . useState < ReturnType < typeof createMonacoGhostInstance > > ( ) ;
5051 const historyQueries = useTypedSelector ( selectQueriesHistory ) ;
5152 const [ isCodeAssistEnabled ] = useSetting ( ENABLE_CODE_ASSISTANT ) ;
5253
@@ -77,18 +78,15 @@ export function YqlEditor({
7778 const { monacoGhostConfig, prepareUserQueriesCache} = useCodeAssistHelpers ( ) ;
7879
7980 React . useEffect ( ( ) => {
80- if ( monacoGhostInstanceRef . current && window . api . codeAssist ) {
81- if ( isCodeAssistEnabled ) {
82- monacoGhostInstanceRef . current . register ( monacoGhostConfig ) ;
83- prepareUserQueriesCache ( ) ;
84- } else {
85- monacoGhostInstanceRef . current . unregister ( ) ;
86- }
81+ if ( monacoGhostInstance && isCodeAssistEnabled ) {
82+ monacoGhostInstance . register ( monacoGhostConfig ) ;
83+ prepareUserQueriesCache ( ) ;
8784 }
85+
8886 return ( ) => {
89- monacoGhostInstanceRef . current ?. unregister ( ) ;
87+ monacoGhostInstance ?. unregister ( ) ;
9088 } ;
91- } , [ isCodeAssistEnabled , monacoGhostConfig , prepareUserQueriesCache ] ) ;
89+ } , [ isCodeAssistEnabled , monacoGhostConfig , monacoGhostInstance , prepareUserQueriesCache ] ) ;
9290
9391 const editorDidMount = ( editor : Monaco . editor . IStandaloneCodeEditor , monaco : typeof Monaco ) => {
9492 window . ydbEditor = editor ;
@@ -103,7 +101,10 @@ export function YqlEditor({
103101 }
104102 } ) ;
105103
106- monacoGhostInstanceRef . current = createMonacoGhostInstance ( editor ) ;
104+ if ( window . api . codeAssist ) {
105+ setMonacoGhostInstance ( createMonacoGhostInstance ( editor ) ) ;
106+ }
107+
107108 initResizeHandler ( editor ) ;
108109 initUserPrompt ( editor , getLastQueryText ) ;
109110 editor . focus ( ) ;
0 commit comments