@@ -20,8 +20,12 @@ import { type Monaco, MonacoEditor, setTheme } from '../../monaco';
2020import { addKeyboardShortcutOverrides } from '../../monaco/keyboard-overrides' ;
2121import { useHandleDiffDismissed } from '../contexts/MonacoRefContext' ;
2222
23+ import createCompletionProvider from '../../editor/magic-completion' ;
24+
25+ import { LoadingIndicator } from './common/LoadingIndicator' ;
2326import { Cursors } from './Cursors' ;
2427import { Tooltip } from './Tooltip' ;
28+ import { loadDTS , type Lib } from '../utils/loadDTS' ;
2529
2630export interface MonacoHandle {
2731 showDiff : ( originalCode : string , modifiedCode : string ) => void ;
@@ -33,6 +37,7 @@ interface CollaborativeMonacoProps {
3337 ytext : Y . Text ;
3438 awareness : Awareness ;
3539 adaptor ?: string ;
40+ metadata ?: object ;
3641 disabled ?: boolean ;
3742 className ?: string ;
3843 options ?: editor . IStandaloneEditorConstructionOptions ;
@@ -46,6 +51,7 @@ export const CollaborativeMonaco = forwardRef<
4651 ytext,
4752 awareness,
4853 adaptor = 'common' ,
54+ metadata,
4955 disabled = false ,
5056 className,
5157 options = { } ,
@@ -57,6 +63,10 @@ export const CollaborativeMonaco = forwardRef<
5763 const bindingRef = useRef < MonacoBinding > ( ) ;
5864 const [ editorReady , setEditorReady ] = useState ( false ) ;
5965
66+ // Type definitions state
67+ const [ lib , setLib ] = useState < Lib [ ] > ( ) ;
68+ const [ loading , setLoading ] = useState ( false ) ;
69+
6070 // Get callback from context to notify when diff is dismissed
6171 const handleDiffDismissed = useHandleDiffDismissed ( ) ;
6272
@@ -66,6 +76,9 @@ export const CollaborativeMonaco = forwardRef<
6676 const containerRef = useRef < HTMLDivElement | null > ( null ) ;
6777 const diffContainerRef = useRef < HTMLDivElement | null > ( null ) ;
6878
79+ // Overflow widgets container ref
80+ const overflowNodeRef = useRef < HTMLDivElement > ( ) ;
81+
6982 // Base editor options shared between main and diff editors
7083 const baseEditorOptions : editor . IStandaloneEditorConstructionOptions =
7184 useMemo (
@@ -82,6 +95,18 @@ export const CollaborativeMonaco = forwardRef<
8295 insertSpaces : true ,
8396 automaticLayout : true ,
8497 fixedOverflowWidgets : true ,
98+ codeLens : false ,
99+ wordBasedSuggestions : 'off' ,
100+ showFoldingControls : 'always' ,
101+ suggest : {
102+ showModules : true ,
103+ showKeywords : false ,
104+ showFiles : false ,
105+ showClasses : false ,
106+ showInterfaces : false ,
107+ showConstructors : false ,
108+ showDeprecated : false ,
109+ } ,
85110 } ) ,
86111 [ ]
87112 ) ;
@@ -99,6 +124,12 @@ export const CollaborativeMonaco = forwardRef<
99124
100125 addKeyboardShortcutOverrides ( editor , monaco ) ;
101126
127+ // Configure TypeScript compiler options
128+ monaco . languages . typescript . javascriptDefaults . setCompilerOptions ( {
129+ allowNonTsExtensions : true ,
130+ noLib : true ,
131+ } ) ;
132+
102133 // Don't create binding here - let the useEffect handle it
103134 // This ensures binding is created/updated whenever ytext changes
104135 } ,
@@ -210,6 +241,55 @@ export const CollaborativeMonaco = forwardRef<
210241 } ;
211242 } , [ ] ) ;
212243
244+ // Load type definitions when adaptor changes
245+ useEffect ( ( ) => {
246+ if ( adaptor ) {
247+ setLoading ( true ) ;
248+ setLib ( [ ] ) ; // instantly clear intelligence
249+ loadDTS ( adaptor )
250+ . then ( l => {
251+ setLib ( l ) ;
252+ } )
253+ . finally ( ( ) => {
254+ setLoading ( false ) ;
255+ } ) ;
256+ }
257+ } , [ adaptor ] ) ;
258+
259+ // Set extra libs on Monaco when lib changes
260+ useEffect ( ( ) => {
261+ if ( monacoRef . current && lib ) {
262+ monacoRef . current . languages . typescript . javascriptDefaults . setExtraLibs (
263+ lib
264+ ) ;
265+ }
266+ } , [ lib ] ) ;
267+
268+ // Register metadata completion provider
269+ useEffect ( ( ) => {
270+ if ( monacoRef . current && metadata ) {
271+ const provider =
272+ monacoRef . current . languages . registerCompletionItemProvider (
273+ 'javascript' ,
274+ createCompletionProvider ( monacoRef . current , metadata )
275+ ) ;
276+ return ( ) => {
277+ provider . dispose ( ) ;
278+ } ;
279+ }
280+ } , [ metadata ] ) ;
281+
282+ // Cleanup overflow node on unmount
283+ useEffect ( ( ) => {
284+ return ( ) => {
285+ if ( overflowNodeRef . current ) {
286+ overflowNodeRef . current . parentNode ?. removeChild (
287+ overflowNodeRef . current
288+ ) ;
289+ }
290+ } ;
291+ } , [ ] ) ;
292+
213293 // showDiff function - creates diff editor overlay
214294 const showDiff = useCallback (
215295 ( originalCode : string , modifiedCode : string ) => {
@@ -354,6 +434,9 @@ export const CollaborativeMonaco = forwardRef<
354434
355435 return (
356436 < div className = { cn ( 'relative' , className || 'h-full w-full' ) } >
437+ < div className = "relative z-10 h-0 overflow-visible text-right text-xs text-white" >
438+ { loading && < LoadingIndicator text = "Loading types" /> }
439+ </ div >
357440 { /* Standard editor container */ }
358441 < div ref = { containerRef } className = "h-full w-full" >
359442 < Cursors />
0 commit comments