@@ -3,6 +3,7 @@ import useDarkMode from "use-dark-mode";
3
3
import { monaco , ControlledEditor , Monaco } from "@monaco-editor/react" ;
4
4
import { MethodObject } from "@open-rpc/meta-schema" ;
5
5
import useWindowSize from "@rehooks/window-size" ;
6
+ import { addDiagnostics } from "@etclabscore/monaco-add-json-schema-diagnostics"
6
7
7
8
interface IProps {
8
9
onChange ?: ( newValue : any ) => void ;
@@ -25,10 +26,14 @@ const JSONRPCRequest: React.FC<IProps> = (props) => {
25
26
editorRef . current = editor ;
26
27
// Now you can use the instance of monaco editor
27
28
// in this component whenever you want
29
+ const modelName = props . openrpcMethodObject ? props . openrpcMethodObject . name : "inspector" ;
30
+ const modelUriString = `inmemory://${ modelName } .json` ;
28
31
monaco
29
32
. init ( )
30
33
. then ( ( m : Monaco ) => {
31
- const modelUri = m . Uri . parse ( `inmemory:/${ Math . random ( ) } /model/userSpec.json` ) ;
34
+ const modelUri = m . Uri . parse ( modelUriString ) ;
35
+ const model = m . editor . createModel ( props . value || "" , "json" , modelUri ) ;
36
+ editor . setModel ( model ) ;
32
37
let schema : any = {
33
38
type : "object" ,
34
39
properties : {
@@ -76,17 +81,7 @@ const JSONRPCRequest: React.FC<IProps> = (props) => {
76
81
} ,
77
82
} ;
78
83
}
79
- m . languages . json . jsonDefaults . setDiagnosticsOptions ( {
80
- enableSchemaRequest : true ,
81
- schemas : [
82
- {
83
- fileMatch : [ "*" ] ,
84
- schema,
85
- uri : modelUri . toString ( ) ,
86
- } ,
87
- ] ,
88
- validate : true ,
89
- } ) ;
84
+ addDiagnostics ( modelUri . toString ( ) , schema , m ) ;
90
85
} )
91
86
. catch ( ( error : Error ) => console . error ( "An error occurred during initialization of Monaco: " , error ) ) ;
92
87
}
0 commit comments