Skip to content

Commit 16b64f3

Browse files
committed
LSP rename
1 parent b6f11b3 commit 16b64f3

14 files changed

+1654
-41
lines changed

libsolidity/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ set(sources
159159
lsp/FileRepository.h
160160
lsp/GotoDefinition.cpp
161161
lsp/GotoDefinition.h
162+
lsp/RenameSymbol.cpp
163+
lsp/RenameSymbol.h
162164
lsp/HandlerBase.cpp
163165
lsp/HandlerBase.h
164166
lsp/LanguageServer.cpp

libsolidity/lsp/FileRepository.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class FileRepository
4444
/// Changes the source identified by the LSP client path _uri to _text.
4545
void setSourceByUri(std::string const& _uri, std::string _text);
4646

47-
void addOrUpdateFile(boost::filesystem::path const& _path, frontend::SourceCode _source);
4847
void setSourceUnits(StringMap _sources);
4948
frontend::ReadCallback::Result readFile(std::string const& _kind, std::string const& _sourceUnitName);
5049
frontend::ReadCallback::Callback reader()

libsolidity/lsp/HandlerBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class HandlerBase
4545
/// from the JSON-RPC parameters.
4646
std::pair<std::string, langutil::LineColumn> extractSourceUnitNameAndLineColumn(Json::Value const& _params) const;
4747

48-
langutil::CharStreamProvider const& charStreamProvider() const noexcept { return m_server.charStreamProvider(); }
49-
FileRepository const& fileRepository() const noexcept { return m_server.fileRepository(); }
48+
langutil::CharStreamProvider const& charStreamProvider() const noexcept { return m_server.compilerStack(); }
49+
FileRepository& fileRepository() const noexcept { return m_server.fileRepository(); }
5050
Transport& client() const noexcept { return m_server.client(); }
5151

5252
protected:

libsolidity/lsp/LanguageServer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
// LSP feature implementations
2828
#include <libsolidity/lsp/GotoDefinition.h>
29+
#include <libsolidity/lsp/RenameSymbol.h>
2930
#include <libsolidity/lsp/SemanticTokensBuilder.h>
3031

3132
#include <liblangutil/SourceReferenceExtractor.h>
@@ -124,6 +125,7 @@ LanguageServer::LanguageServer(Transport& _transport):
124125
{"textDocument/didOpen", bind(&LanguageServer::handleTextDocumentDidOpen, this, _2)},
125126
{"textDocument/didChange", bind(&LanguageServer::handleTextDocumentDidChange, this, _2)},
126127
{"textDocument/didClose", bind(&LanguageServer::handleTextDocumentDidClose, this, _2)},
128+
{"textDocument/rename", RenameSymbol(*this) },
127129
{"textDocument/implementation", GotoDefinition(*this) },
128130
{"textDocument/semanticTokens/full", bind(&LanguageServer::semanticTokensFull, this, _1, _2)},
129131
{"workspace/didChangeConfiguration", bind(&LanguageServer::handleWorkspaceDidChangeConfiguration, this, _2)},
@@ -314,6 +316,8 @@ void LanguageServer::handleInitialize(MessageID _id, Json::Value const& _args)
314316
replyArgs["capabilities"]["semanticTokensProvider"]["legend"] = semanticTokensLegend();
315317
replyArgs["capabilities"]["semanticTokensProvider"]["range"] = false;
316318
replyArgs["capabilities"]["semanticTokensProvider"]["full"] = true; // XOR requests.full.delta = true
319+
replyArgs["capabilities"]["renameProvider"] = true;
320+
317321

318322
m_client.reply(_id, move(replyArgs));
319323
}
@@ -432,6 +436,7 @@ void LanguageServer::handleTextDocumentDidClose(Json::Value const& _args)
432436
compileAndUpdateDiagnostics();
433437
}
434438

439+
435440
ASTNode const* LanguageServer::astNodeAtSourceLocation(std::string const& _sourceUnitName, LineColumn const& _filePos)
436441
{
437442
if (m_compilerStack.state() < CompilerStack::AnalysisPerformed)

libsolidity/lsp/LanguageServer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
namespace solidity::lsp
3434
{
3535

36+
class RenameSymbol;
3637
enum class ErrorCode;
3738

3839
/**
@@ -60,7 +61,7 @@ class LanguageServer
6061
FileRepository& fileRepository() noexcept { return m_fileRepository; }
6162
Transport& client() noexcept { return m_client; }
6263
frontend::ASTNode const* astNodeAtSourceLocation(std::string const& _sourceUnitName, langutil::LineColumn const& _filePos);
63-
langutil::CharStreamProvider const& charStreamProvider() const noexcept { return m_compilerStack; }
64+
frontend::CompilerStack const& compilerStack() const noexcept { return m_compilerStack; }
6465

6566
private:
6667
/// Checks if the server is initialized (to be used by messages that need it to be initialized).
@@ -72,6 +73,7 @@ class LanguageServer
7273
void handleTextDocumentDidOpen(Json::Value const& _args);
7374
void handleTextDocumentDidChange(Json::Value const& _args);
7475
void handleTextDocumentDidClose(Json::Value const& _args);
76+
void handleRename(Json::Value const& _args);
7577
void handleGotoDefinition(MessageID _id, Json::Value const& _args);
7678
void semanticTokensFull(MessageID _id, Json::Value const& _args);
7779

0 commit comments

Comments
 (0)