2021-12-13 13:53:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libsolidity/interface/FileReader.h>
|
2022-05-09 15:34:35 +00:00
|
|
|
#include <libsolutil/Result.h>
|
2021-12-13 13:53:40 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace solidity::lsp
|
|
|
|
{
|
|
|
|
|
|
|
|
class FileRepository
|
|
|
|
{
|
|
|
|
public:
|
2022-05-09 15:34:35 +00:00
|
|
|
FileRepository(boost::filesystem::path _basePath, std::vector<boost::filesystem::path> _includePaths);
|
|
|
|
|
|
|
|
std::vector<boost::filesystem::path> const& includePaths() const noexcept { return m_includePaths; }
|
|
|
|
void setIncludePaths(std::vector<boost::filesystem::path> _paths);
|
2021-12-13 13:53:40 +00:00
|
|
|
|
2022-04-25 13:35:41 +00:00
|
|
|
boost::filesystem::path const& basePath() const { return m_basePath; }
|
2021-12-13 13:53:40 +00:00
|
|
|
|
|
|
|
/// Translates a compiler-internal source unit name to an LSP client path.
|
2022-04-25 13:35:41 +00:00
|
|
|
std::string sourceUnitNameToUri(std::string const& _sourceUnitName) const;
|
|
|
|
|
|
|
|
/// Translates an LSP file URI into a compiler-internal source unit name.
|
|
|
|
std::string uriToSourceUnitName(std::string const& _uri) const;
|
2021-12-13 13:53:40 +00:00
|
|
|
|
|
|
|
/// @returns all sources by their compiler-internal source unit name.
|
2022-04-25 13:35:41 +00:00
|
|
|
StringMap const& sourceUnits() const noexcept { return m_sourceCodes; }
|
|
|
|
|
2021-12-13 13:53:40 +00:00
|
|
|
/// Changes the source identified by the LSP client path _uri to _text.
|
2022-04-25 13:35:41 +00:00
|
|
|
void setSourceByUri(std::string const& _uri, std::string _text);
|
2021-12-13 13:53:40 +00:00
|
|
|
|
2022-04-25 13:35:41 +00:00
|
|
|
void setSourceUnits(StringMap _sources);
|
|
|
|
frontend::ReadCallback::Result readFile(std::string const& _kind, std::string const& _sourceUnitName);
|
|
|
|
frontend::ReadCallback::Callback reader()
|
|
|
|
{
|
|
|
|
return [this](std::string const& _kind, std::string const& _path) { return readFile(_kind, _path); };
|
|
|
|
}
|
2021-12-13 13:53:40 +00:00
|
|
|
|
2022-05-09 15:34:35 +00:00
|
|
|
util::Result<boost::filesystem::path> tryResolvePath(std::string const& _sourceUnitName) const;
|
|
|
|
|
2021-12-13 13:53:40 +00:00
|
|
|
private:
|
2022-04-25 13:35:41 +00:00
|
|
|
/// Base path without URI scheme.
|
|
|
|
boost::filesystem::path m_basePath;
|
|
|
|
|
|
|
|
/// Additional directories used for resolving relative paths in imports.
|
|
|
|
std::vector<boost::filesystem::path> m_includePaths;
|
|
|
|
|
|
|
|
/// Mapping of source unit names to their URIs as understood by the client.
|
|
|
|
StringMap m_sourceUnitNamesToUri;
|
|
|
|
|
|
|
|
/// Mapping of source unit names to their file content.
|
|
|
|
StringMap m_sourceCodes;
|
2021-12-13 13:53:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|