mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Applying more review.
This commit is contained in:
parent
02e84ea547
commit
e924346e1b
@ -165,14 +165,14 @@ set(sources
|
||||
lsp/HandlerBase.h
|
||||
lsp/LanguageServer.cpp
|
||||
lsp/LanguageServer.h
|
||||
lsp/SemanticHighlight.cpp
|
||||
lsp/SemanticHighlight.h
|
||||
lsp/SemanticHighlighter.cpp
|
||||
lsp/SemanticHighlighter.h
|
||||
lsp/SemanticTokensBuilder.cpp
|
||||
lsp/SemanticTokensBuilder.h
|
||||
lsp/ReferenceCollector.cpp
|
||||
lsp/ReferenceCollector.h
|
||||
lsp/References.cpp
|
||||
lsp/References.h
|
||||
lsp/ReferencesHandler.cpp
|
||||
lsp/ReferencesHandler.h
|
||||
lsp/Transport.cpp
|
||||
lsp/Transport.h
|
||||
lsp/Utils.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*LanguageServer.cpp
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
@ -26,9 +26,9 @@
|
||||
|
||||
// LSP feature implementations
|
||||
#include <libsolidity/lsp/GotoDefinition.h>
|
||||
#include <libsolidity/lsp/References.h>
|
||||
#include <libsolidity/lsp/ReferencesHandler.h>
|
||||
#include <libsolidity/lsp/RenameSymbol.h>
|
||||
#include <libsolidity/lsp/SemanticHighlight.h>
|
||||
#include <libsolidity/lsp/SemanticHighlighter.h>
|
||||
#include <libsolidity/lsp/SemanticTokensBuilder.h>
|
||||
|
||||
#include <liblangutil/SourceReferenceExtractor.h>
|
||||
@ -147,10 +147,10 @@ LanguageServer::LanguageServer(Transport& _transport):
|
||||
{"textDocument/didChange", bind(&LanguageServer::handleTextDocumentDidChange, this, _2)},
|
||||
{"textDocument/didClose", bind(&LanguageServer::handleTextDocumentDidClose, this, _2)},
|
||||
{"textDocument/rename", RenameSymbol(*this) },
|
||||
{"textDocument/documentHighlight", SemanticHighlight(*this) },
|
||||
{"textDocument/documentHighlight", SemanticHighlighter(*this) },
|
||||
{"textDocument/implementation", GotoDefinition(*this) },
|
||||
{"textDocument/semanticTokens/full", bind(&LanguageServer::semanticTokensFull, this, _1, _2)},
|
||||
{"textDocument/references", References(*this) },
|
||||
{"textDocument/references", ReferencesHandler(*this) },
|
||||
{"workspace/didChangeConfiguration", bind(&LanguageServer::handleWorkspaceDidChangeConfiguration, this, _2)},
|
||||
},
|
||||
m_fileRepository("/" /* basePath */, {} /* no search paths */),
|
||||
@ -187,7 +187,7 @@ void LanguageServer::changeConfiguration(Json::Value const& _settings)
|
||||
else if (text == "directly-opened-and-on-import")
|
||||
m_fileLoadStrategy = FileLoadStrategy::DirectlyOpenedAndOnImported;
|
||||
else
|
||||
lspRequire(false, ErrorCode::InvalidParams, "Invalid file load strategy: " + text);
|
||||
lspAssert(false, "Invalid file load strategy: " + text);
|
||||
}
|
||||
|
||||
m_settingsObject = _settings;
|
||||
|
@ -107,7 +107,7 @@ bool ReferenceCollector::visit(ImportDirective const& _import)
|
||||
|
||||
void ReferenceCollector::endVisit(Identifier const& _identifier)
|
||||
{
|
||||
if (Declaration const* declaration = _identifier.annotation().referencedDeclaration; declaration == &m_declaration)
|
||||
if (_identifier.annotation().referencedDeclaration == &m_declaration)
|
||||
m_collectedReferences.emplace_back(_identifier.location(), m_kind);
|
||||
}
|
||||
|
||||
@ -133,12 +133,18 @@ void ReferenceCollector::endVisit(MemberAccess const& _memberAccess)
|
||||
|
||||
bool ReferenceCollector::visit(Assignment const& _assignment)
|
||||
{
|
||||
auto const getDocumentHighlightKind = [](Expression const& _expression) noexcept -> DocumentHighlightKind {
|
||||
if (_expression.annotation().willBeWrittenTo)
|
||||
return DocumentHighlightKind::Write;
|
||||
return DocumentHighlightKind::Read;
|
||||
};
|
||||
|
||||
auto const restoreKind = ScopeGuard{[this, savedKind=m_kind]() { m_kind = savedKind; }};
|
||||
|
||||
m_kind = DocumentHighlightKind::Write;
|
||||
m_kind = getDocumentHighlightKind(_assignment.leftHandSide());
|
||||
_assignment.leftHandSide().accept(*this);
|
||||
|
||||
m_kind = DocumentHighlightKind::Read;
|
||||
m_kind = getDocumentHighlightKind(_assignment.rightHandSide());
|
||||
_assignment.rightHandSide().accept(*this);
|
||||
|
||||
return false;
|
||||
|
@ -30,7 +30,6 @@ namespace solidity::lsp
|
||||
*/
|
||||
enum class DocumentHighlightKind
|
||||
{
|
||||
Unspecified = 0, //!< could be for example a highlight found in a comment
|
||||
Text = 1, //!< a textual occurrence
|
||||
Read = 2, //!< read access to a variable
|
||||
Write = 3, //!< write access to a variable
|
||||
|
@ -15,7 +15,7 @@
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
#include <libsolidity/lsp/References.h>
|
||||
#include <libsolidity/lsp/ReferencesHandler.h>
|
||||
#include <libsolidity/lsp/ReferenceCollector.h>
|
||||
#include <libsolidity/lsp/LanguageServer.h>
|
||||
#include <libsolidity/lsp/Utils.h>
|
||||
@ -29,7 +29,7 @@ using namespace solidity::frontend;
|
||||
namespace solidity::lsp
|
||||
{
|
||||
|
||||
void References::operator()(MessageID _id, Json::Value const& _args)
|
||||
void ReferencesHandler::operator()(MessageID _id, Json::Value const& _args)
|
||||
{
|
||||
auto const [sourceUnitName, lineColumn] = extractSourceUnitNameAndLineColumn(_args);
|
||||
|
@ -23,10 +23,10 @@ namespace solidity::lsp
|
||||
/**
|
||||
* Implements JSON RPC for `textDocument/references`.
|
||||
*/
|
||||
class References: public HandlerBase
|
||||
class ReferencesHandler: public HandlerBase
|
||||
{
|
||||
public:
|
||||
explicit References(LanguageServer& _server): HandlerBase(_server) {}
|
||||
using HandlerBase::HandlerBase;
|
||||
|
||||
void operator()(MessageID _id, Json::Value const& _args);
|
||||
};
|
@ -15,7 +15,7 @@
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
#include <libsolidity/lsp/SemanticHighlight.h>
|
||||
#include <libsolidity/lsp/SemanticHighlighter.h>
|
||||
#include <libsolidity/lsp/Utils.h>
|
||||
|
||||
using namespace std;
|
||||
@ -23,24 +23,23 @@ using namespace solidity;
|
||||
using namespace solidity::lsp;
|
||||
using namespace solidity::frontend;
|
||||
|
||||
void SemanticHighlight::operator()(MessageID _id, Json::Value const& _args)
|
||||
void SemanticHighlighter::operator()(MessageID _id, Json::Value const& _args)
|
||||
{
|
||||
auto const [sourceUnitName, lineColumn] = extractSourceUnitNameAndLineColumn(_args);
|
||||
auto const [sourceNode, sourceOffset] = m_server.astNodeAndOffsetAtSourceLocation(sourceUnitName, lineColumn);
|
||||
|
||||
Json::Value jsonReply = Json::arrayValue;
|
||||
for (auto const& [location, kind]: semanticHighlight(sourceNode, sourceOffset, sourceUnitName))
|
||||
for (auto const& [location, kind]: findAllReferences(sourceNode, sourceOffset, sourceUnitName))
|
||||
{
|
||||
Json::Value item = Json::objectValue;
|
||||
item["range"] = toRange(location);
|
||||
if (kind != DocumentHighlightKind::Unspecified)
|
||||
item["kind"] = static_cast<int>(kind);
|
||||
item["kind"] = static_cast<int>(kind);
|
||||
jsonReply.append(item);
|
||||
}
|
||||
client().reply(_id, jsonReply);
|
||||
}
|
||||
|
||||
vector<Reference> SemanticHighlight::semanticHighlight(ASTNode const* _sourceNode, int _sourceOffset, string const& _sourceUnitName)
|
||||
vector<Reference> SemanticHighlighter::findAllReferences(ASTNode const* _sourceNode, int _sourceOffset, string const& _sourceUnitName)
|
||||
{
|
||||
if (!_sourceNode)
|
||||
return {};
|
@ -26,15 +26,15 @@ namespace solidity::lsp
|
||||
/**
|
||||
* Implements JSON RPC for `textDocument/documentHighlight`.
|
||||
*/
|
||||
class SemanticHighlight: public HandlerBase
|
||||
class SemanticHighlighter: public HandlerBase
|
||||
{
|
||||
public:
|
||||
explicit SemanticHighlight(LanguageServer& _server): HandlerBase(_server) {}
|
||||
using HandlerBase::HandlerBase;
|
||||
|
||||
void operator()(MessageID _id, Json::Value const& _args);
|
||||
|
||||
private:
|
||||
std::vector<Reference> semanticHighlight(frontend::ASTNode const* _sourceNode, int _sourceOffset, std::string const& _sourceUnitName);
|
||||
std::vector<Reference> findAllReferences(frontend::ASTNode const* _sourceNode, int _sourceOffset, std::string const& _sourceUnitName);
|
||||
};
|
||||
|
||||
}
|
@ -87,6 +87,11 @@ private:
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Fatally halts the process if the condition fails.
|
||||
*/
|
||||
#define lspAssert(condition, errorMessage) solAssert((condition), (errorMessage))
|
||||
|
||||
/**
|
||||
* Transport layer API
|
||||
*
|
||||
|
@ -23,14 +23,14 @@ contract MyContract
|
||||
// ^^^^^ @ColorType3
|
||||
// ^^^^^ @ColorType4
|
||||
{
|
||||
Color result = Color(a);
|
||||
Color Color = Color(a);
|
||||
// ^^^^^ @ColorType5
|
||||
// ^^^^^ @ColorType6
|
||||
if (a != lastColor)
|
||||
// ^^^^^^^^^ @lastCursor2
|
||||
result = Color.Green;
|
||||
Color = Color.Green;
|
||||
// ^^^^^ @ColorType7
|
||||
return result;
|
||||
return Color;
|
||||
}
|
||||
|
||||
function f() public pure returns (uint)
|
||||
@ -41,6 +41,7 @@ contract MyContract
|
||||
}
|
||||
|
||||
// ----
|
||||
// lib: @diagnostics 2519
|
||||
// -> textDocument/documentHighlight {
|
||||
// "position": @EnumDef
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user