Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this.langServerConnection) {
resolve(this.langServerConnection);
} else {
const socketOptions = {
maxReconnectionDelay: 10000,
minReconnectionDelay: 1000,
reconnectionDelayGrowFactor: 1.3,
connectionTimeout: 10000,
maxRetries: Infinity,
debug: false,
};
// create the web socket
const url = getServiceEndpoint('ballerina-langserver');
const webSocket = new ReconnectingWebSocket(url, undefined, socketOptions);
const m2p = new MonacoToProtocolConverter();
const p2m = new ProtocolToMonacoConverter();
// listen when the web socket is opened
listen({
webSocket,
onConnection: (connection) => {
this.langServerConnection = connection;
// create and start the language client
const languageClient = new BaseLanguageClient({
name: 'Ballerina Language Client',
clientOptions: {
// use a language id as a document selector
documentSelector: ['ballerina-lang'],
// disable the default error handler
errorHandler: {
error: () => ErrorAction.Continue,
closed: () => CloseAction.DoNotRestart,
},
// 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', {});
});
});
export function createMonacoServices (editor, options) {
const m2p = new MonacoToProtocolConverter()
const p2m = new ProtocolToMonacoConverter()
return {
commands: new MonacoCommands(editor),
languages: new MonacoLanguages(p2m, m2p),
workspace: new MonacoWorkspace(p2m, m2p, options.rootUri),
window: new ConsoleWindow()
}
}