Skip to content

Commit

Permalink
LSP: don't send the tokenTypes in the InitializeRequest unless th…
Browse files Browse the repository at this point in the history
…is is the gopls LSP
  • Loading branch information
eranif committed Jul 15, 2024
1 parent 8b29e60 commit e143ce3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 62 deletions.
73 changes: 38 additions & 35 deletions CodeLite/LSP/InitializeRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include <wx/filesys.h>

LSP::InitializeRequest::InitializeRequest(const wxString& rootUri)
LSP::InitializeRequest::InitializeRequest(bool withTokenTypes, const wxString& rootUri)
: m_withTokenTypes(withTokenTypes)
{
SetMethod("initialize");
m_processId = ::wxGetProcessId();
Expand Down Expand Up @@ -45,41 +46,43 @@ JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
hoverFormat.arrayAppend("markdown");
hoverFormat.arrayAppend("plaintext");

auto sematicTokens = textDocumentCapabilities.AddObject("semanticTokens");
auto tokenTypes = sematicTokens.AddArray("tokenTypes");
tokenTypes.arrayAppend("type");
tokenTypes.arrayAppend("class");
tokenTypes.arrayAppend("enum");
tokenTypes.arrayAppend("interface");
tokenTypes.arrayAppend("struct");
tokenTypes.arrayAppend("typeParameter");
tokenTypes.arrayAppend("parameter");
tokenTypes.arrayAppend("variable");
tokenTypes.arrayAppend("property");
tokenTypes.arrayAppend("enumMember");
tokenTypes.arrayAppend("event");
tokenTypes.arrayAppend("function");
tokenTypes.arrayAppend("method");
tokenTypes.arrayAppend("macro");
tokenTypes.arrayAppend("keyword");
tokenTypes.arrayAppend("modifier");
tokenTypes.arrayAppend("comment");
tokenTypes.arrayAppend("string");
tokenTypes.arrayAppend("number");
tokenTypes.arrayAppend("regexp");
tokenTypes.arrayAppend("operator");
if (m_withTokenTypes) {
auto sematicTokens = textDocumentCapabilities.AddObject("semanticTokens");
auto tokenTypes = sematicTokens.AddArray("tokenTypes");
tokenTypes.arrayAppend("type");
tokenTypes.arrayAppend("class");
tokenTypes.arrayAppend("enum");
tokenTypes.arrayAppend("interface");
tokenTypes.arrayAppend("struct");
tokenTypes.arrayAppend("typeParameter");
tokenTypes.arrayAppend("parameter");
tokenTypes.arrayAppend("variable");
tokenTypes.arrayAppend("property");
tokenTypes.arrayAppend("enumMember");
tokenTypes.arrayAppend("event");
tokenTypes.arrayAppend("function");
tokenTypes.arrayAppend("method");
tokenTypes.arrayAppend("macro");
tokenTypes.arrayAppend("keyword");
tokenTypes.arrayAppend("modifier");
tokenTypes.arrayAppend("comment");
tokenTypes.arrayAppend("string");
tokenTypes.arrayAppend("number");
tokenTypes.arrayAppend("regexp");
tokenTypes.arrayAppend("operator");

auto tokenModifiers = sematicTokens.AddArray("tokenModifiers");
tokenModifiers.arrayAppend("declaration");
tokenModifiers.arrayAppend("definition");
tokenModifiers.arrayAppend("readonly");
tokenModifiers.arrayAppend("static");
tokenModifiers.arrayAppend("deprecated");
tokenModifiers.arrayAppend("abstract");
tokenModifiers.arrayAppend("async");
tokenModifiers.arrayAppend("modification");
tokenModifiers.arrayAppend("documentation");
tokenModifiers.arrayAppend("defaultLibrary");
auto tokenModifiers = sematicTokens.AddArray("tokenModifiers");
tokenModifiers.arrayAppend("declaration");
tokenModifiers.arrayAppend("definition");
tokenModifiers.arrayAppend("readonly");
tokenModifiers.arrayAppend("static");
tokenModifiers.arrayAppend("deprecated");
tokenModifiers.arrayAppend("abstract");
tokenModifiers.arrayAppend("async");
tokenModifiers.arrayAppend("modification");
tokenModifiers.arrayAppend("documentation");
tokenModifiers.arrayAppend("defaultLibrary");
}
return json;
}

