| 1 |
#ifndef LANGUAGESERVERCLUSTER_H |
| 2 |
#define LANGUAGESERVERCLUSTER_H |
| 3 |
|
| 4 |
#include "CodeLiteRemoteHelper.hpp" |
| 5 |
#include "LSP/LSPEvent.h" |
| 6 |
#include "LSP/basic_types.h" |
| 7 |
#include "LanguageServerEntry.h" |
| 8 |
#include "LanguageServerProtocol.h" |
| 9 |
#include "clWorkspaceEvent.hpp" |
| 10 |
#include "cl_command_event.h" |
| 11 |
#include "entry.h" |
| 12 |
|
| 13 |
#include <unordered_set> |
| 14 |
#include <vector> |
| 15 |
#include <wx/event.h> |
| 16 |
#include <wx/sharedptr.h> |
| 17 |
#include <wxStringHash.h> |
| 18 |
|
| 19 |
class LSPOutlineViewDlg; |
| 20 |
class LanguageServerPlugin; |
| 21 |
class LanguageServerCluster : public wxEvtHandler |
| 22 |
{ |
| 23 |
struct CrashInfo { |
| 24 |
size_t times = 0; |
| 25 |
time_t last_crash = 0; |
| 26 |
}; |
| 27 |
|
| 28 |
std::unordered_map<wxString, LanguageServerProtocol::Ptr_t> m_servers; |
| 29 |
std::unordered_map<wxString, CrashInfo> m_restartCounters; |
| 30 |
std::unordered_map<wxString, std::vector<LSP::SymbolInformation>> m_symbols_to_file_cache; |
| 31 |
LanguageServerPlugin* m_plugin = nullptr; |
| 32 |
LSPOutlineViewDlg* m_quick_outline_dlg = nullptr; |
| 33 |
std::unique_ptr<CodeLiteRemoteHelper> m_remoteHelper; |
| 34 |
|
| 35 |
public: |
| 36 |
typedef wxSharedPtr<LanguageServerCluster> Ptr_t; |
| 37 |
|
| 38 |
public: |
| 39 |
void StartServer(const LanguageServerEntry& entry); |
| 40 |
void StartServer(const wxString& entry); |
| 41 |
void RestartServer(const wxString& name); |
| 42 |
|
| 43 |
void StopServer(const wxString& entry); |
| 44 |
void DeleteServer(const wxString& name); |
| 45 |
|
| 46 |
void StopAll(const std::unordered_set<wxString>& languages = {}); |
| 47 |
void StartAll(const std::unordered_set<wxString>& languages = {}); |
| 48 |
void ClearAllDiagnostics(); |
| 49 |
void SetWorkspaceType(FileExtManager::FileType type); |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief covnert LSP::SignatureHelp class to TagEntryPtrVector_t |
| 53 |
*/ |
| 54 |
void LSPSignatureHelpToTagEntries(TagEntryPtrVector_t& tags, const LSP::SignatureHelp& sighelp); |
| 55 |
|
| 56 |
protected: |
| 57 |
void OnSignatureHelp(LSPEvent& event); |
| 58 |
void OnHover(LSPEvent& event); |
| 59 |
void OnSymbolFound(LSPEvent& event); |
| 60 |
void OnCompletionReady(LSPEvent& event); |
| 61 |
void OnReparseNeeded(LSPEvent& event); |
| 62 |
void OnRestartNeeded(LSPEvent& event); |
| 63 |
void OnLSPInitialized(LSPEvent& event); |
| 64 |
void OnMethodNotFound(LSPEvent& event); |
| 65 |
void OnWorkspaceClosed(clWorkspaceEvent& event); |
| 66 |
void OnWorkspaceOpen(clWorkspaceEvent& event); |
| 67 |
void OnCompileCommandsGenerated(clCommandEvent& event); |
| 68 |
void OnSetDiagnostics(LSPEvent& event); |
| 69 |
void OnClearDiagnostics(LSPEvent& event); |
| 70 |
void OnQuickOutlineView(LSPEvent& event); |
| 71 |
void OnShowQuickOutlineDlg(LSPEvent& event); |
| 72 |
void OnOulineViewSymbols(LSPEvent& event); |
| 73 |
void OnSemanticTokens(LSPEvent& event); |
| 74 |
void OnLogMessage(LSPEvent& event); |
| 75 |
void OnDocumentSymbolsForHighlight(LSPEvent& event); |
| 76 |
void OnBuildEnded(clBuildEvent& event); |
| 77 |
void OnOpenResource(wxCommandEvent& event); |
| 78 |
void OnEditorClosed(clCommandEvent& event); |
| 79 |
void OnActiveEditorChanged(wxCommandEvent& event); |
| 80 |
void OnWorkspaceScanCompleted(clWorkspaceEvent& event); |
| 81 |
|
| 82 |
wxString GetEditorFilePath(IEditor* editor) const; |
| 83 |
/** |
| 84 |
* @brief find an editor either by local or remote path |
| 85 |
*/ |
| 86 |
IEditor* FindEditor(const wxString& path) const; |
| 87 |
IEditor* FindEditor(const LSPEvent& event) const; |
| 88 |
|
| 89 |
void DiscoverWorkspaceType(); |
| 90 |
void UpdateNavigationBar(); |
| 91 |
|
| 92 |
public: |
| 93 |
LanguageServerCluster(LanguageServerPlugin* plugin); |
| 94 |
virtual ~LanguageServerCluster(); |
| 95 |
/** |
| 96 |
* @brief restart language servers associated with a given languages |
| 97 |
*/ |
| 98 |
void Reload(const std::unordered_set<wxString>& languages = {}); |
| 99 |
LanguageServerProtocol::Ptr_t GetServerForEditor(IEditor* editor); |
| 100 |
LanguageServerProtocol::Ptr_t GetServerByName(const wxString& name); |
| 101 |
LanguageServerProtocol::Ptr_t GetServerForLanguage(const wxString& lang); |
| 102 |
void ClearRestartCounters(); |
| 103 |
}; |
| 104 |
|
| 105 |
#endif // LANGUAGESERVERCLUSTER_H |