Skip to content

Commit

Permalink
Language Server: Adds support for configuring extra include paths ``i…
Browse files Browse the repository at this point in the history
…nclude-paths`` JSON settings object that can be passed during LSP configuration stage.
  • Loading branch information
christianparpart committed May 16, 2022
1 parent f6c6179 commit 0a4acc5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Compiler Features:
* SMTChecker: Support ``abi.encodeCall`` taking into account the called selector.
* Language Server: Allow full filesystem access to language server.
* Language Server: Always adds ``{project_root}/node_modules`` to include search paths.
* Language Server: Adds support for configuring extra include paths ``include-paths`` JSON settings object that can be passed during LSP configuration stage.


Bugfixes:
Expand Down
14 changes: 13 additions & 1 deletion libsolidity/lsp/FileRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ using solidity::util::Result;

FileRepository::FileRepository(boost::filesystem::path _basePath): m_basePath(std::move(_basePath))
{
m_includePaths.emplace_back(m_basePath / "node_modules");
}

void FileRepository::setIncludePaths(std::vector<boost::filesystem::path> _paths)
{
// Prefix relative paths with base-path.
for (auto& path: _paths)
if (path.is_relative())
path = m_basePath / path;

// Always have {projectRoot}/node_modules in the include-paths.
_paths.emplace_back(m_basePath / "node_modules");

m_includePaths = std::move(_paths);
}

string FileRepository::sourceUnitNameToUri(string const& _sourceUnitName) const
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/lsp/FileRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class FileRepository
public:
explicit FileRepository(boost::filesystem::path _basePath);

void setIncludePaths(std::vector<boost::filesystem::path> _paths);

boost::filesystem::path const& basePath() const { return m_basePath; }

/// Translates a compiler-internal source unit name to an LSP client path.
Expand Down
15 changes: 15 additions & 0 deletions libsolidity/lsp/LanguageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ Json::Value LanguageServer::toJson(SourceLocation const& _location)
void LanguageServer::changeConfiguration(Json::Value const& _settings)
{
m_settingsObject = _settings;
if (_settings["include-paths"] && _settings["include-paths"].isArray())
{
std::vector<boost::filesystem::path> includePaths;
Json::Value jsonIncludePaths = _settings["includes"];
for (Json::Value jsonPath : jsonIncludePaths)
{
if (!jsonPath.isString())
{
m_client.trace("Invalid JSON configuration passed. \"include-paths\" must be an array of strings.");
continue;
}
includePaths.emplace_back(boost::filesystem::path(jsonPath.asString()));
}
m_fileRepository.setIncludePaths(move(includePaths));
}
}

void LanguageServer::compile()
Expand Down

0 comments on commit 0a4acc5

Please sign in to comment.