Expand Down
5 changes: 3 additions & 2 deletions CodeLite/LSP/InitializeRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class WXDLLIMPEXP_CL InitializeRequest : public LSP::Request
int m_processId = wxNOT_FOUND;
wxString m_rootUri;
wxString m_initOptions;
bool m_withTokenTypes = false;

public:
InitializeRequest(const wxString& rootUri = "");
InitializeRequest(bool withTokenTypes, const wxString& rootUri = "");
virtual ~InitializeRequest();
InitializeRequest& SetProcessId(int processId)
{
Expand All @@ -32,5 +33,5 @@ class WXDLLIMPEXP_CL InitializeRequest : public LSP::Request
void SetInitOptions(const wxString& initOptions) { this->m_initOptions = initOptions; }
const wxString& GetInitOptions() const { return m_initOptions; }
};
}; // namespace LSP
}; // namespace LSP
#endif // INITIALIZEREQUEST_H
3 changes: 0 additions & 3 deletions LanguageServer/LSPDetectorManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "LSPDetectorManager.hpp"

#include "LanguageServerConfig.h"
#include "LanguageServerEntry.h"
#include "detectors/LSPCMakeDetector.hpp"
#include "detectors/LSPCTagsdDetector.hpp"
#include "detectors/LSPClangdDetector.hpp"
Expand All @@ -11,7 +9,6 @@
#include "detectors/LSPRustAnalyzerDetector.hpp"
#include "detectors/LSPTypeScriptDetector.hpp"
#include "environmentconfig.h"
#include "file_logger.h"

LSPDetectorManager::LSPDetectorManager()
{
Expand Down
10 changes: 8 additions & 2 deletions Plugin/LSP/LanguageServerProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void LanguageServerProtocol::DoClear()
m_initializeRequestID = wxNOT_FOUND;
m_Queue.Clear();
m_lastCompletionRequestId = wxNOT_FOUND;
// Destory the current connection
// Destroy the current connection
m_network->Close();
}

Expand Down Expand Up @@ -674,7 +674,13 @@ void LanguageServerProtocol::OnNetConnected(clCommandEvent& event)

// The process started successfully
// Send the 'initialize' request
LSP::InitializeRequest::Ptr_t req = LSP::MessageWithParams::MakeRequest(new LSP::InitializeRequest());

// Go lsp requires the client to send the list of tokenTypes (for semanticTokens support) in the
// initialise request
bool withTokenTypesHack = CanHandle(FileExtManager::TypeGo);
LSP::InitializeRequest::Ptr_t req =
LSP::MessageWithParams::MakeRequest(new LSP::InitializeRequest(withTokenTypesHack));

// some LSPs will crash if we path an empty root folder
wxString root_uri = m_rootFolder;
if (root_uri.empty()) {
Expand Down
25 changes: 5 additions & 20 deletions docs/docs/plugins/lsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,13 @@ select the ones you are interested in and then [configure them in CodeLite][14]
TARGET=$(rustup target list|grep installed|cut -d" " -f1)
$HOME/.rustup/toolchains/nightly-$TARGET/bin/rust-analyzer```

=== "rls"
`rls` is yet another rust language server, but less popular than `rust-analzyer`
=== "gopls"
`gopls` (pronounced "Go Please") is the official LSP for `golang`

To install it:

- [Install rust][13]
- Open a terminal and type:
- On `macOS` and `Linux`:
```bash
rustup update
rustup component add rls rust-analysis rust-src```

- On `Windows`:
```batch
%USERPROFILE%\.cargo\bin\rustup update
%USERPROFILE%\.cargo\bin\rustup component add rls rust-analysis rust-src```

Visit the [project home page][8]

!!! Important
The `rls` language server must be started from the cargo project directory
i.e. the location of the `Cargo.toml` file
```bash
go install golang.org/x/tools/gopls@latest
```

---

Expand Down

0 comments on commit e143ce3

Please sign in to comment.