Skip to content

Commit

Permalink
[clangd] Cleanup of readability-identifier-naming
Browse files Browse the repository at this point in the history
Auto-generated patch based on clang-tidy readability-identifier-naming.
Only some manual cleanup for `extern "C"` declarations and a GTest change was required.

I'm not sure if this cleanup is actually very useful. It cleans up clang-tidy findings to the number of warnings from clang-tidy should be lower.  Since it was easy to do and required only little cleanup I thought I'd upload it for discussion.

One pattern that keeps recurring: Test **matchers** are also supposed to start with a lowercase letter as per LLVM convention. However GTest naming convention for matchers start with upper case. I would propose to keep stay consistent with the GTest convention there. However that would imply a lot of `//NOLINT` throughout these files.

To re-product this patch run:
```
run-clang-tidy -checks="-*,readability-identifier-naming" -fix -format ./clang-tools-extra/clangd
```

To convert the macro names, I was using this script with some manual cleanup afterwards:
https://gist.github.com/ChristianKuehnel/a01cc4362b07c58281554ab46235a077

Differential Revision: https://reviews.llvm.org/D115634
  • Loading branch information
ChristianKuehnel committed Feb 1, 2022
1 parent fa7834a commit 8edfc2f
Show file tree
Hide file tree
Showing 40 changed files with 1,595 additions and 1,586 deletions.
4 changes: 4 additions & 0 deletions .clang-tidy
Expand Up @@ -6,6 +6,10 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
# Exclude from scanning as this is an exported symbol used for fuzzing
# throughout the code base.
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: "LLVMFuzzerTestOneInput"
- key: readability-identifier-naming.MemberCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Expand Up @@ -71,8 +71,8 @@ llvm::Optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
return llvm::None;
}

const llvm::StringLiteral APPLY_FIX_COMMAND = "clangd.applyFix";
const llvm::StringLiteral APPLY_TWEAK_COMMAND = "clangd.applyTweak";
const llvm::StringLiteral ApplyFixCommand = "clangd.applyFix";
const llvm::StringLiteral ApplyTweakCommand = "clangd.applyTweak";

