diff --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp --- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp +++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp @@ -740,6 +740,16 @@ SYMBOL(move, std::, ) // There are multiple headers for size_t, pick one. SYMBOL(size_t, std::, ) + // These symbols are located in `std::experimental`. + // For libstdc++, This mapping mainly fixes issue that some internal headers + // would be inserted for code completion as not all symbols from + // `std::experimental::filesystem` are in the main header, i.e., + // + // libc++ had already dropped support for experimental FS as of now. + // MSVC STL includes all experimental FS symbols in one single file. + // TODO: More TS symbols? It appears to me that only FS was not implemented + // in one single file in libstdc++. What about libc++ or MSVC? +#include "clang/Tooling/Inclusions/TsStdSymbolMap.inc" #undef SYMBOL }); StdSymbolMapping = Symbols; diff --git a/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp b/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp --- a/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp +++ b/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp @@ -62,6 +62,23 @@ EXPECT_EQ("", CI.mapHeader(File)); } +TEST(CanonicalIncludesTest, CXXSymbolsFromTS) { + CanonicalIncludes CI; + auto Language = LangOptions(); + Language.CPlusPlus = true; + CI.addSystemHeadersMapping(Language); + + EXPECT_EQ("", + CI.mapSymbol("std::experimental::filesystem::path")); + EXPECT_EQ("", + CI.mapSymbol("std::experimental::filesystem::file_type")); + EXPECT_EQ("", + CI.mapSymbol("std::experimental::filesystem::file_status")); + EXPECT_EQ("", + CI.mapSymbol( + "std::experimental::filesystem::recursive_directory_iterator")); +} + TEST(CanonicalIncludesTest, PathMapping) { auto InMemFS = llvm::makeIntrusiveRefCnt(); FileManager Files(FileSystemOptions(), InMemFS); diff --git a/clang/include/clang/Tooling/Inclusions/TsStdSymbolMap.inc b/clang/include/clang/Tooling/Inclusions/TsStdSymbolMap.inc new file mode 100644 --- /dev/null +++ b/clang/include/clang/Tooling/Inclusions/TsStdSymbolMap.inc @@ -0,0 +1,57 @@ +// FIXME: Add a parser for experimental pages to `clang/tools/include-mapping/cppreference_parser.py` + +// clang-format off +SYMBOL(absolute, std::experimental::filesystem::, ) +SYMBOL(canonical, std::experimental::filesystem::, ) +SYMBOL(copy, std::experimental::filesystem::, ) +SYMBOL(copy_file, std::experimental::filesystem::, ) +SYMBOL(copy_options, std::experimental::filesystem::, ) +SYMBOL(copy_symlink, std::experimental::filesystem::, ) +SYMBOL(create_directories, std::experimental::filesystem::, ) +SYMBOL(create_directory, std::experimental::filesystem::, ) +SYMBOL(create_directory_symlink, std::experimental::filesystem::, ) +SYMBOL(create_hard_link, std::experimental::filesystem::, ) +SYMBOL(create_symlink, std::experimental::filesystem::, ) +SYMBOL(current_path, std::experimental::filesystem::, ) +SYMBOL(directory_entry, std::experimental::filesystem::, ) +SYMBOL(directory_iterator, std::experimental::filesystem::, ) +SYMBOL(directory_options, std::experimental::filesystem::, ) +SYMBOL(equivalent, std::experimental::filesystem::, ) +SYMBOL(exists, std::experimental::filesystem::, ) +SYMBOL(file_size, std::experimental::filesystem::, ) +SYMBOL(file_status, std::experimental::filesystem::, ) +SYMBOL(file_time_type, std::experimental::filesystem::, ) +SYMBOL(file_type, std::experimental::filesystem::, ) +SYMBOL(filesystem_error, std::experimental::filesystem::, ) +SYMBOL(hard_link_count, std::experimental::filesystem::, ) +SYMBOL(is_block_file, std::experimental::filesystem::, ) +SYMBOL(is_character_file, std::experimental::filesystem::, ) +SYMBOL(is_directory, std::experimental::filesystem::, ) +SYMBOL(is_empty, std::experimental::filesystem::, ) +SYMBOL(is_fifo, std::experimental::filesystem::, ) +SYMBOL(is_other, std::experimental::filesystem::, ) +SYMBOL(is_regular_file, std::experimental::filesystem::, ) +SYMBOL(is_socket, std::experimental::filesystem::, ) +SYMBOL(is_symlink, std::experimental::filesystem::, ) +SYMBOL(last_write_time, std::experimental::filesystem::, ) +SYMBOL(path, std::experimental::filesystem::, ) +SYMBOL(perm_options, std::experimental::filesystem::, ) +SYMBOL(permissions, std::experimental::filesystem::, ) +SYMBOL(perms, std::experimental::filesystem::, ) +SYMBOL(proximate, std::experimental::filesystem::, ) +SYMBOL(read_symlink, std::experimental::filesystem::, ) +SYMBOL(recursive_directory_iterator, std::experimental::filesystem::, ) +SYMBOL(relative, std::experimental::filesystem::, ) +SYMBOL(remove, std::experimental::filesystem::, ) +SYMBOL(remove_all, std::experimental::filesystem::, ) +SYMBOL(rename, std::experimental::filesystem::, ) +SYMBOL(resize_file, std::experimental::filesystem::, ) +SYMBOL(space, std::experimental::filesystem::, ) +SYMBOL(space_info, std::experimental::filesystem::, ) +SYMBOL(status, std::experimental::filesystem::, ) +SYMBOL(status_known, std::experimental::filesystem::, ) +SYMBOL(symlink_status, std::experimental::filesystem::, ) +SYMBOL(temp_directory_path, std::experimental::filesystem::, ) +SYMBOL(u8path, std::experimental::filesystem::, ) +SYMBOL(weakly_canonical, std::experimental::filesystem::, ) +// clang-format on