diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -22,12 +22,19 @@ # -DCLANG_TIDY_CHECKS=Off avoids a dependency on clang-tidy, reducing rebuilds. option(CLANGD_TIDY_CHECKS "Link all clang-tidy checks into clangd" ON) +if ("${LLVM_VERSION_SUFFIX}" STREQUAL "git") + set(CLANGD_PRE_RELEASE ON) +else() + set(CLANGD_PRE_RELEASE OFF) +endif() + llvm_canonicalize_cmake_booleans( CLANGD_BUILD_XPC CLANGD_ENABLE_REMOTE ENABLE_GRPC_REFLECTION CLANGD_MALLOC_TRIM CLANGD_TIDY_CHECKS + CLANGD_PRE_RELEASE LLVM_ENABLE_ZLIB ) diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "Feature.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -17,6 +18,7 @@ #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/Version.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Token.h" #include "llvm/ADT/ArrayRef.h" @@ -918,9 +920,31 @@ // information to be worth linking. // https://clang.llvm.org/docs/DiagnosticsReference.html break; - case Diag::ClangTidy: - return {("https://clang.llvm.org/extra/clang-tidy/checks/" + Name + ".html") - .str()}; + case Diag::ClangTidy: { + StringRef Module, Check; + // This won't correctly get the module for clang-analyzer checks, but as we + // don't link in the analyzer that shouldn't be an issue. + // This would also need updating if anyone decides to create a module with a + // '-' in the name. + std::tie(Module, Check) = Name.split('-'); + if (Module.empty() || Check.empty()) + return llvm::None; +#if CLANGD_PRE_RELEASE + return ("https://clang.llvm.org/extra/clang-tidy/checks/" + Module + "/" + + Check + ".html") + .str(); +#else +#define XSTRINGIFY(X) STRINGIFY(X) +#define STRINGIFY(X) #X + return ("https://releases.llvm.org/" XSTRINGIFY( + CLANG_VERSION_MAJOR) ".0.0/tools/clang/tools/extra/docs/" + "clang-tidy/checks/" + + Module + "/" + Check + ".html") + .str(); +#undef STRINGIFY +#undef XSTRINGIFY +#endif + } case Diag::Clangd: if (Name == "unused-includes") return {"https://clangd.llvm.org/guides/include-cleaner"}; diff --git a/clang-tools-extra/clangd/Features.inc.in b/clang-tools-extra/clangd/Features.inc.in --- a/clang-tools-extra/clangd/Features.inc.in +++ b/clang-tools-extra/clangd/Features.inc.in @@ -4,3 +4,4 @@ #define ENABLE_GRPC_REFLECTION @ENABLE_GRPC_REFLECTION@ #define CLANGD_MALLOC_TRIM @CLANGD_MALLOC_TRIM@ #define CLANGD_TIDY_CHECKS @CLANGD_TIDY_CHECKS@ +#define CLANGD_PRE_RELEASE @CLANGD_PRE_RELEASE@ diff --git a/clang-tools-extra/clangd/test/diagnostics-tidy.test b/clang-tools-extra/clangd/test/diagnostics-tidy.test --- a/clang-tools-extra/clangd/test/diagnostics-tidy.test +++ b/clang-tools-extra/clangd/test/diagnostics-tidy.test @@ -1,4 +1,5 @@ # REQUIRES: clangd-tidy-checks +# REQUIRES: clangd-pre-release # RUN: clangd -lit-test -clang-tidy-checks=bugprone-sizeof-expression < %s | FileCheck -strict-whitespace %s {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}} --- @@ -9,7 +10,7 @@ # CHECK-NEXT: { # CHECK-NEXT: "code": "bugprone-sizeof-expression", # CHECK-NEXT: "codeDescription": { -# CHECK-NEXT: "href": "https://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-expression.html" +# CHECK-NEXT: "href": "https://clang.llvm.org/extra/clang-tidy/checks/bugprone/sizeof-expression.html" # CHECK-NEXT: }, # CHECK-NEXT: "message": "Suspicious usage of 'sizeof(K)'; did you mean 'K'?", # CHECK-NEXT: "range": { diff --git a/clang-tools-extra/clangd/test/lit.cfg.py b/clang-tools-extra/clangd/test/lit.cfg.py --- a/clang-tools-extra/clangd/test/lit.cfg.py +++ b/clang-tools-extra/clangd/test/lit.cfg.py @@ -34,5 +34,8 @@ if config.clangd_tidy_checks: config.available_features.add('clangd-tidy-checks') +if config.clangd_pre_release: + config.available_features.add('clangd-pre-release') + if config.have_zlib: config.available_features.add('zlib') diff --git a/clang-tools-extra/clangd/test/lit.site.cfg.py.in b/clang-tools-extra/clangd/test/lit.site.cfg.py.in --- a/clang-tools-extra/clangd/test/lit.site.cfg.py.in +++ b/clang-tools-extra/clangd/test/lit.site.cfg.py.in @@ -16,6 +16,7 @@ config.clangd_build_xpc = @CLANGD_BUILD_XPC@ config.clangd_enable_remote = @CLANGD_ENABLE_REMOTE@ config.clangd_tidy_checks = @CLANGD_TIDY_CHECKS@ +config.clangd_pre_release = @CLANGD_PRE_RELEASE@ config.have_zlib = @LLVM_ENABLE_ZLIB@ # Delegate logic to lit.cfg.py.