| 237 | } |
| 238 | |
| 239 | void LanguageServer::compile() |
| 240 | { |
| 241 | // For files that are not open, we have to take changes on disk into account, |
| 242 | // so we just remove all non-open files. |
| 243 | |
| 244 | FileRepository oldRepository(m_fileRepository.basePath(), m_fileRepository.includePaths()); |
| 245 | std::swap(oldRepository, m_fileRepository); |
| 246 | |
| 247 | // Load all solidity files from project. |
| 248 | if (m_fileLoadStrategy == FileLoadStrategy::ProjectDirectory) |
| 249 | for (auto const& projectFile: allSolidityFilesFromProject()) |
| 250 | { |
| 251 | lspDebug(fmt::format("adding project file: {}", projectFile.generic_string())); |
| 252 | m_fileRepository.setSourceByUri( |
| 253 | m_fileRepository.sourceUnitNameToUri(projectFile.generic_string()), |
| 254 | util::readFileAsString(projectFile) |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | // Overwrite all files as opened by the client, including the ones which might potentially have changes. |
| 259 | for (std::string const& fileName: m_openFiles) |
| 260 | m_fileRepository.setSourceByUri( |
| 261 | fileName, |
| 262 | oldRepository.sourceUnits().at(oldRepository.uriToSourceUnitName(fileName)) |
| 263 | ); |
| 264 | |
| 265 | // TODO: optimize! do not recompile if nothing has changed (file(s) not flagged dirty). |
| 266 | |
| 267 | m_compilerStack.reset(false); |
| 268 | m_compilerStack.setSources(m_fileRepository.sourceUnits()); |
| 269 | m_compilerStack.compile(CompilerStack::State::AnalysisSuccessful); |
| 270 | } |
| 271 | |
| 272 | void LanguageServer::compileAndUpdateDiagnostics() |
| 273 | { |
no test coverage detected