/// Transforms a tweak into a code action that would apply it if executed.
/// EXPECTS: T.prepare() was called and returned true.
Expand All @@ -88,7 +88,7 @@ CodeAction toCodeAction(const ClangdServer::TweakRef &T, const URIForFile &File,
// directly.
CA.command.emplace();
CA.command->title = T.Title;
CA.command->command = std::string(APPLY_TWEAK_COMMAND);
CA.command->command = std::string(ApplyTweakCommand);
TweakArgs Args;
Args.file = File;
Args.tweakID = T.ID;
Expand Down Expand Up @@ -950,7 +950,7 @@ static llvm::Optional<Command> asCommand(const CodeAction &Action) {
if (Action.command) {
Cmd = *Action.command;
} else if (Action.edit) {
Cmd.command = std::string(APPLY_FIX_COMMAND);
Cmd.command = std::string(ApplyFixCommand);
Cmd.argument = *Action.edit;
} else {
return None;
Expand Down Expand Up @@ -1495,8 +1495,8 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
Bind.method("$/memoryUsage", this, &ClangdLSPServer::onMemoryUsage);
if (Opts.FoldingRanges)
Bind.method("textDocument/foldingRange", this, &ClangdLSPServer::onFoldingRange);
Bind.command(APPLY_FIX_COMMAND, this, &ClangdLSPServer::onCommandApplyEdit);
Bind.command(APPLY_TWEAK_COMMAND, this, &ClangdLSPServer::onCommandApplyTweak);
Bind.command(ApplyFixCommand, this, &ClangdLSPServer::onCommandApplyEdit);
Bind.command(ApplyTweakCommand, this, &ClangdLSPServer::onCommandApplyTweak);

ApplyWorkspaceEdit = Bind.outgoingMethod("workspace/applyEdit");
PublishDiagnostics = Bind.outgoingNotification("textDocument/publishDiagnostics");
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/SourceCode.cpp
Expand Up @@ -1177,10 +1177,10 @@ bool isProtoFile(SourceLocation Loc, const SourceManager &SM) {
return false;
auto FID = SM.getFileID(Loc);
// All proto generated headers should start with this line.
static const char *PROTO_HEADER_COMMENT =
static const char *ProtoHeaderComment =
"// Generated by the protocol buffer compiler. DO NOT EDIT!";
// Double check that this is an actual protobuf header.
return SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT);
return SM.getBufferData(FID).startswith(ProtoHeaderComment);
}

namespace {
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/TUScheduler.cpp
Expand Up @@ -100,10 +100,10 @@ namespace {
class ASTWorker;
} // namespace

static clang::clangd::Key<std::string> kFileBeingProcessed;
static clang::clangd::Key<std::string> FileBeingProcessed;

llvm::Optional<llvm::StringRef> TUScheduler::getFileBeingProcessedInContext() {
if (auto *File = Context::current().get(kFileBeingProcessed))
if (auto *File = Context::current().get(FileBeingProcessed))
return llvm::StringRef(*File);
return None;
}
Expand Down Expand Up @@ -1228,7 +1228,7 @@ void ASTWorker::startTask(llvm::StringRef Name,
}

// Allow this request to be cancelled if invalidated.
Context Ctx = Context::current().derive(kFileBeingProcessed, FileName);
Context Ctx = Context::current().derive(FileBeingProcessed, FileName);
Canceler Invalidate = nullptr;
if (Invalidation) {
WithContext WC(std::move(Ctx));
Expand Down Expand Up @@ -1656,7 +1656,7 @@ void TUScheduler::runWithPreamble(llvm::StringRef Name, PathRef File,
auto Task = [Worker, Consistency, Name = Name.str(), File = File.str(),
Contents = It->second->Contents,
Command = Worker->getCurrentCompileCommand(),
Ctx = Context::current().derive(kFileBeingProcessed,
Ctx = Context::current().derive(FileBeingProcessed,
std::string(File)),
Action = std::move(Action), this]() mutable {
ThreadCrashReporter ScopedReporter([&Name, &Contents, &Command]() {
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Expand Up @@ -1861,7 +1861,9 @@ static QualType typeForNode(const SelectionTree::Node *N) {
QualType VisitCXXThrowExpr(const CXXThrowExpr *S) {
return S->getSubExpr()->getType();
}
QualType VisitCoyieldStmt(const CoyieldExpr *S) {
// FIXME(sammccall): this should be VisitCoyieldExpr
// see https://reviews.llvm.org/D115634
QualType visitCoyieldStmt(const CoyieldExpr *S) {
return type(S->getOperand());
}
// Treat a designated initializer like a reference to the field.
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp
Expand Up @@ -73,29 +73,29 @@ std::vector<FuzzyFindRequest> extractQueriesFromLogs() {
return Requests;
}

static void MemQueries(benchmark::State &State) {
static void memQueries(benchmark::State &State) {
const auto Mem = buildMem();
const auto Requests = extractQueriesFromLogs();
for (auto _ : State)
for (const auto &Request : Requests)
Mem->fuzzyFind(Request, [](const Symbol &S) {});
}
BENCHMARK(MemQueries);
BENCHMARK(memQueries);

static void DexQueries(benchmark::State &State) {
static void dexQueries(benchmark::State &State) {
const auto Dex = buildDex();
const auto Requests = extractQueriesFromLogs();
for (auto _ : State)
for (const auto &Request : Requests)
Dex->fuzzyFind(Request, [](const Symbol &S) {});
}
BENCHMARK(DexQueries);
BENCHMARK(dexQueries);

static void DexBuild(benchmark::State &State) {
static void dexBuild(benchmark::State &State) {
for (auto _ : State)
buildDex();
}
BENCHMARK(DexBuild);
BENCHMARK(dexBuild);

} // namespace
} // namespace clangd
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp
Expand Up @@ -19,12 +19,12 @@

using namespace clang::clangd;

extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
if (size == 0)
extern "C" int LLVMFuzzerTestOneInput(uint8_t *Data, size_t Size) {
if (Size == 0)
return 0;

// fmemopen isn't portable, but I think we only run the fuzzer on Linux.
std::FILE *In = fmemopen(data, size, "r");
std::FILE *In = fmemopen(Data, Size, "r");
auto Transport = newJSONTransport(In, llvm::nulls(),
/*InMirror=*/nullptr, /*Pretty=*/false,
/*Style=*/JSONStreamStyle::Delimited);
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/index/YAMLSerialization.cpp
Expand Up @@ -161,19 +161,19 @@ template <> struct MappingTraits<SymbolLocation> {
};

template <> struct MappingTraits<SymbolInfo> {
static void mapping(IO &io, SymbolInfo &SymInfo) {
static void mapping(IO &IO, SymbolInfo &SymInfo) {
// FIXME: expose other fields?
io.mapRequired("Kind", SymInfo.Kind);
io.mapRequired("Lang", SymInfo.Lang);
IO.mapRequired("Kind", SymInfo.Kind);
IO.mapRequired("Lang", SymInfo.Lang);
}
};

template <>
struct MappingTraits<clang::clangd::Symbol::IncludeHeaderWithReferences> {
static void mapping(IO &io,
static void mapping(IO &IO,
clang::clangd::Symbol::IncludeHeaderWithReferences &Inc) {
io.mapRequired("Header", Inc.IncludeHeader);
io.mapRequired("References", Inc.References);
IO.mapRequired("Header", Inc.IncludeHeader);
IO.mapRequired("References", Inc.References);
}
};

Expand Down

0 comments on commit 8edfc2f

Please sign in to comment.