public void connect()

in PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-bicep/src/main/java/org/wso2/lsp4intellij/client/languageserver/wrapper/LanguageServerWrapper.java [324:426]


    public void connect(Editor editor) {
        if (editor == null) {
            LOG.warn("editor is null for " + serverDefinition);
            return;
        }
        if (!FileUtils.isEditorSupported(editor)) {
            LOG.debug("Editor hosts a unsupported file type by the LS library.");
            return;
        }

        String uri = editorToURIString(editor);
        if (connectedEditors.contains(editor)) {
            return;
        }
        ImmutablePair<String, String> key = new ImmutablePair<>(uri, editorToProjectFolderUri(editor));

        uriToLanguageServerWrapper.put(key, this);

        start();
        if (initializeFuture != null) {
            ServerCapabilities capabilities = getServerCapabilities();
            if (capabilities == null) {
                LOG.warn("Capabilities are null for " + serverDefinition);
                return;
            }

            initializeFuture.thenRun(() -> {
                if (connectedEditors.contains(editor)) {
                    return;
                }
                try {
                    Either<TextDocumentSyncKind, TextDocumentSyncOptions> syncOptions = capabilities.getTextDocumentSync();
                    if (syncOptions != null) {
                        //Todo - Implement
                        //  SelectionListenerImpl selectionListener = new SelectionListenerImpl();
                        DocumentListenerImpl documentListener = new DocumentListenerImpl();
                        EditorMouseListenerImpl mouseListener = new EditorMouseListenerImpl();
                        EditorMouseMotionListenerImpl mouseMotionListener = new EditorMouseMotionListenerImpl();
                        LSPCaretListenerImpl caretListener = new LSPCaretListenerImpl();

                        ServerOptions serverOptions = new ServerOptions(capabilities);
                        EditorEventManager manager;
                        if (extManager != null) {
                            manager = extManager.getExtendedEditorEventManagerFor(editor, documentListener,
                                    mouseListener, mouseMotionListener, caretListener, requestManager, serverOptions,
                                    this);
                            if (manager == null) {
                                manager = new EditorEventManager(editor, documentListener, mouseListener,
                                        mouseMotionListener, caretListener,
                                        requestManager, serverOptions, this);
                            }
                        } else {
                            manager = new EditorEventManager(editor, documentListener, mouseListener,
                                    mouseMotionListener, caretListener,
                                    requestManager, serverOptions, this);
                        }
                        // selectionListener.setManager(manager);
                        documentListener.setManager(manager);
                        mouseListener.setManager(manager);
                        mouseMotionListener.setManager(manager);
                        caretListener.setManager(manager);
                        manager.registerListeners();
                        if (!urisUnderLspControl.contains(uri)) {
                            manager.documentEventManager.registerListeners();
                        }
                        urisUnderLspControl.add(uri);
                        connectedEditors.add(editor);
                        if (uriToEditorManagers.containsKey(uri)) {
                            uriToEditorManagers.get(uri).add(manager);
                        } else {
                            Set<EditorEventManager> set = new HashSet<>();
                            set.add(manager);
                            uriToEditorManagers.put(uri, set);
                            manager.documentOpened();
                        }
                        LOG.info("Created a manager for " + uri);
                        synchronized (toConnect) {
                            toConnect.remove(editor);
                        }
                        for (Editor ed : new HashSet<>(toConnect)) {
                            connect(ed);
                        }
                        // Triggers annotators since this is the first editor which starts the LS
                        // and annotators are executed before LS is bootstrap to provide diagnostics.
                        computableReadAction(() -> {
                            PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
                            if (psiFile != null) {
                                DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
                            }
                            return null;
                        });
                    }
                } catch (Exception e) {
                    LOG.error(e);
                }
            });

        } else {
            synchronized (toConnect) {
                toConnect.add(editor);
            }
        }
    }