Skip to content

Commit

Permalink
Merged master:5f8b8d28204 into amd-gfx:68f7718e978
Browse files Browse the repository at this point in the history
Local branch amd-gfx 68f7718 [AMDGPU] Extend the pre-gfx8 vccz bug workaround
Remote branch master 5f8b8d2 [openmp] Recognise ARMv7ve machine arch.
  • Loading branch information
Sw authored and Sw committed Nov 26, 2019
2 parents 68f7718 + 5f8b8d2 commit 36c2fd7
Show file tree
Hide file tree
Showing 199 changed files with 9,172 additions and 3,328 deletions.
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ std::string getQualification(ASTContext &Context,
const DeclContext *DestContext,
SourceLocation InsertionPoint, const NamedDecl *ND,
llvm::ArrayRef<std::string> VisibleNamespaces) {
for (llvm::StringRef NS : VisibleNamespaces)
for (llvm::StringRef NS : VisibleNamespaces) {
assert(NS.endswith("::"));
(void)NS;
}
return getQualification(
Context, DestContext, ND->getDeclContext(),
[&](NestedNameSpecifier *NNS) {
Expand Down
36 changes: 21 additions & 15 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ std::vector<std::vector<std::string>> buildHighlightScopeLookupTable() {
return LookupTable;
}

// Makes sure edits in \p E are applicable to latest file contents reported by
// Makes sure edits in \p FE are applicable to latest file contents reported by
// editor. If not generates an error message containing information about files
// that needs to be saved.
llvm::Error validateEdits(const DraftStore &DraftMgr, const Tweak::Effect &E) {
llvm::Error validateEdits(const DraftStore &DraftMgr, const FileEdits &FE) {
size_t InvalidFileCount = 0;
llvm::StringRef LastInvalidFile;
for (const auto &It : E.ApplyEdits) {
for (const auto &It : FE) {
if (auto Draft = DraftMgr.getDraft(It.first())) {
// If the file is open in user's editor, make sure the version we
// saw and current version are compatible as this is the text that
Expand Down Expand Up @@ -704,7 +704,7 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
if (R->ApplyEdits.empty())
return Reply("Tweak applied.");

if (auto Err = validateEdits(DraftMgr, *R))
if (auto Err = validateEdits(DraftMgr, R->ApplyEdits))
return Reply(std::move(Err));

WorkspaceEdit WE;
Expand Down Expand Up @@ -758,17 +758,23 @@ void ClangdLSPServer::onRename(const RenameParams &Params,
if (!Code)
return Reply(llvm::make_error<LSPError>(
"onRename called for non-added file", ErrorCode::InvalidParams));

Server->rename(File, Params.position, Params.newName, /*WantFormat=*/true,
[File, Code, Params, Reply = std::move(Reply)](
llvm::Expected<std::vector<TextEdit>> Edits) mutable {
if (!Edits)
return Reply(Edits.takeError());

WorkspaceEdit WE;
WE.changes = {{Params.textDocument.uri.uri(), *Edits}};
Reply(WE);
});
Server->rename(
File, Params.position, Params.newName,
/*WantFormat=*/true,
[File, Params, Reply = std::move(Reply),
this](llvm::Expected<FileEdits> Edits) mutable {
if (!Edits)
return Reply(Edits.takeError());
if (auto Err = validateEdits(DraftMgr, *Edits))
return Reply(std::move(Err));
WorkspaceEdit Result;
Result.changes.emplace();
for (const auto &Rep : *Edits) {
(*Result.changes)[URI::createFile(Rep.first()).toString()] =
Rep.second.asTextEdits();
}
Reply(Result);
});
}

void ClangdLSPServer::onDocumentDidClose(
Expand Down
71 changes: 43 additions & 28 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
: nullptr),
GetClangTidyOptions(Opts.GetClangTidyOptions),
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
TweakFilter(Opts.TweakFilter), WorkspaceRoot(Opts.WorkspaceRoot),
CrossFileRename(Opts.CrossFileRename), TweakFilter(Opts.TweakFilter),
WorkspaceRoot(Opts.WorkspaceRoot),
// Pass a callback into `WorkScheduler` to extract symbols from a newly
// parsed file and rebuild the file index synchronously each time an AST
// is parsed.
Expand Down Expand Up @@ -308,54 +309,68 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
if (!InpAST)
return CB(InpAST.takeError());
auto &AST = InpAST->AST;
// Performing the rename isn't substantially more expensive than doing an
// AST-based check, so we just rename and throw away the results. We may
// have to revisit this when we support cross-file rename.
auto Changes = renameWithinFile(AST, File, Pos, "dummy", Index);
const auto &SM = AST.getSourceManager();
SourceLocation Loc =
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts()));
auto Range = getTokenRange(SM, AST.getASTContext().getLangOpts(), Loc);
if (!Range)
return CB(llvm::None); // "rename" is not valid at the position.

if (CrossFileRename)
// FIXME: we now assume cross-file rename always succeeds, revisit this.
return CB(*Range);

// Performing the local rename isn't substantially more expensive than
// doing an AST-based check, so we just rename and throw away the results.
auto Changes = clangd::rename({Pos, "dummy", AST, File, Index,
/*AllowCrossFile=*/false,
/*GetDirtyBuffer=*/nullptr});
if (!Changes) {
// LSP says to return null on failure, but that will result in a generic
// failure message. If we send an LSP error response, clients can surface
// the message to users (VSCode does).
return CB(Changes.takeError());
}
SourceLocation Loc = getBeginningOfIdentifier(
Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts());
if (auto Range = getTokenRange(AST.getSourceManager(),
AST.getASTContext().getLangOpts(), Loc))
return CB(*Range);
// Return null if the "rename" is not valid at the position.
CB(llvm::None);
return CB(*Range);
};
WorkScheduler.runWithAST("PrepareRename", File, std::move(Action));
}

void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
bool WantFormat, Callback<std::vector<TextEdit>> CB) {
bool WantFormat, Callback<FileEdits> CB) {
// A snapshot of all file dirty buffers.
llvm::StringMap<std::string> Snapshot = WorkScheduler.getAllFileContents();
auto Action = [File = File.str(), NewName = NewName.str(), Pos, WantFormat,
CB = std::move(CB),
CB = std::move(CB), Snapshot = std::move(Snapshot),
this](llvm::Expected<InputsAndAST> InpAST) mutable {
if (!InpAST)
return CB(InpAST.takeError());
auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index);
if (!Changes)
return CB(Changes.takeError());
auto GetDirtyBuffer =
[&Snapshot](PathRef AbsPath) -> llvm::Optional<std::string> {
auto It = Snapshot.find(AbsPath);
if (It == Snapshot.end())
return llvm::None;
return It->second;
};
auto Edits = clangd::rename({Pos, NewName, InpAST->AST, File, Index,
CrossFileRename, GetDirtyBuffer});
if (!Edits)
return CB(Edits.takeError());

if (WantFormat) {
auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
InpAST->Inputs.FS.get());
if (auto Formatted =
cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
*Changes = std::move(*Formatted);
else
elog("Failed to format replacements: {0}", Formatted.takeError());
}
llvm::Error Err = llvm::Error::success();
for (auto &E : *Edits)
Err =
llvm::joinErrors(reformatEdit(E.getValue(), Style), std::move(Err));

std::vector<TextEdit> Edits;
for (const auto &Rep : *Changes)
Edits.push_back(replacementToEdit(InpAST->Inputs.Contents, Rep));
return CB(std::move(Edits));
if (Err)
return CB(std::move(Err));
}
return CB(std::move(*Edits));
};

WorkScheduler.runWithAST("Rename", File, std::move(Action));
}

Expand Down
8 changes: 7 additions & 1 deletion clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "index/Background.h"
#include "index/FileIndex.h"
#include "index/Index.h"
#include "refactor/Rename.h"
#include "refactor/Tweak.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Core/Replacement.h"
Expand Down Expand Up @@ -133,6 +134,9 @@ class ClangdServer {
/// Enable semantic highlighting features.
bool SemanticHighlighting = false;

/// Enable cross-file rename feature.
bool CrossFileRename = false;

/// Returns true if the tweak should be enabled.
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
return !T.hidden(); // only enable non-hidden tweaks.
Expand Down Expand Up @@ -252,7 +256,7 @@ class ClangdServer {
/// embedders could use this method to get all occurrences of the symbol (e.g.
/// highlighting them in prepare stage).
void rename(PathRef File, Position Pos, llvm::StringRef NewName,
bool WantFormat, Callback<std::vector<TextEdit>> CB);
bool WantFormat, Callback<FileEdits> CB);

struct TweakRef {
std::string ID; /// ID to pass for applyTweak.
Expand Down Expand Up @@ -327,6 +331,8 @@ class ClangdServer {
// can be caused by missing includes (e.g. member access in incomplete type).
bool SuggestMissingIncludes = false;

bool CrossFileRename = false;

std::function<bool(const Tweak &)> TweakFilter;

// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/SourceCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ struct Edit {
/// Checks whether the Replacements are applicable to given Code.
bool canApplyTo(llvm::StringRef Code) const;
};
/// A mapping from absolute file path (the one used for accessing the underlying
/// VFS) to edits.
using FileEdits = llvm::StringMap<Edit>;

/// Formats the edits and code around it according to Style. Changes
/// Replacements to formatted ones if succeeds.
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,13 @@ llvm::StringRef TUScheduler::getContents(PathRef File) const {
return It->second->Contents;
}

llvm::StringMap<std::string> TUScheduler::getAllFileContents() const {
llvm::StringMap<std::string> Results;
for (auto &It : Files)
Results.try_emplace(It.getKey(), It.getValue()->Contents);
return Results;
}

void TUScheduler::run(llvm::StringRef Name,
llvm::unique_function<void()> Action) {
if (!PreambleTasks)
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/TUScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class TUScheduler {
/// The returned StringRef may be invalidated by any write to TUScheduler.
llvm::StringRef getContents(PathRef File) const;

/// Returns a snapshot of all file buffer contents, per last update().
llvm::StringMap<std::string> getAllFileContents() const;

/// Schedule an async task with no dependencies.
void run(llvm::StringRef Name, llvm::unique_function<void()> Action);

Expand Down
Loading

0 comments on commit 36c2fd7

Please sign in to comment.