Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// create Monaco editor
const value = `{
"$schema": "http://json.schemastore.org/coffeelint",
"line_endings": "unix"
}`;
const editor = monaco.editor.create(document.getElementById("container")!, {
model: monaco.editor.createModel(value, 'json', monaco.Uri.parse('inmemory://model.json')),
glyphMargin: true,
lightbulb: {
enabled: true
}
});
// install Monaco language client services
MonacoServices.install(editor);
// create the web socket
const url = createUrl('/sampleServer')
const webSocket = createWebSocket(url);
// listen when the web socket is opened
listen({
webSocket,
onConnection: connection => {
// create and start the language client
const languageClient = createLanguageClient(connection);
const disposable = languageClient.start();
connection.onClose(() => disposable.dispose());
}
});
function createLanguageClient(connection: MessageConnection): MonacoLanguageClient {
editor.addAction({
id: 'runTests',
label: 'Run tests',
keybindings: [monacoEditor.KeyCode.F2],
run: onRunTests,
})
editor.addAction({
id: 'submit',
label: 'Submit',
keybindings: [monacoEditor.KeyCode.F3],
run: onSubmit,
})
MonacoServices.install(editor)
editor.setModel(filesRef.current[0].model)
// Fix a custom code font rendering bug
// See https://github.com/exercism/website/issues/742#issuecomment-816806513
document.fonts.ready.then(() => monacoEditor.editor.remeasureFonts())
editorDidMount({ getFiles, setFiles, openPalette })
}
{
theme: 'vs-light',
language: CADENCE_LANGUAGE_ID,
model: model,
minimap: {
enabled: false
},
}
);
// The Monaco Language Client services have to be installed globally, once.
// An editor must be passed, which is only used for commands.
// As the Cadence language server is not providing any commands this is OK
if (id === 1) {
MonacoServices.install(editor);
}
const server = await createServer(
'cadence-language-server.wasm',
(address: string): string | undefined => {
if (address === '0000000000000001') {
return models[0].getValue()
}
}
)
// The stop button demonstrates how to dispose the editor
// and stop the language server
buttonElement.addEventListener('click', () => {
editor.dispose()
const editor = monaco.editor.create(document.getElementById('container')!, {
model: monaco.editor.createModel(value, 'bflu', monaco.Uri.parse('inmemory://model.json')),
glyphMargin: true,
autoClosingBrackets: 'always',
wordBasedSuggestions: false,
autoIndent: true,
formatOnType: true,
lightbulb: {
enabled: true,
},
theme: 'lutheme',
});
// install Monaco language client services
MonacoServices.install(editor);
// create the web socket
const url = createUrl('/luServer');
const webSocket = createWebSocket(url);
// listen when the web socket is opened
listen({
webSocket,
onConnection: connection => {
// create and start the language client
const languageClient = createLanguageClient(connection);
const disposable: Disposable = languageClient.start();
connection.onClose(() => disposable.dispose());
// editor.addCommand(monaco.KeyMod.Alt | monaco.KeyCode.F9, function () {
// connection.sendRequest(DocumentOnTypeFormattingRequest.type );
// });
},
const value = `#ted
- hello hello
- range
- great
- ted hello `;
const editor = monaco.editor.create(document.getElementById('container')!, {
model: monaco.editor.createModel(value, 'botbuilderlg', monaco.Uri.parse('inmemory://model.json')),
glyphMargin: true,
lightbulb: {
enabled: true,
},
theme: 'lgtheme',
});
// install Monaco language client services
MonacoServices.install(editor);
// create the web socket
const url = createUrl('/lgServer');
const webSocket = createWebSocket(url);
// listen when the web socket is opened
listen({
webSocket,
onConnection: connection => {
// create and start the language client
const languageClient = createLanguageClient(connection);
const disposable = languageClient.start();
connection.onClose(() => disposable.dispose());
},
});
function createLanguageClient(connection: MessageConnection): MonacoLanguageClient {
// create Monaco editor
const value = `export class Bar {
}
`;
const rootUri = (window as any).rootUri;
const editor = monaco.editor.create(document.getElementById("container")!, {
model: monaco.editor.createModel(value, "typescript", monaco.Uri.parse(rootUri + '/bar.ts')),
glyphMargin: true,
lightbulb: {
enabled: true
}
});
// install Monaco language client services
MonacoServices.install(editor, { rootUri });
const p2m = new ProtocolToMonacoConverter();
// create the web socket
const url = createUrl('/sampleServer')
const webSocket = createWebSocket(url);
// listen when the web socket is opened
listen({
webSocket,
onConnection: connection => {
// create and start the language client
const languageClient = createLanguageClient(connection);
languageClient.onReady().then(() => {
languageClient.onRequest(TypeScriptRenameRequest.type, params => {
editor.setPosition(p2m.asPosition(params.position));
editor.trigger('', 'editor.action.rename', {});
});
const handleEditorDidMount = (
editor: monacoEditor.editor.IStandaloneCodeEditor
) => {
editorRef.current = editor
editor.addAction({
id: 'runTests',
label: 'Run tests',
keybindings: [monacoEditor.KeyCode.F2],
run: onRunTests,
})
MonacoServices.install(editor)
editorDidMount(editor)
}
const editorDidMount = (editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: typeof monacoEditor) => {
if (!window.monacoServiceInstance) {
window.monacoServiceInstance = MonacoServices.install(editor as monacoCore.editor.IStandaloneCodeEditor | any);
}
if (!window.monacoLGEditorInstance) {
const uri = get(editor.getModel(), 'uri._formatted', '');
const url = createUrl(lgServer);
const webSocket: WebSocket = createWebSocket(url);
listen({
webSocket,
onConnection: (connection: MessageConnection) => {
const languageClient = createLanguageClient('LG Language Client', ['botbuilderlg'], connection);
if (!window.monacoLGEditorInstance) {
window.monacoLGEditorInstance = languageClient;
}
initializeDocuments(lgOption, uri);
const disposable = languageClient.start();
connection.onClose(() => disposable.dispose());