From 15de02ea0c92948e1c51b5da11541c2d382b79ca Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 30 Nov 2016 15:29:36 +0100 Subject: Clang: Add refactoring support for unsaved content We need the generated UI header but we don't have a build directory. So we provide clang with in memory represations of the file. Change-Id: Ie9db97bbea2222b0203a0457baa1f1fc7ad97213 Reviewed-by: Tim Jenssen --- .../source/refactoringserver.cpp | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/tools/clangrefactoringbackend/source/refactoringserver.cpp') diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp index debc827968..f4e5372e9a 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp @@ -72,7 +72,9 @@ void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLo void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage( RequestSourceRangesAndDiagnosticsForQueryMessage &&message) { - gatherSourceRangesAndDiagnosticsForQueryMessage(message.takeFileContainers(), message.takeQuery()); + gatherSourceRangesAndDiagnosticsForQueryMessage(message.takeSources(), + message.takeUnsavedContent(), + message.takeQuery()); } void RefactoringServer::cancel() @@ -93,16 +95,19 @@ void RefactoringServer::supersedePollEventLoop(std::function &&pollEven namespace { SourceRangesAndDiagnosticsForQueryMessage createSourceRangesAndDiagnosticsForQueryMessage( - V2::FileContainer &&fileContainer, + V2::FileContainer &&source, + std::vector &&unsaved, Utils::SmallString &&query, const std::atomic_bool &cancelWork) { ClangQuery clangQuery(std::move(query)); if (!cancelWork) { - clangQuery.addFile(fileContainer.filePath().directory(), - fileContainer.filePath().name(), - fileContainer.takeUnsavedFileContent(), - fileContainer.takeCommandLineArguments()); + clangQuery.addFile(source.filePath().directory(), + source.filePath().name(), + source.takeUnsavedFileContent(), + source.takeCommandLineArguments()); + + clangQuery.addUnsavedFiles(std::move(unsaved)); clangQuery.findLocations(); } @@ -114,27 +119,30 @@ SourceRangesAndDiagnosticsForQueryMessage createSourceRangesAndDiagnosticsForQue } void RefactoringServer::gatherSourceRangesAndDiagnosticsForQueryMessage( - std::vector &&fileContainers, + std::vector &&sources, + std::vector &&unsaved, Utils::SmallString &&query) { std::vector futures; std::size_t freeProcessors = std::thread::hardware_concurrency(); - while (!fileContainers.empty() || !futures.empty()) { + while (!sources.empty() || !futures.empty()) { --freeProcessors; - if (!fileContainers.empty()) { + if (!sources.empty()) { Future &&future = std::async(std::launch::async, createSourceRangesAndDiagnosticsForQueryMessage, - std::move(fileContainers.back()), - query.clone(), std::ref(cancelWork)); - fileContainers.pop_back(); + std::move(sources.back()), + Utils::clone(unsaved), + query.clone(), + std::ref(cancelWork)); + sources.pop_back(); futures.emplace_back(std::move(future)); } - if (freeProcessors == 0 || fileContainers.empty()) + if (freeProcessors == 0 || sources.empty()) freeProcessors += waitForNewSourceRangesAndDiagnosticsForQueryMessage(futures); } } -- cgit v1.2.1