diff --git a/.gitignore b/.gitignore index 4ba98ad5..a0783c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,4 @@ -.cquery_cached_index -.DS_Store -.lock-waf* -.vs -.vscode/ -.vscode/.ropeproject -.waf* -*.cquery -*.sln -*.swp -*.vcxproj -*.vcxproj.filters -*.vcxproj.user -**/*.pyc +.* build -cquery_diagnostics.log -cquery_log.txt -Debug -e2e_cache -foo -libcxx -vscode-extension.vsix -waf-* -waf2* -waf3* -x64 +debug +release diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ed816b..90c13cc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.1) -project(cquery LANGUAGES CXX) +project(ccls LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) include(DefaultCMakeBuildType) @@ -8,11 +8,11 @@ include(DownloadAndExtractLLVM) set(CLANG_VERSION 6.0.0 CACHE STRING "Downloaded Clang version (6.0.0)") option(SYSTEM_CLANG "Use system Clang instead of downloading Clang" OFF) option(ASAN "Compile with address sanitizers" OFF) -option(CLANG_CXX "Build with Clang C++ api required by some cquery \ +option(CLANG_CXX "Build with Clang C++ api required by some ccls \ features (warning: not available in LLVM Windows downloads)" OFF) # Sources for the executable are specified at end of CMakeLists.txt -add_executable(cquery "") +add_executable(ccls "") ### Compile options @@ -25,16 +25,16 @@ add_executable(cquery "") # release: -O3 -DNDEBUG # Enable C++14 (Required) -set_property(TARGET cquery PROPERTY CXX_STANDARD 14) -set_property(TARGET cquery PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET ccls PROPERTY CXX_STANDARD 17) +set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON) # Disable gnu extensions except for Cygwin which needs them to build properly if(NOT CYGWIN) - set_property(TARGET cquery PROPERTY CXX_EXTENSIONS OFF) + set_property(TARGET ccls PROPERTY CXX_EXTENSIONS OFF) endif() if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) # Common MSVC/Clang(Windows) options - target_compile_options(cquery PRIVATE + target_compile_options(ccls PRIVATE /nologo /EHsc /W3 # roughly -Wall @@ -49,17 +49,17 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) ) else() # Common GCC/Clang(Linux) options - target_compile_options(cquery PRIVATE + target_compile_options(ccls PRIVATE -Wall -Wno-sign-compare ) if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) - target_compile_options(cquery PRIVATE -Wno-return-type -Wno-unused-result) + target_compile_options(ccls PRIVATE -Wno-return-type -Wno-unused-result) endif() if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) - target_compile_options(cquery PRIVATE + target_compile_options(ccls PRIVATE $<$:-fno-limit-debug-info>) endif() @@ -67,13 +67,13 @@ else() # -Wno-comment: include/clang/Format/Format.h error: multi-line comment # -fno-rtti: # Without -fno-rtti, some Clang C++ functions may report # `undefined references to typeinfo` - target_compile_options(cquery PRIVATE -Wno-comment -fno-rtti) + target_compile_options(ccls PRIVATE -Wno-comment -fno-rtti) endif() if(ASAN) - target_compile_options(cquery PRIVATE -fsanitize=address,undefined) + target_compile_options(ccls PRIVATE -fsanitize=address,undefined) # target_link_libraries also takes linker flags - target_link_libraries(cquery PRIVATE -fsanitize=address,undefined) + target_link_libraries(ccls PRIVATE -fsanitize=address,undefined) endif() endif() @@ -89,50 +89,50 @@ endif() # See cmake/FindClang.cmake find_package(Clang REQUIRED) -target_link_libraries(cquery PRIVATE Clang::Clang) +target_link_libraries(ccls PRIVATE Clang::Clang) # Enable threading support set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -target_link_libraries(cquery PRIVATE Threads::Threads) +target_link_libraries(ccls PRIVATE Threads::Threads) if(${CMAKE_SYSTEM_NAME} STREQUAL Linux) # loguru calls dladdr - target_link_libraries(cquery PRIVATE ${CMAKE_DL_LIBS}) + target_link_libraries(ccls PRIVATE ${CMAKE_DL_LIBS}) elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) # loguru::stacktrace_as_stdstring calls backtrace_symbols # sparsepp/spp_memory.h uses libkvm # src/platform_posix.cc uses libthr find_package(Backtrace REQUIRED) - target_link_libraries(cquery PRIVATE ${Backtrace_LIBRARIES} kvm thr) + target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES} kvm thr) elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) # sparsepp/spp_memory.h uses LibPsapi - target_link_libraries(cquery PRIVATE Psapi) + target_link_libraries(ccls PRIVATE Psapi) endif() if(CLANG_CXX) # Clang C++ api uses ncurses find_package(Curses REQUIRED) - target_link_libraries(cquery PRIVATE ${CURSES_LIBRARIES}) + target_link_libraries(ccls PRIVATE ${CURSES_LIBRARIES}) endif() ### Definitions -target_compile_definitions(cquery PRIVATE +target_compile_definitions(ccls PRIVATE LOGURU_WITH_STREAMS=1 LOGURU_FILENAME_WIDTH=18 LOGURU_THREADNAME_WIDTH=13 DEFAULT_RESOURCE_DIRECTORY="${Clang_RESOURCE_DIR}") if(CLANG_CXX) - target_compile_definitions(cquery PRIVATE USE_CLANG_CXX=1 LOGURU_RTTI=0) + target_compile_definitions(ccls PRIVATE USE_CLANG_CXX=1 LOGURU_RTTI=0) endif() ### Includes -target_include_directories(cquery PRIVATE +target_include_directories(ccls PRIVATE src third_party third_party/rapidjson/include @@ -143,17 +143,17 @@ target_include_directories(cquery PRIVATE ### Install -install(TARGETS cquery RUNTIME DESTINATION bin) +install(TARGETS ccls RUNTIME DESTINATION bin) # We don't need to install libclang on Windows if we are using downloaded LLVM # since libclang is distributed as a static library on Windows if(NOT SYSTEM_CLANG AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows) if(${CMAKE_SYSTEM_NAME} MATCHES Linux|FreeBSD) - set_property(TARGET cquery APPEND PROPERTY + set_property(TARGET ccls APPEND PROPERTY INSTALL_RPATH $ORIGIN/../lib) elseif(${CMAKE_SYSTEM_NAME} STREQUAL Darwin) - set_property(TARGET cquery APPEND PROPERTY + set_property(TARGET ccls APPEND PROPERTY INSTALL_RPATH @loader_path/../lib) endif() @@ -164,9 +164,9 @@ endif() ### Sources -target_sources(cquery PRIVATE third_party/siphash.cc) +target_sources(ccls PRIVATE third_party/siphash.cc) -target_sources(cquery PRIVATE +target_sources(ccls PRIVATE src/cache_manager.cc src/clang_complete.cc src/clang_cursor.cc @@ -215,24 +215,23 @@ target_sources(cquery PRIVATE src/work_thread.cc src/working_files.cc) -target_sources(cquery PRIVATE - src/messages/cquery_base.cc - src/messages/cquery_call_hierarchy.cc - src/messages/cquery_callers.cc - src/messages/cquery_derived.cc - src/messages/cquery_did_view.cc - src/messages/cquery_file_info.cc - src/messages/cquery_freshen_index.cc - src/messages/cquery_index_file.cc - src/messages/cquery_inheritance_hierarchy.cc - src/messages/cquery_member_hierarchy.cc - src/messages/cquery_random.cc - src/messages/cquery_vars.cc - src/messages/cquery_wait.cc +target_sources(ccls PRIVATE + src/messages/ccls_base.cc + src/messages/ccls_call_hierarchy.cc + src/messages/ccls_callers.cc + src/messages/ccls_derived.cc + src/messages/ccls_did_view.cc + src/messages/ccls_file_info.cc + src/messages/ccls_freshen_index.cc + src/messages/ccls_index_file.cc + src/messages/ccls_inheritance_hierarchy.cc + src/messages/ccls_member_hierarchy.cc + src/messages/ccls_random.cc + src/messages/ccls_vars.cc + src/messages/ccls_wait.cc src/messages/exit.cc src/messages/initialize.cc src/messages/shutdown.cc - src/messages/text_document_code_action.cc src/messages/text_document_code_lens.cc src/messages/text_document_completion.cc src/messages/text_document_definition.cc @@ -252,4 +251,5 @@ target_sources(cquery PRIVATE src/messages/text_document_type_definition.cc src/messages/workspace_did_change_configuration.cc src/messages/workspace_did_change_watched_files.cc - src/messages/workspace_symbol.cc) + src/messages/workspace_symbol.cc + ) diff --git a/README.md b/README.md index 5a066814..9f29f1b2 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,6 @@ -[![Join the chat at https://gitter.im/cquery-project/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cquery-project/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +# ccls -# cquery - -cquery is a highly-scalable, low-latency language server for C/C++/Objective-C. It is tested -and designed for large code bases like -[Chromium](https://chromium.googlesource.com/chromium/src/). cquery provides -accurate and fast semantic analysis without interrupting workflow. - -![Demo](https://ptpb.pw/GlSQ.png?raw=true) - -cquery implements almost the entire language server protocol and provides -some extra features to boot: +ccls is a fork of cquery, a C/C++/Objective-C language server. * code completion (with both signature help and snippets) * finding [definition](src/messages/text_document_definition.cc)/[references](src/messages/text_document_references.cc) @@ -26,19 +16,7 @@ some extra features to boot: * auto-implement functions without a definition * semantic highlighting, including support for [rainbow semantic highlighting](https://medium.com/@evnbr/coding-in-color-3a6db2743a1e) -# >>> [Getting started](https://github.com/jacobdufault/cquery/wiki/Getting-started) (CLICK HERE) <<< - - - Packaging status - - -# Limitations - -cquery is able to respond to queries quickly because it caches a huge amount of -information. When a request comes in, cquery just looks it up in the cache -without running many computations. As a result, there's a large memory overhead. -For example, a full index of Chrome will take about 10gb of memory. If you -exclude v8, webkit, and third_party, it goes down to about 6.5gb. +# >>> [Getting started](https://github.com/MaskRay/ccls/wiki/Getting-started) (CLICK HERE) <<< # License diff --git a/index_tests/_empty_test.cc b/index_tests/_empty_test.cc new file mode 100644 index 00000000..237e1553 --- /dev/null +++ b/index_tests/_empty_test.cc @@ -0,0 +1,10 @@ +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/class_forward_declaration.cc b/index_tests/class_forward_declaration.cc new file mode 100644 index 00000000..e2194d75 --- /dev/null +++ b/index_tests/class_forward_declaration.cc @@ -0,0 +1,31 @@ +class Foo; +class Foo; +class Foo {}; +class Foo; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": ["1:7-1:10|-1|1|1", "2:7-2:10|-1|1|1", "4:7-4:10|-1|1|1"], + "spell": "3:7-3:10|-1|1|2", + "extent": "3:1-3:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/constructors/constructor.cc b/index_tests/constructors/constructor.cc new file mode 100644 index 00000000..82c7469f --- /dev/null +++ b/index_tests/constructors/constructor.cc @@ -0,0 +1,92 @@ +class Foo { +public: + Foo() {} +}; + +void foo() { + Foo f; + Foo* f2 = new Foo(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": ["3:3-3:6|-1|1|4"], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [0, 1], + "uses": ["3:3-3:6|0|2|4", "7:3-7:6|-1|1|4", "8:3-8:6|-1|1|4", "8:17-8:20|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 3385168158331140247, + "detailed_name": "void Foo::Foo()", + "short_name": "Foo", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "3:3-3:6|0|2|2", + "extent": "3:3-3:11|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["7:7-7:8|1|3|288", "8:17-8:20|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "6:6-6:9|-1|1|2", + "extent": "6:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": ["7:7-7:8|0|3|288", "7:7-7:8|0|3|288", "8:17-8:20|0|3|32", "8:17-8:20|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 18410644574635149442, + "detailed_name": "Foo f", + "short_name": "f", + "declarations": [], + "spell": "7:7-7:8|1|3|2", + "extent": "7:3-7:8|1|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 11468802633764653592, + "detailed_name": "Foo *f2", + "short_name": "f2", + "hover": "Foo *f2 = new Foo()", + "declarations": [], + "spell": "8:8-8:10|1|3|2", + "extent": "8:3-8:22|1|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/constructors/destructor.cc b/index_tests/constructors/destructor.cc new file mode 100644 index 00000000..acfa71a3 --- /dev/null +++ b/index_tests/constructors/destructor.cc @@ -0,0 +1,100 @@ +class Foo { +public: + Foo() {} + ~Foo() {}; +}; + +void foo() { + Foo f; +} + +// TODO: Support destructors (notice how the dtor has no usages listed). +// - check if variable is a pointer. if so, do *not* insert dtor +// - check if variable is normal type. if so, insert dtor +// - scan for statements that look like dtors in function def handler +// - figure out some way to support w/ unique_ptrs? +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": ["3:3-3:6|-1|1|4", "4:4-4:7|-1|1|4"], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0, 1], + "vars": [], + "instances": [0], + "uses": ["3:3-3:6|0|2|4", "8:3-8:6|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 3385168158331140247, + "detailed_name": "void Foo::Foo()", + "short_name": "Foo", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "3:3-3:6|0|2|2", + "extent": "3:3-3:11|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:7-8:8|2|3|288"], + "callees": [] + }, { + "id": 1, + "usr": 7440261702884428359, + "detailed_name": "void Foo::~Foo() noexcept", + "short_name": "~Foo", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "4:3-4:7|0|2|2", + "extent": "4:3-4:12|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "7:6-7:9|-1|1|2", + "extent": "7:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["8:7-8:8|0|3|288", "8:7-8:8|0|3|288"] + }], + "vars": [{ + "id": 0, + "usr": 9954632887635271906, + "detailed_name": "Foo f", + "short_name": "f", + "declarations": [], + "spell": "8:7-8:8|2|3|2", + "extent": "8:3-8:8|2|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/constructors/implicit_constructor.cc b/index_tests/constructors/implicit_constructor.cc new file mode 100644 index 00000000..fd696780 --- /dev/null +++ b/index_tests/constructors/implicit_constructor.cc @@ -0,0 +1,90 @@ +struct Type { + Type() {} +}; + +void Make() { + Type foo0; + auto foo1 = Type(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13487927231218873822, + "detailed_name": "Type", + "short_name": "Type", + "kind": 23, + "declarations": ["2:3-2:7|-1|1|4"], + "spell": "1:8-1:12|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [0, 1], + "uses": ["2:3-2:7|0|2|4", "6:3-6:7|-1|1|4", "7:15-7:19|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 10530961286677896857, + "detailed_name": "void Type::Type()", + "short_name": "Type", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "2:3-2:7|0|2|2", + "extent": "2:3-2:12|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:8-6:12|1|3|288", "7:15-7:19|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 3957104924306079513, + "detailed_name": "void Make()", + "short_name": "Make", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:10|-1|1|2", + "extent": "5:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": ["6:8-6:12|0|3|288", "6:8-6:12|0|3|288", "7:15-7:19|0|3|32", "7:15-7:19|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 17348451315735351657, + "detailed_name": "Type foo0", + "short_name": "foo0", + "declarations": [], + "spell": "6:8-6:12|1|3|2", + "extent": "6:3-6:12|1|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 3757978174345638825, + "detailed_name": "Type foo1", + "short_name": "foo1", + "declarations": [], + "spell": "7:8-7:12|1|3|2", + "extent": "7:3-7:21|1|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/constructors/invalid_reference.cc b/index_tests/constructors/invalid_reference.cc new file mode 100644 index 00000000..31bacba3 --- /dev/null +++ b/index_tests/constructors/invalid_reference.cc @@ -0,0 +1,51 @@ +struct Foo {}; + +template +Foo::Foo() {} + +/* +EXTRA_FLAGS: +-fms-compatibility +-fdelayed-template-parsing + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["4:6-4:9|-1|1|4"], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-1:14|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["4:6-4:9|-1|1|4", "4:1-4:4|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 17319723337446061757, + "detailed_name": "void Foo::Foo()", + "short_name": "Foo", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "4:6-4:9|0|2|2", + "extent": "4:1-4:11|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/constructors/make_functions.cc b/index_tests/constructors/make_functions.cc new file mode 100644 index 00000000..f044001a --- /dev/null +++ b/index_tests/constructors/make_functions.cc @@ -0,0 +1,353 @@ +#include "make_functions.h" + +template +T* MakeUnique(Args&&... args) { + return nullptr; +} + +template +T* maKE_NoRefs(Args... args) { + return nullptr; +} + +void caller22() { + MakeUnique(); + MakeUnique(1); + MakeUnique(1, new Bar(), nullptr); + maKE_NoRefs(1, new Bar(), nullptr); +} + +// TODO: Eliminate the extra entries in the "types" array here. They come from +// the template function definitions. + +// Foobar is defined in a separate file to ensure that we can attribute +// MakeUnique calls across translation units. + +/* +OUTPUT: make_functions.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 12993848456528750350, + "detailed_name": "Bar", + "short_name": "Bar", + "kind": 23, + "declarations": [], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-1:14|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:17-7:20|-1|1|4", "8:15-8:18|-1|1|4"] + }, { + "id": 1, + "usr": 14935975554338052500, + "detailed_name": "Foobar", + "short_name": "Foobar", + "kind": 5, + "declarations": ["5:3-5:9|-1|1|4", "6:3-6:9|-1|1|4", "7:3-7:9|-1|1|4", "8:3-8:9|-1|1|4"], + "spell": "3:7-3:13|-1|1|2", + "extent": "3:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0, 1, 2, 3], + "vars": [], + "instances": [], + "uses": ["5:3-5:9|1|2|4", "6:3-6:9|1|2|4", "7:3-7:9|1|2|4", "8:3-8:9|1|2|4"] + }], + "funcs": [{ + "id": 0, + "usr": 13131778807733950299, + "detailed_name": "void Foobar::Foobar()", + "short_name": "Foobar", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "5:3-5:9|1|2|2", + "extent": "5:3-5:14|1|2|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 13028995015627606181, + "detailed_name": "void Foobar::Foobar(int)", + "short_name": "Foobar", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "6:3-6:9|1|2|2", + "extent": "6:3-6:17|1|2|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 3765833212244435302, + "detailed_name": "void Foobar::Foobar(int &&, Bar *, bool *)", + "short_name": "Foobar", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "7:3-7:9|1|2|2", + "extent": "7:3-7:32|1|2|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 17321436359755983845, + "detailed_name": "void Foobar::Foobar(int, Bar *, bool *)", + "short_name": "Foobar", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "8:3-8:9|1|2|2", + "extent": "8:3-8:30|1|2|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +OUTPUT: make_functions.cc +{ + "includes": [{ + "line": 0, + "resolved_path": "&make_functions.h" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 7902098450755788854, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "3:20-3:21|0|3|2", + "extent": "3:11-3:21|0|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:1-4:2|-1|1|4"] + }, { + "id": 1, + "usr": 12533159752419999454, + "detailed_name": "Args", + "short_name": "Args", + "kind": 26, + "declarations": [], + "spell": "3:35-3:39|0|3|2", + "extent": "3:23-3:39|0|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:15-4:19|-1|1|4"] + }, { + "id": 2, + "usr": 18441628706991062891, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "8:20-8:21|1|3|2", + "extent": "8:11-8:21|1|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["9:1-9:2|-1|1|4"] + }, { + "id": 3, + "usr": 9441341235704820385, + "detailed_name": "Args", + "short_name": "Args", + "kind": 26, + "declarations": [], + "spell": "8:35-8:39|1|3|2", + "extent": "8:23-8:39|1|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["9:16-9:20|-1|1|4"] + }, { + "id": 4, + "usr": 14935975554338052500, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["14:14-14:20|-1|1|4", "15:14-15:20|-1|1|4", "16:14-16:20|-1|1|4", "17:15-17:21|-1|1|4"] + }, { + "id": 5, + "usr": 12993848456528750350, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["16:29-16:32|-1|1|4", "17:30-17:33|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 15793662558620604611, + "detailed_name": "T *MakeUnique(Args &&... args)", + "short_name": "MakeUnique", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "4:4-4:14|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": ["14:3-14:13|2|3|32", "15:3-15:13|2|3|32", "16:3-16:13|2|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 2532818908869373467, + "detailed_name": "T *maKE_NoRefs(Args... args)", + "short_name": "maKE_NoRefs", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "9:4-9:15|-1|1|2", + "extent": "9:1-11:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [1], + "uses": ["17:3-17:14|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 2816883305867289955, + "detailed_name": "void caller22()", + "short_name": "caller22", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "13:6-13:14|-1|1|2", + "extent": "13:1-18:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["14:3-14:13|0|3|32", "15:3-15:13|0|3|32", "16:3-16:13|0|3|32", "17:3-17:14|1|3|32"] + }, { + "id": 3, + "usr": 13131778807733950299, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["14:3-14:13|-1|1|288"], + "callees": [] + }, { + "id": 4, + "usr": 13028995015627606181, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["15:3-15:13|-1|1|288"], + "callees": [] + }, { + "id": 5, + "usr": 3765833212244435302, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["16:3-16:13|-1|1|288"], + "callees": [] + }, { + "id": 6, + "usr": 17321436359755983845, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["17:3-17:14|-1|1|288"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 15288691366352169805, + "detailed_name": "Args &&... args", + "short_name": "args", + "declarations": [], + "spell": "4:25-4:29|0|3|2", + "extent": "4:15-4:29|0|3|0", + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 12338908251430965107, + "detailed_name": "Args... args", + "short_name": "args", + "declarations": [], + "spell": "9:24-9:28|1|3|2", + "extent": "9:16-9:28|1|3|0", + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/constructors/make_functions.h b/index_tests/constructors/make_functions.h new file mode 100644 index 00000000..f119cfb8 --- /dev/null +++ b/index_tests/constructors/make_functions.h @@ -0,0 +1,10 @@ +struct Bar {}; + +class Foobar { + public: + Foobar() {} + Foobar(int) {} + Foobar(int&&, Bar*, bool*) {} + Foobar(int, Bar*, bool*) {} +}; + diff --git a/index_tests/declaration_vs_definition/class.cc b/index_tests/declaration_vs_definition/class.cc new file mode 100644 index 00000000..00e22bc4 --- /dev/null +++ b/index_tests/declaration_vs_definition/class.cc @@ -0,0 +1,33 @@ +class Foo; +class Foo; +class Foo {}; +class Foo; + +/* +// NOTE: Separate decl/definition are not supported for classes. See source +// for comments. +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": ["1:7-1:10|-1|1|1", "2:7-2:10|-1|1|1", "4:7-4:10|-1|1|1"], + "spell": "3:7-3:10|-1|1|2", + "extent": "3:1-3:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/declaration_vs_definition/class_member.cc b/index_tests/declaration_vs_definition/class_member.cc new file mode 100644 index 00000000..ccbbd2c9 --- /dev/null +++ b/index_tests/declaration_vs_definition/class_member.cc @@ -0,0 +1,56 @@ +class Foo { + int foo; +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 9736582033442720743, + "detailed_name": "int Foo::foo", + "short_name": "foo", + "declarations": [], + "spell": "2:7-2:10|0|2|2", + "extent": "2:3-2:10|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/declaration_vs_definition/class_member_static.cc b/index_tests/declaration_vs_definition/class_member_static.cc new file mode 100644 index 00000000..838913bc --- /dev/null +++ b/index_tests/declaration_vs_definition/class_member_static.cc @@ -0,0 +1,58 @@ +class Foo { + static int foo; +}; + +int Foo::foo; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": ["5:5-5:8|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 8942920329766232482, + "detailed_name": "int Foo::foo", + "short_name": "foo", + "declarations": ["2:14-2:17|0|2|1"], + "spell": "5:10-5:13|0|2|2", + "extent": "5:1-5:13|-1|1|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 1 + }] +} +*/ diff --git a/index_tests/declaration_vs_definition/func.cc b/index_tests/declaration_vs_definition/func.cc new file mode 100644 index 00000000..8e69aeb1 --- /dev/null +++ b/index_tests/declaration_vs_definition/func.cc @@ -0,0 +1,40 @@ +void foo(); +void foo(); +void foo() {} +void foo(); + +/* +// Note: we always use the latest seen ("most local") definition/declaration. +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:9|-1|1|1", + "param_spellings": [] + }, { + "spell": "2:6-2:9|-1|1|1", + "param_spellings": [] + }, { + "spell": "4:6-4:9|-1|1|1", + "param_spellings": [] + }], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-3:14|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/declaration_vs_definition/func_associated_function_params.cc b/index_tests/declaration_vs_definition/func_associated_function_params.cc new file mode 100644 index 00000000..f917921e --- /dev/null +++ b/index_tests/declaration_vs_definition/func_associated_function_params.cc @@ -0,0 +1,78 @@ +int foo(int, int); +int foo(int aa, + int bb); +int foo(int aaa, int bbb); +int foo(int a, int b) { return 0; } + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 2747674671862363334, + "detailed_name": "int foo(int a, int b)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:5-1:8|-1|1|1", + "param_spellings": ["1:12-1:12", "1:17-1:17"] + }, { + "spell": "2:5-2:8|-1|1|1", + "param_spellings": ["2:13-2:15", "3:13-3:15"] + }, { + "spell": "4:5-4:8|-1|1|1", + "param_spellings": ["4:13-4:16", "4:22-4:25"] + }], + "spell": "5:5-5:8|-1|1|2", + "extent": "5:1-5:36|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 10480417713467708012, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "5:13-5:14|0|3|2", + "extent": "5:9-5:14|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 18099600680625658464, + "detailed_name": "int b", + "short_name": "b", + "declarations": [], + "spell": "5:20-5:21|0|3|2", + "extent": "5:16-5:21|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/declaration_vs_definition/method.cc b/index_tests/declaration_vs_definition/method.cc new file mode 100644 index 00000000..1be15a33 --- /dev/null +++ b/index_tests/declaration_vs_definition/method.cc @@ -0,0 +1,87 @@ +class Foo { + void declonly(); + virtual void purevirtual() = 0; + void def(); +}; + +void Foo::def() {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0, 1, 2], + "vars": [], + "instances": [], + "uses": ["7:6-7:9|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 4012226004228259562, + "detailed_name": "void Foo::declonly()", + "short_name": "declonly", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:16|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 10939323144126021546, + "detailed_name": "void Foo::purevirtual()", + "short_name": "purevirtual", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "3:16-3:27|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 15416083548883122431, + "detailed_name": "void Foo::def()", + "short_name": "def", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "4:8-4:11|0|2|1", + "param_spellings": [] + }], + "spell": "7:11-7:14|0|2|2", + "extent": "7:1-7:19|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/enums/enum_class_decl.cc b/index_tests/enums/enum_class_decl.cc new file mode 100644 index 00000000..6d1cd6fb --- /dev/null +++ b/index_tests/enums/enum_class_decl.cc @@ -0,0 +1,90 @@ +typedef unsigned char uint8_t; +enum class Foo : uint8_t { + A, + B = 20 +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 5, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 2010430204259339553, + "detailed_name": "uint8_t", + "short_name": "uint8_t", + "kind": 252, + "hover": "typedef unsigned char uint8_t", + "declarations": [], + "spell": "1:23-1:30|-1|1|2", + "extent": "1:1-1:30|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:23-1:30|-1|1|4", "2:12-2:15|-1|1|4"] + }, { + "id": 2, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 10, + "declarations": [], + "spell": "2:12-2:15|-1|1|2", + "extent": "2:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 439339022761937396, + "detailed_name": "Foo::A", + "short_name": "A", + "hover": "Foo::A = 0", + "declarations": [], + "spell": "3:3-3:4|2|2|2", + "extent": "3:3-3:4|2|2|0", + "type": 2, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 15962370213938840720, + "detailed_name": "Foo::B", + "short_name": "B", + "hover": "Foo::B = 20", + "declarations": [], + "spell": "4:3-4:4|2|2|2", + "extent": "4:3-4:9|2|2|0", + "type": 2, + "uses": [], + "kind": 22, + "storage": 0 + }] +} +*/ diff --git a/index_tests/enums/enum_decl.cc b/index_tests/enums/enum_decl.cc new file mode 100644 index 00000000..9240c5a5 --- /dev/null +++ b/index_tests/enums/enum_decl.cc @@ -0,0 +1,57 @@ +enum Foo { + A, + B = 20 +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 10, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 439339022761937396, + "detailed_name": "Foo::A", + "short_name": "A", + "hover": "Foo::A = 0", + "declarations": [], + "spell": "2:3-2:4|0|2|2", + "extent": "2:3-2:4|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 15962370213938840720, + "detailed_name": "Foo::B", + "short_name": "B", + "hover": "Foo::B = 20", + "declarations": [], + "spell": "3:3-3:4|0|2|2", + "extent": "3:3-3:9|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }] +} +*/ diff --git a/index_tests/enums/enum_inherit.cc b/index_tests/enums/enum_inherit.cc new file mode 100644 index 00000000..9ee6bcdf --- /dev/null +++ b/index_tests/enums/enum_inherit.cc @@ -0,0 +1,138 @@ +enum Foo : int { + A, + B = 20 +}; + +typedef int int32_t; + +enum class E : int32_t { + E0, + E20 = 20 +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 10, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 14939241684006947339, + "detailed_name": "int32_t", + "short_name": "int32_t", + "kind": 252, + "hover": "typedef int int32_t", + "declarations": [], + "spell": "6:13-6:20|-1|1|2", + "extent": "6:1-6:20|-1|1|0", + "alias_of": 1, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["6:13-6:20|-1|1|4", "8:12-8:13|-1|1|4"] + }, { + "id": 3, + "usr": 2986879766914123941, + "detailed_name": "E", + "short_name": "E", + "kind": 10, + "declarations": [], + "spell": "8:12-8:13|-1|1|2", + "extent": "8:1-11:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 439339022761937396, + "detailed_name": "Foo::A", + "short_name": "A", + "hover": "Foo::A = 0", + "declarations": [], + "spell": "2:3-2:4|0|2|2", + "extent": "2:3-2:4|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 15962370213938840720, + "detailed_name": "Foo::B", + "short_name": "B", + "hover": "Foo::B = 20", + "declarations": [], + "spell": "3:3-3:4|0|2|2", + "extent": "3:3-3:9|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 2, + "usr": 16614320383091394267, + "detailed_name": "E::E0", + "short_name": "E0", + "hover": "E::E0 = 0", + "declarations": [], + "spell": "9:3-9:5|3|2|2", + "extent": "9:3-9:5|3|2|0", + "type": 3, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 3, + "usr": 16847439761518576294, + "detailed_name": "E::E20", + "short_name": "E20", + "hover": "E::E20 = 20", + "declarations": [], + "spell": "10:3-10:6|3|2|2", + "extent": "10:3-10:11|3|2|0", + "type": 3, + "uses": [], + "kind": 22, + "storage": 0 + }] +} +*/ diff --git a/index_tests/enums/enum_usage.cc b/index_tests/enums/enum_usage.cc new file mode 100644 index 00000000..c019a36c --- /dev/null +++ b/index_tests/enums/enum_usage.cc @@ -0,0 +1,72 @@ +enum class Foo { + A, + B = 20 +}; + +Foo x = Foo::A; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 10, + "declarations": [], + "spell": "1:12-1:15|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["6:1-6:4|-1|1|4", "6:9-6:12|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 439339022761937396, + "detailed_name": "Foo::A", + "short_name": "A", + "hover": "Foo::A = 0", + "declarations": [], + "spell": "2:3-2:4|0|2|2", + "extent": "2:3-2:4|0|2|0", + "type": 0, + "uses": ["6:14-6:15|-1|1|4"], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 15962370213938840720, + "detailed_name": "Foo::B", + "short_name": "B", + "hover": "Foo::B = 20", + "declarations": [], + "spell": "3:3-3:4|0|2|2", + "extent": "3:3-3:9|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 2, + "usr": 10677751717622394455, + "detailed_name": "Foo x", + "short_name": "x", + "hover": "Foo x = Foo::A", + "declarations": [], + "spell": "6:5-6:6|-1|1|2", + "extent": "6:1-6:15|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/foobar.cc b/index_tests/foobar.cc new file mode 100644 index 00000000..0d240d27 --- /dev/null +++ b/index_tests/foobar.cc @@ -0,0 +1,108 @@ +enum A {}; +enum B {}; + +template +struct Foo { + struct Inner {}; +}; + +Foo::Inner a; +Foo b; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 6697181287623958829, + "detailed_name": "A", + "short_name": "A", + "kind": 10, + "declarations": [], + "spell": "1:6-1:7|-1|1|2", + "extent": "1:1-1:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["9:5-9:6|-1|1|4"] + }, { + "id": 1, + "usr": 13892793056005362145, + "detailed_name": "B", + "short_name": "B", + "kind": 10, + "declarations": [], + "spell": "2:6-2:7|-1|1|2", + "extent": "2:1-2:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["10:5-10:6|-1|1|4"] + }, { + "id": 2, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "5:8-5:11|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": ["9:1-9:4|-1|1|4", "10:1-10:4|-1|1|4"] + }, { + "id": 3, + "usr": 13938528237873543349, + "detailed_name": "Foo::Inner", + "short_name": "Inner", + "kind": 23, + "declarations": [], + "spell": "6:10-6:15|2|2|2", + "extent": "6:3-6:18|2|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["9:9-9:14|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "Foo::Inner a", + "short_name": "a", + "declarations": [], + "spell": "9:15-9:16|-1|1|2", + "extent": "9:1-9:16|-1|1|0", + "type": 3, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "Foo b", + "short_name": "b", + "declarations": [], + "spell": "10:8-10:9|-1|1|2", + "extent": "10:1-10:9|-1|1|0", + "type": 2, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/function_declaration.cc b/index_tests/function_declaration.cc new file mode 100644 index 00000000..a9bb6ae1 --- /dev/null +++ b/index_tests/function_declaration.cc @@ -0,0 +1,28 @@ +void foo(int a, int b); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 2747674671862363334, + "detailed_name": "void foo(int a, int b)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:9|-1|1|1", + "param_spellings": ["1:14-1:15", "1:21-1:22"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/function_declaration_definition.cc b/index_tests/function_declaration_definition.cc new file mode 100644 index 00000000..7b1f4030 --- /dev/null +++ b/index_tests/function_declaration_definition.cc @@ -0,0 +1,32 @@ +void foo(); + +void foo() {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:9|-1|1|1", + "param_spellings": [] + }], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-3:14|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/function_definition.cc b/index_tests/function_definition.cc new file mode 100644 index 00000000..f4ccb882 --- /dev/null +++ b/index_tests/function_definition.cc @@ -0,0 +1,27 @@ +void foo() {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-1:14|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/inheritance/class_inherit.cc b/index_tests/inheritance/class_inherit.cc new file mode 100644 index 00000000..f4e214c9 --- /dev/null +++ b/index_tests/inheritance/class_inherit.cc @@ -0,0 +1,45 @@ +class Parent {}; +class Derived : public Parent {}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 3866412049634585509, + "detailed_name": "Parent", + "short_name": "Parent", + "kind": 5, + "declarations": ["2:24-2:30|-1|1|4"], + "spell": "1:7-1:13|-1|1|2", + "extent": "1:1-1:16|-1|1|0", + "bases": [], + "derived": [1], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:24-2:30|-1|1|4"] + }, { + "id": 1, + "usr": 10963370434658308541, + "detailed_name": "Derived", + "short_name": "Derived", + "kind": 5, + "declarations": [], + "spell": "2:7-2:14|-1|1|2", + "extent": "2:1-2:33|-1|1|0", + "bases": [0], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/inheritance/class_inherit_templated_parent.cc b/index_tests/inheritance/class_inherit_templated_parent.cc new file mode 100644 index 00000000..1b1bda9d --- /dev/null +++ b/index_tests/inheritance/class_inherit_templated_parent.cc @@ -0,0 +1,146 @@ +template +class Base1 {}; + +template +class Base2 {}; + +template +class Derived1 : Base1 {}; + +template +class Derived2 : Base2 {}; + +class Derived : Base1<3>, Base2, Derived1<4>, Derived2 {}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11930058224338108382, + "detailed_name": "Base1", + "short_name": "Base1", + "kind": 5, + "declarations": ["8:18-8:23|-1|1|4", "13:17-13:22|-1|1|4"], + "spell": "2:7-2:12|-1|1|2", + "extent": "2:1-2:15|-1|1|0", + "bases": [], + "derived": [2, 6], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["8:18-8:23|-1|1|4", "13:17-13:22|-1|1|4"] + }, { + "id": 1, + "usr": 11118288764693061434, + "detailed_name": "Base2", + "short_name": "Base2", + "kind": 5, + "declarations": ["11:18-11:23|-1|1|4", "13:27-13:32|-1|1|4"], + "spell": "5:7-5:12|-1|1|2", + "extent": "5:1-5:15|-1|1|0", + "bases": [], + "derived": [4, 6], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["11:18-11:23|-1|1|4", "13:27-13:32|-1|1|4"] + }, { + "id": 2, + "usr": 5863733211528032190, + "detailed_name": "Derived1", + "short_name": "Derived1", + "kind": 5, + "declarations": ["13:43-13:51|-1|1|4"], + "spell": "8:7-8:15|-1|1|2", + "extent": "8:1-8:29|-1|1|0", + "bases": [0], + "derived": [6], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["13:43-13:51|-1|1|4"] + }, { + "id": 3, + "usr": 9, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }, { + "id": 4, + "usr": 10651399730831737929, + "detailed_name": "Derived2", + "short_name": "Derived2", + "kind": 5, + "declarations": ["13:56-13:64|-1|1|4"], + "spell": "11:7-11:15|-1|1|2", + "extent": "11:1-11:29|-1|1|0", + "bases": [1], + "derived": [6], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["13:56-13:64|-1|1|4"] + }, { + "id": 5, + "usr": 780719166805015998, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "10:19-10:20|-1|1|2", + "extent": "10:10-10:20|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["11:24-11:25|-1|1|4"] + }, { + "id": 6, + "usr": 10963370434658308541, + "detailed_name": "Derived", + "short_name": "Derived", + "kind": 5, + "declarations": ["13:33-13:40|-1|1|4", "13:65-13:72|-1|1|4"], + "spell": "13:7-13:14|-1|1|2", + "extent": "13:1-13:76|-1|1|0", + "bases": [0, 1, 2, 4], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["13:33-13:40|-1|1|4", "13:65-13:72|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 3880651725784125791, + "detailed_name": "unsigned int T", + "short_name": "T", + "declarations": [], + "spell": "7:23-7:24|-1|1|2", + "extent": "7:10-7:24|-1|1|0", + "type": 3, + "uses": ["8:24-8:25|-1|1|4"], + "kind": 26, + "storage": 0 + }] +} +*/ diff --git a/index_tests/inheritance/class_multiple_inherit.cc b/index_tests/inheritance/class_multiple_inherit.cc new file mode 100644 index 00000000..785a1bf9 --- /dev/null +++ b/index_tests/inheritance/class_multiple_inherit.cc @@ -0,0 +1,79 @@ +class Root {}; +class MiddleA : public Root {}; +class MiddleB : public Root {}; +class Derived : public MiddleA, public MiddleB {}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 3897841498936210886, + "detailed_name": "Root", + "short_name": "Root", + "kind": 5, + "declarations": ["2:24-2:28|-1|1|4", "3:24-3:28|-1|1|4"], + "spell": "1:7-1:11|-1|1|2", + "extent": "1:1-1:14|-1|1|0", + "bases": [], + "derived": [1, 2], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:24-2:28|-1|1|4", "3:24-3:28|-1|1|4"] + }, { + "id": 1, + "usr": 11863524815063131483, + "detailed_name": "MiddleA", + "short_name": "MiddleA", + "kind": 5, + "declarations": ["4:24-4:31|-1|1|4"], + "spell": "2:7-2:14|-1|1|2", + "extent": "2:1-2:31|-1|1|0", + "bases": [0], + "derived": [3], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:24-4:31|-1|1|4"] + }, { + "id": 2, + "usr": 14022569716337624303, + "detailed_name": "MiddleB", + "short_name": "MiddleB", + "kind": 5, + "declarations": ["4:40-4:47|-1|1|4"], + "spell": "3:7-3:14|-1|1|2", + "extent": "3:1-3:31|-1|1|0", + "bases": [0], + "derived": [3], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:40-4:47|-1|1|4"] + }, { + "id": 3, + "usr": 10963370434658308541, + "detailed_name": "Derived", + "short_name": "Derived", + "kind": 5, + "declarations": [], + "spell": "4:7-4:14|-1|1|2", + "extent": "4:1-4:50|-1|1|0", + "bases": [1, 2], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/inheritance/function_override.cc b/index_tests/inheritance/function_override.cc new file mode 100644 index 00000000..36b5d32d --- /dev/null +++ b/index_tests/inheritance/function_override.cc @@ -0,0 +1,82 @@ +class Root { + virtual void foo(); +}; +class Derived : public Root { + void foo() override {} +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 3897841498936210886, + "detailed_name": "Root", + "short_name": "Root", + "kind": 5, + "declarations": ["4:24-4:28|-1|1|4"], + "spell": "1:7-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [1], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["4:24-4:28|-1|1|4"] + }, { + "id": 1, + "usr": 10963370434658308541, + "detailed_name": "Derived", + "short_name": "Derived", + "kind": 5, + "declarations": [], + "spell": "4:7-4:14|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [0], + "derived": [], + "types": [], + "funcs": [1], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 9948027785633571339, + "detailed_name": "void Root::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:16-2:19|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [1], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 6666242542855173890, + "detailed_name": "void Derived::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "5:8-5:11|1|2|2", + "extent": "5:3-5:25|1|2|0", + "declaring_type": 1, + "bases": [0], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/inheritance/interface_pure_virtual.cc b/index_tests/inheritance/interface_pure_virtual.cc new file mode 100644 index 00000000..69251384 --- /dev/null +++ b/index_tests/inheritance/interface_pure_virtual.cc @@ -0,0 +1,47 @@ +class IFoo { + virtual void foo() = 0; +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 9949214233977131946, + "detailed_name": "IFoo", + "short_name": "IFoo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 3277829753446788562, + "detailed_name": "void IFoo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:16-2:19|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/inheritance/multiple_base_functions.cc b/index_tests/inheritance/multiple_base_functions.cc new file mode 100644 index 00000000..6550bb37 --- /dev/null +++ b/index_tests/inheritance/multiple_base_functions.cc @@ -0,0 +1,116 @@ +struct Base0 { + virtual ~Base0() { } +}; +struct Base1 { + virtual ~Base1() { } +}; +struct Derived : Base0, Base1 { + ~Derived() override { } +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11628904180681204356, + "detailed_name": "Base0", + "short_name": "Base0", + "kind": 23, + "declarations": ["2:12-2:17|-1|1|4", "7:18-7:23|-1|1|4"], + "spell": "1:8-1:13|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [2], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["7:18-7:23|-1|1|4"] + }, { + "id": 1, + "usr": 15826803741381445676, + "detailed_name": "Base1", + "short_name": "Base1", + "kind": 23, + "declarations": ["5:12-5:17|-1|1|4", "7:25-7:30|-1|1|4"], + "spell": "4:8-4:13|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [], + "derived": [2], + "types": [], + "funcs": [1], + "vars": [], + "instances": [], + "uses": ["7:25-7:30|-1|1|4"] + }, { + "id": 2, + "usr": 10963370434658308541, + "detailed_name": "Derived", + "short_name": "Derived", + "kind": 23, + "declarations": ["8:4-8:11|-1|1|4"], + "spell": "7:8-7:15|-1|1|2", + "extent": "7:1-9:2|-1|1|0", + "bases": [0, 1], + "derived": [], + "types": [], + "funcs": [2], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 16347272523198263017, + "detailed_name": "void Base0::~Base0() noexcept", + "short_name": "~Base0", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "2:11-2:17|0|2|2", + "extent": "2:3-2:23|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [2], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 8401779086123965305, + "detailed_name": "void Base1::~Base1() noexcept", + "short_name": "~Base1", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "5:11-5:17|1|2|2", + "extent": "5:3-5:23|1|2|0", + "declaring_type": 1, + "bases": [], + "derived": [2], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 13164726294460837993, + "detailed_name": "void Derived::~Derived() noexcept", + "short_name": "~Derived", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "8:3-8:11|2|2|2", + "extent": "8:3-8:26|2|2|0", + "declaring_type": 2, + "bases": [0, 1], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ \ No newline at end of file diff --git a/index_tests/lambdas/lambda.cc b/index_tests/lambdas/lambda.cc new file mode 100644 index 00000000..2bc4d60f --- /dev/null +++ b/index_tests/lambdas/lambda.cc @@ -0,0 +1,115 @@ +void foo() { + int x; + + auto dosomething = [&x](int y) { + ++x; + ++y; + }; + + dosomething(1); + dosomething(1); + dosomething(1); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 2], + "uses": [] + }, { + "id": 1, + "usr": 1287417953265234030, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-12:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": ["9:14-9:15|1|3|32", "10:14-10:15|1|3|32", "11:14-11:15|1|3|32"] + }, { + "id": 1, + "usr": 1328781044864682611, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["9:14-9:15|0|3|32", "10:14-10:15|0|3|32", "11:14-11:15|0|3|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 17270098654620601683, + "detailed_name": "int x", + "short_name": "x", + "declarations": [], + "spell": "2:7-2:8|0|3|2", + "extent": "2:3-2:8|0|3|0", + "type": 0, + "uses": ["5:7-5:8|-1|1|4", "4:24-4:25|0|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 16806544259835773270, + "detailed_name": "lambda dosomething", + "short_name": "dosomething", + "declarations": [], + "spell": "4:8-4:19|0|3|2", + "extent": "4:3-7:4|0|3|0", + "type": 1, + "uses": ["9:3-9:14|0|3|4", "10:3-10:14|0|3|4", "11:3-11:14|0|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 2034725908368218782, + "detailed_name": "int y", + "short_name": "y", + "declarations": [], + "spell": "4:31-4:32|0|3|2", + "extent": "4:27-4:32|0|3|0", + "type": 0, + "uses": ["6:7-6:8|0|3|4"], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/macros/complex.cc b/index_tests/macros/complex.cc new file mode 100644 index 00000000..827a67e1 --- /dev/null +++ b/index_tests/macros/complex.cc @@ -0,0 +1,95 @@ +#define FOO(aaa, bbb) \ + int a();\ + int a() { return aaa + bbb; } + + +int make1() { + return 3; +} +const int make2 = 5; + + +FOO(make1(), make2); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 14400399977994209582, + "detailed_name": "int make1()", + "short_name": "make1", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "6:5-6:10|-1|1|2", + "extent": "6:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["12:5-12:10|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 9720930732776154610, + "detailed_name": "int a()", + "short_name": "a", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "12:1-12:20|-1|1|1", + "param_spellings": [] + }], + "spell": "12:1-12:20|-1|1|2", + "extent": "12:1-12:20|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["12:5-12:10|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 2878407290385495202, + "detailed_name": "const int make2", + "short_name": "make2", + "hover": "const int make2 = 5", + "declarations": [], + "spell": "9:11-9:16|-1|1|2", + "extent": "9:1-9:20|-1|1|0", + "type": 0, + "uses": ["12:14-12:19|1|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 4261071340275951718, + "detailed_name": "FOO", + "short_name": "FOO", + "hover": "#define FOO(aaa, bbb)\n int a();\n int a() { return aaa + bbb; }", + "declarations": [], + "spell": "1:9-1:12|-1|1|2", + "extent": "1:9-3:32|-1|1|0", + "uses": ["12:1-12:4|-1|1|4"], + "kind": 255, + "storage": 0 + }] +} +*/ \ No newline at end of file diff --git a/index_tests/macros/foo.cc b/index_tests/macros/foo.cc new file mode 100644 index 00000000..6dbe1466 --- /dev/null +++ b/index_tests/macros/foo.cc @@ -0,0 +1,102 @@ +#define A 5 +#define DISALLOW(type) type(type&&) = delete; + +struct Foo { + DISALLOW(Foo); +}; + +int x = A; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["5:12-5:15|-1|1|4"], + "spell": "4:8-4:11|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["5:12-5:15|0|2|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 13788753348312146871, + "detailed_name": "void Foo::Foo(Foo &&)", + "short_name": "Foo", + "kind": 9, + "storage": 1, + "declarations": [], + "spell": "5:12-5:15|0|2|2", + "extent": "5:12-5:16|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 10677751717622394455, + "detailed_name": "int x", + "short_name": "x", + "hover": "int x = A", + "declarations": [], + "spell": "8:5-8:6|-1|1|2", + "extent": "8:1-8:10|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 7651988378939587454, + "detailed_name": "A", + "short_name": "A", + "hover": "#define A 5", + "declarations": [], + "spell": "1:9-1:10|-1|1|2", + "extent": "1:9-1:12|-1|1|0", + "uses": ["8:9-8:10|-1|1|4"], + "kind": 255, + "storage": 0 + }, { + "id": 2, + "usr": 14946041066794678724, + "detailed_name": "DISALLOW", + "short_name": "DISALLOW", + "hover": "#define DISALLOW(type) type(type&&) = delete;", + "declarations": [], + "spell": "2:9-2:17|-1|1|2", + "extent": "2:9-2:46|-1|1|0", + "uses": ["5:3-5:11|-1|1|4"], + "kind": 255, + "storage": 0 + }] +} +*/ diff --git a/index_tests/method_declaration.cc b/index_tests/method_declaration.cc new file mode 100644 index 00000000..1b2698dd --- /dev/null +++ b/index_tests/method_declaration.cc @@ -0,0 +1,51 @@ +class Foo { + void foo(); +}; + +/* +// NOTE: Lack of declaring_type in functions and funcs in Foo is okay, because +// those are processed when we find the definition for Foo::foo. Pure +// virtuals are treated specially and get added to the type immediately. + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17922201480358737771, + "detailed_name": "void Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:11|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/method_definition.cc b/index_tests/method_definition.cc new file mode 100644 index 00000000..8da4a2af --- /dev/null +++ b/index_tests/method_definition.cc @@ -0,0 +1,51 @@ +class Foo { + void foo() const; +}; + +void Foo::foo() const {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["5:6-5:9|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 6446764306530590711, + "detailed_name": "void Foo::foo() const", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:11|0|2|1", + "param_spellings": [] + }], + "spell": "5:11-5:14|0|2|2", + "extent": "5:1-5:25|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/method_inline_declaration.cc b/index_tests/method_inline_declaration.cc new file mode 100644 index 00000000..85cfb39c --- /dev/null +++ b/index_tests/method_inline_declaration.cc @@ -0,0 +1,46 @@ +class Foo { + void foo() {} +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17922201480358737771, + "detailed_name": "void Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "2:8-2:11|0|2|2", + "extent": "2:3-2:16|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/multi_file/funky_enum.cc b/index_tests/multi_file/funky_enum.cc new file mode 100644 index 00000000..d445744f --- /dev/null +++ b/index_tests/multi_file/funky_enum.cc @@ -0,0 +1,97 @@ +enum Foo { +#include "funky_enum.h" +}; + +/* +// TODO: In the future try to have better support for types defined across +// multiple files. + +OUTPUT: funky_enum.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 439339022761937396, + "detailed_name": "Foo::A", + "short_name": "A", + "hover": "Foo::A = 0", + "declarations": [], + "spell": "4:1-4:2|0|2|2", + "extent": "4:1-4:2|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 15962370213938840720, + "detailed_name": "Foo::B", + "short_name": "B", + "hover": "Foo::B = 1", + "declarations": [], + "spell": "5:1-5:2|0|2|2", + "extent": "5:1-5:2|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 2, + "usr": 8524995777615948802, + "detailed_name": "Foo::C", + "short_name": "C", + "hover": "Foo::C = 2", + "declarations": [], + "spell": "6:1-6:2|0|2|2", + "extent": "6:1-6:2|0|2|0", + "type": 0, + "uses": [], + "kind": 22, + "storage": 0 + }] +} +OUTPUT: funky_enum.cc +{ + "includes": [{ + "line": 1, + "resolved_path": "&funky_enum.h" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 16985894625255407295, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 10, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [] +} +*/ \ No newline at end of file diff --git a/index_tests/multi_file/funky_enum.h b/index_tests/multi_file/funky_enum.h new file mode 100644 index 00000000..b11cc441 --- /dev/null +++ b/index_tests/multi_file/funky_enum.h @@ -0,0 +1,6 @@ +// This file cannot be built directory. It is included in an enum definition of +// another file. + +A, +B, +C \ No newline at end of file diff --git a/index_tests/multi_file/header.h b/index_tests/multi_file/header.h new file mode 100644 index 00000000..717ef821 --- /dev/null +++ b/index_tests/multi_file/header.h @@ -0,0 +1,18 @@ +#pragma once + +struct Base {}; + +struct SameFileDerived : Base {}; + +using Foo0 = SameFileDerived; + +template +void Foo1() {} + +template +struct Foo2 {}; + +enum Foo3 { A, B, C }; + +int Foo4; +static int Foo5; \ No newline at end of file diff --git a/index_tests/multi_file/impl.cc b/index_tests/multi_file/impl.cc new file mode 100644 index 00000000..1e3fb85c --- /dev/null +++ b/index_tests/multi_file/impl.cc @@ -0,0 +1,229 @@ +#include "header.h" + +void Impl() { + Foo1(); +} + +/* +OUTPUT: header.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 8420119006782424779, + "detailed_name": "Base", + "short_name": "Base", + "kind": 23, + "declarations": ["5:26-5:30|-1|1|4"], + "spell": "3:8-3:12|-1|1|2", + "extent": "3:1-3:15|-1|1|0", + "bases": [], + "derived": [1], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:26-5:30|-1|1|4"] + }, { + "id": 1, + "usr": 16750616846959666305, + "detailed_name": "SameFileDerived", + "short_name": "SameFileDerived", + "kind": 23, + "declarations": [], + "spell": "5:8-5:23|-1|1|2", + "extent": "5:1-5:33|-1|1|0", + "bases": [0], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:14-7:29|-1|1|4"] + }, { + "id": 2, + "usr": 619345544228965342, + "detailed_name": "Foo0", + "short_name": "Foo0", + "kind": 252, + "hover": "using Foo0 = SameFileDerived", + "declarations": [], + "spell": "7:7-7:11|-1|1|2", + "extent": "7:1-7:29|-1|1|0", + "alias_of": 1, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:7-7:11|-1|1|4"] + }, { + "id": 3, + "usr": 529393482671181129, + "detailed_name": "Foo2", + "short_name": "Foo2", + "kind": 5, + "declarations": [], + "spell": "13:8-13:12|-1|1|2", + "extent": "13:1-13:15|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 4, + "usr": 4481210672785600703, + "detailed_name": "Foo3", + "short_name": "Foo3", + "kind": 10, + "declarations": [], + "spell": "15:6-15:10|-1|1|2", + "extent": "15:1-15:22|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 5, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [3, 4], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 11650481237659640387, + "detailed_name": "void Foo1()", + "short_name": "Foo1", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "10:6-10:10|-1|1|2", + "extent": "10:1-10:15|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 6141718166919284735, + "detailed_name": "Foo3::A", + "short_name": "A", + "hover": "Foo3::A = 0", + "declarations": [], + "spell": "15:13-15:14|4|2|2", + "extent": "15:13-15:14|4|2|0", + "type": 4, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 1, + "usr": 17716334512218775320, + "detailed_name": "Foo3::B", + "short_name": "B", + "hover": "Foo3::B = 1", + "declarations": [], + "spell": "15:16-15:17|4|2|2", + "extent": "15:16-15:17|4|2|0", + "type": 4, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 2, + "usr": 7285646116511901840, + "detailed_name": "Foo3::C", + "short_name": "C", + "hover": "Foo3::C = 2", + "declarations": [], + "spell": "15:19-15:20|4|2|2", + "extent": "15:19-15:20|4|2|0", + "type": 4, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 3, + "usr": 2638219001294786365, + "detailed_name": "int Foo4", + "short_name": "Foo4", + "declarations": [], + "spell": "17:5-17:9|-1|1|2", + "extent": "17:1-17:9|-1|1|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 4, + "usr": 8395885290297540138, + "detailed_name": "int Foo5", + "short_name": "Foo5", + "declarations": [], + "spell": "18:12-18:16|-1|1|2", + "extent": "18:1-18:16|-1|1|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 3 + }] +} +OUTPUT: impl.cc +{ + "includes": [{ + "line": 0, + "resolved_path": "&header.h" + }], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 5817708529036841195, + "detailed_name": "void Impl()", + "short_name": "Impl", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:10|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["4:3-4:7|1|3|32"] + }, { + "id": 1, + "usr": 11650481237659640387, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["4:3-4:7|0|3|32"], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/multi_file/simple_header.h b/index_tests/multi_file/simple_header.h new file mode 100644 index 00000000..3bdf008a --- /dev/null +++ b/index_tests/multi_file/simple_header.h @@ -0,0 +1,3 @@ +#pragma once + +void header(); \ No newline at end of file diff --git a/index_tests/multi_file/simple_impl.cc b/index_tests/multi_file/simple_impl.cc new file mode 100644 index 00000000..d322603a --- /dev/null +++ b/index_tests/multi_file/simple_impl.cc @@ -0,0 +1,71 @@ +#include "simple_header.h" + +void impl() { + header(); +} + +/* +OUTPUT: simple_header.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 16236105532929924676, + "detailed_name": "void header()", + "short_name": "header", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "3:6-3:12|-1|1|1", + "param_spellings": [] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +OUTPUT: simple_impl.cc +{ + "includes": [{ + "line": 0, + "resolved_path": "&simple_header.h" + }], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 3373269392705484958, + "detailed_name": "void impl()", + "short_name": "impl", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:10|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["4:3-4:9|1|3|32"] + }, { + "id": 1, + "usr": 16236105532929924676, + "detailed_name": "", + "short_name": "", + "kind": 0, + "storage": 0, + "declarations": [], + "bases": [], + "derived": [], + "vars": [], + "uses": ["4:3-4:9|0|3|32"], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/multi_file/static.cc b/index_tests/multi_file/static.cc new file mode 100644 index 00000000..8ad0f72d --- /dev/null +++ b/index_tests/multi_file/static.cc @@ -0,0 +1,88 @@ +#include "static.h" + +void Buffer::CreateSharedBuffer() {} + +/* +OUTPUT: static.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 9411323049603567600, + "detailed_name": "Buffer", + "short_name": "Buffer", + "kind": 23, + "declarations": [], + "spell": "3:8-3:14|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 14576076421851654759, + "detailed_name": "void Buffer::CreateSharedBuffer()", + "short_name": "CreateSharedBuffer", + "kind": 254, + "storage": 3, + "declarations": [{ + "spell": "4:15-4:33|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +OUTPUT: static.cc +{ + "includes": [{ + "line": 0, + "resolved_path": "&static.h" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 9411323049603567600, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["3:6-3:12|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 14576076421851654759, + "detailed_name": "void Buffer::CreateSharedBuffer()", + "short_name": "CreateSharedBuffer", + "kind": 254, + "storage": 1, + "declarations": [], + "spell": "3:14-3:32|0|2|2", + "extent": "3:1-3:37|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ \ No newline at end of file diff --git a/index_tests/multi_file/static.h b/index_tests/multi_file/static.h new file mode 100644 index 00000000..4204f785 --- /dev/null +++ b/index_tests/multi_file/static.h @@ -0,0 +1,5 @@ +#pragma once + +struct Buffer { + static void CreateSharedBuffer(); +}; diff --git a/index_tests/namespaces/anonymous_function.cc b/index_tests/namespaces/anonymous_function.cc new file mode 100644 index 00000000..17905fe2 --- /dev/null +++ b/index_tests/namespaces/anonymous_function.cc @@ -0,0 +1,45 @@ +namespace { +void foo(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 7144845543074395457, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 5010253035933134245, + "detailed_name": "void (anon)::foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "2:6-2:9|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/function_declaration.cc b/index_tests/namespaces/function_declaration.cc new file mode 100644 index 00000000..7c6ba361 --- /dev/null +++ b/index_tests/namespaces/function_declaration.cc @@ -0,0 +1,61 @@ +namespace hello { +void foo(int a, int b); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 2029211996748007610, + "detailed_name": "hello", + "short_name": "hello", + "kind": 3, + "declarations": [], + "spell": "1:11-1:16|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["1:11-1:16|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 18343102288837190527, + "detailed_name": "void hello::foo(int a, int b)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "2:6-2:9|0|2|1", + "param_spellings": ["2:14-2:15", "2:21-2:22"] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/function_definition.cc b/index_tests/namespaces/function_definition.cc new file mode 100644 index 00000000..5ccd8254 --- /dev/null +++ b/index_tests/namespaces/function_definition.cc @@ -0,0 +1,60 @@ +namespace hello { +void foo() {} +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 2029211996748007610, + "detailed_name": "hello", + "short_name": "hello", + "kind": 3, + "declarations": [], + "spell": "1:11-1:16|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["1:11-1:16|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 243328841292951622, + "detailed_name": "void hello::foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "2:6-2:9|0|2|2", + "extent": "2:1-2:14|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/method_declaration.cc b/index_tests/namespaces/method_declaration.cc new file mode 100644 index 00000000..37687fd3 --- /dev/null +++ b/index_tests/namespaces/method_declaration.cc @@ -0,0 +1,79 @@ +namespace hello { +class Foo { + void foo(); +}; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 2029211996748007610, + "detailed_name": "hello", + "short_name": "hello", + "kind": 3, + "declarations": [], + "spell": "1:11-1:16|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:11-1:16|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 4508214972876735896, + "detailed_name": "hello::Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:7-2:10|0|2|2", + "extent": "2:1-4:2|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 10487325150128053272, + "detailed_name": "void hello::Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "3:8-3:11|2|2|1", + "param_spellings": [] + }], + "declaring_type": 2, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/method_definition.cc b/index_tests/namespaces/method_definition.cc new file mode 100644 index 00000000..4df6edf1 --- /dev/null +++ b/index_tests/namespaces/method_definition.cc @@ -0,0 +1,83 @@ +namespace hello { +class Foo { + void foo(); +}; + +void Foo::foo() {} +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 2029211996748007610, + "detailed_name": "hello", + "short_name": "hello", + "kind": 3, + "declarations": [], + "spell": "1:11-1:16|-1|1|2", + "extent": "1:1-7:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:11-1:16|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 4508214972876735896, + "detailed_name": "hello::Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:7-2:10|0|2|2", + "extent": "2:1-4:2|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["6:6-6:9|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 10487325150128053272, + "detailed_name": "void hello::Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "3:8-3:11|2|2|1", + "param_spellings": [] + }], + "spell": "6:11-6:14|2|2|2", + "extent": "6:1-6:19|0|2|0", + "declaring_type": 2, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/method_inline_declaration.cc b/index_tests/namespaces/method_inline_declaration.cc new file mode 100644 index 00000000..9d0b940f --- /dev/null +++ b/index_tests/namespaces/method_inline_declaration.cc @@ -0,0 +1,78 @@ +namespace hello { +class Foo { + void foo() {} +}; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 2029211996748007610, + "detailed_name": "hello", + "short_name": "hello", + "kind": 3, + "declarations": [], + "spell": "1:11-1:16|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:11-1:16|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 4508214972876735896, + "detailed_name": "hello::Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:7-2:10|0|2|2", + "extent": "2:1-4:2|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 10487325150128053272, + "detailed_name": "void hello::Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "3:8-3:11|2|2|2", + "extent": "3:3-3:16|2|2|0", + "declaring_type": 2, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/namespaces/namespace_alias.cc b/index_tests/namespaces/namespace_alias.cc new file mode 100644 index 00000000..9a92b808 --- /dev/null +++ b/index_tests/namespaces/namespace_alias.cc @@ -0,0 +1,171 @@ +namespace foo { + namespace bar { + namespace baz { + int qux = 42; + } + } +} + +namespace fbz = foo::bar::baz; + +void func() { + int a = foo::bar::baz::qux; + int b = fbz::qux; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 926793467007732869, + "detailed_name": "foo", + "short_name": "foo", + "kind": 3, + "declarations": [], + "spell": "1:11-1:14|-1|1|2", + "extent": "1:1-7:2|-1|1|0", + "bases": [1], + "derived": [2], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:11-1:14|-1|1|4", "9:17-9:20|-1|1|4", "12:11-12:14|0|3|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 17805385787823406700, + "detailed_name": "foo::bar", + "short_name": "bar", + "kind": 3, + "declarations": [], + "spell": "2:15-2:18|0|2|2", + "extent": "2:5-6:6|0|2|0", + "bases": [0], + "derived": [3], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:15-2:18|0|2|4", "9:22-9:25|-1|1|4", "12:16-12:19|0|3|4"] + }, { + "id": 3, + "usr": 14450849931009540802, + "detailed_name": "foo::bar::baz", + "short_name": "baz", + "kind": 3, + "declarations": [], + "spell": "3:20-3:23|2|2|2", + "extent": "3:10-5:11|2|2|0", + "bases": [2], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": ["3:20-3:23|2|2|4", "9:27-9:30|-1|1|4", "12:21-12:24|0|3|4"] + }, { + "id": 4, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2], + "uses": [] + }, { + "id": 5, + "usr": 11879713791858506216, + "detailed_name": "fbz", + "short_name": "fbz", + "kind": 0, + "declarations": [], + "spell": "9:11-9:14|-1|1|2", + "extent": "9:1-9:30|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["13:11-13:14|0|3|4"] + }], + "funcs": [{ + "id": 0, + "usr": 10818727483146447186, + "detailed_name": "void func()", + "short_name": "func", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "11:6-11:10|-1|1|2", + "extent": "11:1-14:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [1, 2], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 15042442838933090518, + "detailed_name": "int foo::bar::baz::qux", + "short_name": "qux", + "hover": "int foo::bar::baz::qux = 42", + "declarations": [], + "spell": "4:18-4:21|3|2|2", + "extent": "4:14-4:26|3|2|0", + "type": 4, + "uses": ["12:26-12:29|-1|1|4", "13:16-13:19|-1|1|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 107714981785063096, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = foo::bar::baz::qux", + "declarations": [], + "spell": "12:7-12:8|0|3|2", + "extent": "12:3-12:29|0|3|0", + "type": 4, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 1200087780658383286, + "detailed_name": "int b", + "short_name": "b", + "hover": "int b = fbz::qux", + "declarations": [], + "spell": "13:7-13:8|0|3|2", + "extent": "13:3-13:19|0|3|0", + "type": 4, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/namespaces/namespace_reference.cc b/index_tests/namespaces/namespace_reference.cc new file mode 100644 index 00000000..235ebaee --- /dev/null +++ b/index_tests/namespaces/namespace_reference.cc @@ -0,0 +1,123 @@ +namespace ns { + int Foo; + void Accept(int a) {} +} + +void Runner() { + ns::Accept(ns::Foo); + using namespace ns; + Accept(Foo); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "1:11-1:13|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [0], + "vars": [0], + "instances": [], + "uses": ["1:11-1:13|-1|1|4", "7:3-7:5|1|3|4", "7:14-7:16|1|3|4", "8:19-8:21|1|3|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17328473273923617489, + "detailed_name": "void ns::Accept(int a)", + "short_name": "Accept", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:8-3:14|0|2|2", + "extent": "3:3-3:24|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [1], + "uses": ["7:7-7:13|1|3|32", "9:3-9:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 631910859630953711, + "detailed_name": "void Runner()", + "short_name": "Runner", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "6:6-6:12|-1|1|2", + "extent": "6:1-10:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["7:7-7:13|0|3|32", "9:3-9:9|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 12898699035586282159, + "detailed_name": "int ns::Foo", + "short_name": "Foo", + "declarations": [], + "spell": "2:7-2:10|0|2|2", + "extent": "2:3-2:10|0|2|0", + "type": 2, + "uses": ["7:18-7:21|1|3|4", "9:10-9:13|1|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 7976909968919750794, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "3:19-3:20|0|3|2", + "extent": "3:15-3:20|0|3|0", + "type": 2, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ + + + diff --git a/index_tests/objective-c/class.m b/index_tests/objective-c/class.m new file mode 100644 index 00000000..4736cade --- /dev/null +++ b/index_tests/objective-c/class.m @@ -0,0 +1,184 @@ +@interface AClass + + (void)test; + - (void)anInstanceMethod; + @property (nonatomic) int aProp; +@end + +@implementation AClass ++ (void)test {} +- (void)anInstanceMethod {} +@end + +int main(void) +{ + AClass *instance = [AClass init]; + [instance anInstanceMethod]; + instance.aProp = 12; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11832280568361305387, + "detailed_name": "AClass", + "short_name": "AClass", + "kind": 7, + "spell": "7:17-7:23|-1|1|2", + "extent": "7:1-10:2|-1|1|0", + "parents": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["14:3-14:9|-1|1|4", "14:23-14:29|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "parents": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 12775970426728664910, + "detailed_name": "AClass::test", + "short_name": "test", + "kind": 17, + "storage": 0, + "declarations": [{ + "spelling": "2:11-2:15", + "extent": "2:3-2:16", + "content": "+ (void)test;", + "param_spellings": [] + }], + "spell": "8:9-8:13|-1|1|2", + "extent": "8:1-8:16|-1|1|0", + "base": [], + "derived": [], + "locals": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 4096877434426330804, + "detailed_name": "AClass::anInstanceMethod", + "short_name": "anInstanceMethod", + "kind": 16, + "storage": 0, + "declarations": [{ + "spelling": "3:11-3:27", + "extent": "3:3-3:28", + "content": "- (void)anInstanceMethod;", + "param_spellings": [] + }], + "spell": "9:9-9:25|-1|1|2", + "extent": "9:1-9:28|-1|1|0", + "base": [], + "derived": [], + "locals": [], + "uses": ["15:13-15:29|4|3|64"], + "callees": [] + }, { + "id": 2, + "usr": 12774569141855220778, + "detailed_name": "AClass::aProp", + "short_name": "aProp", + "kind": 16, + "storage": 0, + "declarations": [{ + "spelling": "0:0-0:0", + "extent": "4:29-4:34", + "content": "aProp", + "param_spellings": [] + }], + "extent": "4:29-4:34|-1|1|0", + "base": [], + "derived": [], + "locals": [], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 17992064398538597892, + "detailed_name": "AClass::setAProp:", + "short_name": "setAProp:", + "kind": 16, + "storage": 0, + "declarations": [{ + "spelling": "0:0-0:0", + "extent": "4:29-4:34", + "content": "aProp", + "param_spellings": ["4:29-4:34"] + }], + "extent": "4:29-4:34|-1|1|0", + "base": [], + "derived": [], + "locals": [], + "uses": ["0:0-0:0|4|3|64"], + "callees": [] + }, { + "id": 4, + "usr": 7033269674615638282, + "detailed_name": "int main()", + "short_name": "main", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "12:5-12:9|-1|1|2", + "extent": "12:1-17:2|-1|1|0", + "base": [], + "derived": [], + "locals": [], + "uses": [], + "callees": ["15:13-15:29|1|3|64", "0:0-0:0|3|3|64"] + }], + "vars": [{ + "id": 0, + "usr": 14842397373703114213, + "detailed_name": "int AClass::aProp", + "short_name": "aProp", + "declarations": ["4:29-4:34|-1|1|1"], + "type": 1, + "uses": ["16:12-16:17|4|3|4"], + "kind": 19, + "storage": 0 + }, { + "id": 1, + "usr": 17112602610366149042, + "detailed_name": "int AClass::_aProp", + "short_name": "_aProp", + "declarations": [], + "spell": "4:29-4:34|-1|1|2", + "extent": "4:29-4:34|-1|1|0", + "type": 1, + "uses": [], + "kind": 14, + "storage": 0 + }, { + "id": 2, + "usr": 6849095699869081177, + "detailed_name": "AClass *instance", + "short_name": "instance", + "hover": "AClass *instance = [AClass init]", + "declarations": [], + "spell": "14:11-14:19|4|3|2", + "extent": "14:3-14:35|4|3|2", + "type": 0, + "uses": ["15:4-15:12|4|3|4", "16:3-16:11|4|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/operators/operator.cc b/index_tests/operators/operator.cc new file mode 100644 index 00000000..dc8151b0 --- /dev/null +++ b/index_tests/operators/operator.cc @@ -0,0 +1,100 @@ +class Foo { + void operator()(int) { } + void operator()(bool); + int operator()(int a, int b); +}; + +Foo &operator += (const Foo&, const int&); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0, 1, 2], + "vars": [], + "instances": [], + "uses": ["7:1-7:4|-1|1|4", "7:25-7:28|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 7874436189163837815, + "detailed_name": "void Foo::operator()(int)", + "short_name": "operator()", + "kind": 6, + "storage": 1, + "declarations": [], + "spell": "2:8-2:18|0|2|2", + "extent": "2:3-2:27|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 3545323327609582678, + "detailed_name": "void Foo::operator()(bool)", + "short_name": "operator()", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "3:8-3:18|0|2|1", + "param_spellings": ["3:23-3:23"] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 3986818119971932909, + "detailed_name": "int Foo::operator()(int a, int b)", + "short_name": "operator()", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "4:7-4:17|0|2|1", + "param_spellings": ["4:22-4:23", "4:29-4:30"] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 8288368475529136092, + "detailed_name": "Foo &operator+=(const Foo &, const int &)", + "short_name": "operator+=", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "7:6-7:17|-1|1|1", + "param_spellings": ["7:29-7:29", "7:41-7:41"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/outline/outline.cc b/index_tests/outline/outline.cc new file mode 100644 index 00000000..08b07313 --- /dev/null +++ b/index_tests/outline/outline.cc @@ -0,0 +1,120 @@ +#include + +struct MergeableUpdate { + int a; + int b; + std::vector to_add; +}; + +/* +TEXT_REPLACE: +std::__1::vector <===> std::vector +c:@N@std@ST>2#T#T@vector <===> c:@N@std@N@__1@ST>2#T#T@vector +10956461108384510180 <===> 9178760565669096175 + +OUTPUT: +{ + "includes": [{ + "line": 0, + "resolved_path": "&vector" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 14399919566014425846, + "detailed_name": "MergeableUpdate", + "short_name": "MergeableUpdate", + "kind": 23, + "declarations": [], + "spell": "3:8-3:23|-1|1|2", + "extent": "3:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1, 2], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }, { + "id": 2, + "usr": 9178760565669096175, + "detailed_name": "std::vector", + "short_name": "vector", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["6:8-6:14|-1|1|4"] + }, { + "id": 3, + "usr": 5401847601697785946, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["6:3-6:6|0|2|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 11633578660978286467, + "detailed_name": "int MergeableUpdate::a", + "short_name": "a", + "declarations": [], + "spell": "4:7-4:8|0|2|2", + "extent": "4:3-4:8|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 14949552147532317793, + "detailed_name": "int MergeableUpdate::b", + "short_name": "b", + "declarations": [], + "spell": "5:7-5:8|0|2|2", + "extent": "5:3-5:8|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 9003350345237582363, + "detailed_name": "std::vector MergeableUpdate::to_add", + "short_name": "to_add", + "declarations": [], + "spell": "6:20-6:26|0|2|2", + "extent": "6:3-6:26|0|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/outline/outline2.cc b/index_tests/outline/outline2.cc new file mode 100644 index 00000000..c5a31861 --- /dev/null +++ b/index_tests/outline/outline2.cc @@ -0,0 +1,158 @@ +//#pragma once + +#include +#include + +struct CompilationEntry { + std::string directory; + std::string filename; + std::vector args; +}; + +std::vector LoadCompilationEntriesFromDirectory(const std::string& project_directory); + +/* +TEXT_REPLACE: +std::__1::vector <===> std::vector +std::__1::string <===> std::string +std::__cxx11::string <===> std::string +c:@N@std@string <===> c:@N@std@N@__1@T@string +c:@N@std@T@string <===> c:@N@std@N@__1@T@string +c:@N@std@N@__cxx11@T@string <===> c:@N@std@N@__1@T@string +c:@N@std@ST>2#T#T@vector <===> c:@N@std@N@__1@ST>2#T#T@vector +c:@F@LoadCompilationEntriesFromDirectory#&1$@N@std@N@__1@S@basic_string>#C#$@N@std@N@__1@S@char_traits>#C#$@N@std@N@__1@S@allocator>#C# <===> c:@F@LoadCompilationEntriesFromDirectory#&1$@N@std@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C# +c:@F@LoadCompilationEntriesFromDirectory#&1$@N@std@N@__cxx11@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C# <===> c:@F@LoadCompilationEntriesFromDirectory#&1$@N@std@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C# +4160338041907786 <===> 14151982074805896770 +7543170857910783654 <===> 14151982074805896770 +9802818309312685221 <===> 11244864715202245734 +7636646237071509980 <===> 14151982074805896770 +9178760565669096175 <===> 10956461108384510180 +10468929532989002392 <===> 11244864715202245734 +4160338041907786 <===> 14151982074805896770 +9802818309312685221 <===> 11244864715202245734 + +OUTPUT: +{ + "includes": [{ + "line": 2, + "resolved_path": "&string" + }, { + "line": 3, + "resolved_path": "&vector" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 4992269036372211530, + "detailed_name": "CompilationEntry", + "short_name": "CompilationEntry", + "kind": 23, + "declarations": [], + "spell": "6:8-6:24|-1|1|2", + "extent": "6:1-10:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1, 2], + "instances": [], + "uses": ["12:13-12:29|-1|1|4"] + }, { + "id": 1, + "usr": 14151982074805896770, + "detailed_name": "std::string", + "short_name": "string", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["7:8-7:14|-1|1|4", "8:8-8:14|-1|1|4", "9:20-9:26|-1|1|4", "12:78-12:84|-1|1|4"] + }, { + "id": 2, + "usr": 5401847601697785946, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:3-7:6|0|2|4", "8:3-8:6|0|2|4", "9:3-9:6|0|2|4", "9:15-9:18|0|2|4", "12:1-12:4|-1|1|4", "12:73-12:76|-1|1|4"] + }, { + "id": 3, + "usr": 10956461108384510180, + "detailed_name": "std::vector", + "short_name": "vector", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["9:8-9:14|-1|1|4", "12:6-12:12|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 11244864715202245734, + "detailed_name": "std::vector LoadCompilationEntriesFromDirectory(const std::string &project_directory)", + "short_name": "LoadCompilationEntriesFromDirectory", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "12:31-12:66|-1|1|1", + "param_spellings": ["12:86-12:103"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 1153224798516629792, + "detailed_name": "std::string CompilationEntry::directory", + "short_name": "directory", + "declarations": [], + "spell": "7:15-7:24|0|2|2", + "extent": "7:3-7:24|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 2255668374222866345, + "detailed_name": "std::string CompilationEntry::filename", + "short_name": "filename", + "declarations": [], + "spell": "8:15-8:23|0|2|2", + "extent": "8:3-8:23|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 12616880765274259414, + "detailed_name": "std::vector CompilationEntry::args", + "short_name": "args", + "declarations": [], + "spell": "9:28-9:32|0|2|2", + "extent": "9:3-9:32|0|2|0", + "type": 3, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/outline/static_function_in_type.cc b/index_tests/outline/static_function_in_type.cc new file mode 100644 index 00000000..2bcf1f76 --- /dev/null +++ b/index_tests/outline/static_function_in_type.cc @@ -0,0 +1,192 @@ +#include "static_function_in_type.h" + +namespace ns { +// static +void Foo::Register(Manager* m) { +} +} + +/* +OUTPUT: static_function_in_type.h +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "1:11-1:13|-1|1|2", + "extent": "1:1-9:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:11-1:13|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 1972401196751872203, + "detailed_name": "ns::Manager", + "short_name": "Manager", + "kind": 5, + "declarations": ["3:7-3:14|0|2|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["6:24-6:31|-1|1|4"] + }, { + "id": 3, + "usr": 17262466801709381811, + "detailed_name": "ns::Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "5:8-5:11|0|2|2", + "extent": "5:1-7:2|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17019747379608639279, + "detailed_name": "void ns::Foo::Register(ns::Manager *)", + "short_name": "Register", + "kind": 254, + "storage": 3, + "declarations": [{ + "spell": "6:15-6:23|3|2|1", + "param_spellings": ["6:32-6:32"] + }], + "declaring_type": 3, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +OUTPUT: static_function_in_type.cc +{ + "includes": [{ + "line": 0, + "resolved_path": "&static_function_in_type.h" + }], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "3:11-3:13|-1|1|2", + "extent": "3:1-7:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["3:11-3:13|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 17262466801709381811, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["5:6-5:9|-1|1|4"] + }, { + "id": 3, + "usr": 1972401196751872203, + "detailed_name": "ns::Manager", + "short_name": "Manager", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["5:20-5:27|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 17019747379608639279, + "detailed_name": "void ns::Foo::Register(ns::Manager *m)", + "short_name": "Register", + "kind": 254, + "storage": 1, + "declarations": [], + "spell": "5:11-5:19|2|2|2", + "extent": "5:1-6:2|0|2|0", + "declaring_type": 2, + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 9285345059965948351, + "detailed_name": "ns::Manager *m", + "short_name": "m", + "declarations": [], + "spell": "5:29-5:30|0|3|2", + "extent": "5:20-5:30|0|3|0", + "type": 3, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ \ No newline at end of file diff --git a/index_tests/outline/static_function_in_type.h b/index_tests/outline/static_function_in_type.h new file mode 100644 index 00000000..013aa70e --- /dev/null +++ b/index_tests/outline/static_function_in_type.h @@ -0,0 +1,9 @@ +namespace ns { + +class Manager; + +struct Foo { + static void Register(Manager*); +}; + +} // namespace ns \ No newline at end of file diff --git a/index_tests/preprocessor/include_guard.cc b/index_tests/preprocessor/include_guard.cc new file mode 100644 index 00000000..4ae27e17 --- /dev/null +++ b/index_tests/preprocessor/include_guard.cc @@ -0,0 +1,27 @@ +#ifndef FOO +#define FOO + +#endif + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 13076155634261037336, + "detailed_name": "FOO", + "short_name": "FOO", + "hover": "#define FOO", + "declarations": [], + "spell": "2:9-2:12|-1|1|2", + "extent": "2:9-2:12|-1|1|0", + "uses": [], + "kind": 255, + "storage": 0 + }] +} +*/ diff --git a/index_tests/preprocessor/skipped.cc b/index_tests/preprocessor/skipped.cc new file mode 100644 index 00000000..41cb3c34 --- /dev/null +++ b/index_tests/preprocessor/skipped.cc @@ -0,0 +1,25 @@ + +#ifdef FOOBAR +void hello(); +#endif + +#if false + + + +#endif + +#if defined(OS_FOO) + +#endif + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": ["2:1-4:7", "6:1-10:7", "12:1-14:7"], + "types": [], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/templates/func_specialized_template_param.cc b/index_tests/templates/func_specialized_template_param.cc new file mode 100644 index 00000000..cdcb516c --- /dev/null +++ b/index_tests/templates/func_specialized_template_param.cc @@ -0,0 +1,70 @@ +template +class Template {}; + +struct Foo { + void Bar(Template&); +}; + +void Foo::Bar(Template&) {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17107291254533526269, + "detailed_name": "Template", + "short_name": "Template", + "kind": 5, + "declarations": [], + "spell": "2:7-2:15|-1|1|2", + "extent": "2:1-2:18|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:12-5:20|-1|1|4", "8:15-8:23|-1|1|4"] + }, { + "id": 1, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "4:8-4:11|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["8:6-8:9|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 8412238651648388423, + "detailed_name": "void Foo::Bar(Template &)", + "short_name": "Bar", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "5:8-5:11|1|2|1", + "param_spellings": ["5:29-5:29"] + }], + "spell": "8:11-8:14|1|2|2", + "extent": "8:1-8:36|-1|1|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/templates/implicit_variable_instantiation.cc b/index_tests/templates/implicit_variable_instantiation.cc new file mode 100644 index 00000000..3301266f --- /dev/null +++ b/index_tests/templates/implicit_variable_instantiation.cc @@ -0,0 +1,155 @@ +namespace ns { + enum VarType {}; + + template + struct Holder { + static constexpr VarType static_var = (VarType)0x0; + }; + + template + const typename VarType Holder<_>::static_var; + + + int Foo = Holder::static_var; + int Foo2 = Holder::static_var; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "1:11-1:13|-1|1|2", + "extent": "1:1-15:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [1, 2], + "instances": [], + "uses": ["1:11-1:13|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 1532099849728741556, + "detailed_name": "ns::VarType", + "short_name": "VarType", + "kind": 10, + "declarations": [], + "spell": "2:8-2:15|0|2|2", + "extent": "2:3-2:18|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["6:22-6:29|-1|1|4", "6:44-6:51|-1|1|4", "10:18-10:25|-1|1|4"] + }, { + "id": 3, + "usr": 12688716854043726585, + "detailed_name": "ns::Holder", + "short_name": "Holder", + "kind": 5, + "declarations": [], + "spell": "5:10-5:16|0|2|2", + "extent": "5:3-7:4|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": ["10:26-10:32|-1|1|4", "13:13-13:19|-1|1|4", "14:14-14:20|-1|1|4"] + }, { + "id": 4, + "usr": 14511917000226829276, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["10:33-10:34|-1|1|4"] + }, { + "id": 5, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1, 2], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 4731849186641714451, + "detailed_name": "const ns::VarType ns::Holder::static_var", + "short_name": "static_var", + "hover": "const ns::VarType ns::Holder::static_var = (VarType)0x0", + "declarations": ["6:30-6:40|3|2|1"], + "spell": "10:37-10:47|3|2|2", + "extent": "9:3-10:47|0|2|0", + "type": 2, + "uses": ["13:26-13:36|-1|1|4", "14:27-14:37|-1|1|4"], + "kind": 8, + "storage": 1 + }, { + "id": 1, + "usr": 12898699035586282159, + "detailed_name": "int ns::Foo", + "short_name": "Foo", + "hover": "int ns::Foo = Holder::static_var", + "declarations": [], + "spell": "13:7-13:10|0|2|2", + "extent": "13:3-13:36|0|2|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 9008550860229740818, + "detailed_name": "int ns::Foo2", + "short_name": "Foo2", + "hover": "int ns::Foo2 = Holder::static_var", + "declarations": [], + "spell": "14:7-14:11|0|2|2", + "extent": "14:3-14:37|0|2|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/member_ref_in_template.cc b/index_tests/templates/member_ref_in_template.cc new file mode 100644 index 00000000..7044a041 --- /dev/null +++ b/index_tests/templates/member_ref_in_template.cc @@ -0,0 +1,107 @@ +template +struct C { + T x; + void bar(); +}; + +template +void foo() { + C d; + d.x; // spelling range is empty, use cursor extent for range + d.bar(); // spelling range is empty, use cursor extent for range + + auto e = new C; + e->x; // `x` seems not exposed by libclang + e->bar(); // `bar` seems not exposed by libclang +} + +/* +EXTRA_FLAGS: +-fms-extensions +-fms-compatibility +-fdelayed-template-parsing + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 8402783583255987702, + "detailed_name": "C", + "short_name": "C", + "kind": 5, + "declarations": [], + "spell": "2:8-2:9|-1|1|2", + "extent": "2:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [0], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 14750650276757822712, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "1:17-1:18|-1|1|2", + "extent": "1:11-1:18|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["3:3-3:4|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 8905286151237717330, + "detailed_name": "void C::bar()", + "short_name": "bar", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "4:8-4:11|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 6875364467121018690, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "8:6-8:9|-1|1|2", + "extent": "8:1-8:11|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 5866801090710377175, + "detailed_name": "T C::x", + "short_name": "x", + "declarations": [], + "spell": "3:5-3:6|0|2|2", + "extent": "3:3-3:6|0|2|0", + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/templates/namespace_template_class_template_func_usage_folded_into_one.cc b/index_tests/templates/namespace_template_class_template_func_usage_folded_into_one.cc new file mode 100644 index 00000000..c7e77d6e --- /dev/null +++ b/index_tests/templates/namespace_template_class_template_func_usage_folded_into_one.cc @@ -0,0 +1,125 @@ +namespace ns { + template + struct Foo { + template + static int foo() { + return 3; + } + }; + + int a = Foo::foo(); + int b = Foo::foo(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "1:11-1:13|-1|1|2", + "extent": "1:1-12:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [], + "uses": ["1:11-1:13|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 14042997404480181958, + "detailed_name": "ns::Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "3:10-3:13|0|2|2", + "extent": "3:3-8:4|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["10:11-10:14|-1|1|4", "11:11-11:14|-1|1|4"] + }, { + "id": 3, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 8221803074608342407, + "detailed_name": "int ns::Foo::foo()", + "short_name": "foo", + "kind": 254, + "storage": 3, + "declarations": [], + "spell": "5:16-5:19|2|2|2", + "extent": "5:5-7:6|2|2|0", + "declaring_type": 2, + "bases": [], + "derived": [], + "vars": [], + "uses": ["10:21-10:24|0|2|32", "11:22-11:25|0|2|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 15768138241775955040, + "detailed_name": "int ns::a", + "short_name": "a", + "hover": "int ns::a = Foo::foo()", + "declarations": [], + "spell": "10:7-10:8|0|2|2", + "extent": "10:3-10:33|0|2|0", + "type": 3, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 3182917058194750998, + "detailed_name": "int ns::b", + "short_name": "b", + "hover": "int ns::b = Foo::foo()", + "declarations": [], + "spell": "11:7-11:8|0|2|2", + "extent": "11:3-11:35|0|2|0", + "type": 3, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/namespace_template_type_usage_folded_into_one.cc b/index_tests/templates/namespace_template_type_usage_folded_into_one.cc new file mode 100644 index 00000000..61a53f89 --- /dev/null +++ b/index_tests/templates/namespace_template_type_usage_folded_into_one.cc @@ -0,0 +1,88 @@ +namespace ns { + template + class Foo {}; + + Foo a; + Foo b; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 11072669167287398027, + "detailed_name": "ns", + "short_name": "ns", + "kind": 3, + "declarations": [], + "spell": "1:11-1:13|-1|1|2", + "extent": "1:1-7:2|-1|1|0", + "bases": [1], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [], + "uses": ["1:11-1:13|-1|1|4"] + }, { + "id": 1, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [0], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 14042997404480181958, + "detailed_name": "ns::Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "3:9-3:12|0|2|2", + "extent": "3:3-3:15|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["5:3-5:6|-1|1|4", "6:3-6:6|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 15768138241775955040, + "detailed_name": "Foo ns::a", + "short_name": "a", + "declarations": [], + "spell": "5:12-5:13|0|2|2", + "extent": "5:3-5:13|0|2|0", + "type": 2, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 3182917058194750998, + "detailed_name": "Foo ns::b", + "short_name": "b", + "declarations": [], + "spell": "6:13-6:14|0|2|2", + "extent": "6:3-6:14|0|2|0", + "type": 2, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/specialization.cc b/index_tests/templates/specialization.cc new file mode 100644 index 00000000..5a545a48 --- /dev/null +++ b/index_tests/templates/specialization.cc @@ -0,0 +1,436 @@ +template +class function; + +template +class function {}; + +function f; + +template class allocator; + +template > +class vector { + void clear(); +}; + +template +class vector {}; + +struct Z1 {}; + +template class vector; + +struct Z2 {}; + +template<> +class vector { + void clear(); +}; + +vector vc; +vector vip; +vector vz1; +vector vz2; + +enum Enum { + Enum0, Enum1 +}; +template +void foo(T Value) {} + +static const int kOnst = 7; +template <> +void foo(float Value); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15019211479263750068, + "detailed_name": "function", + "short_name": "function", + "kind": 5, + "declarations": ["2:7-2:15|-1|1|1", "5:7-5:15|-1|1|4"], + "spell": "2:7-2:15|-1|1|2", + "extent": "1:1-2:15|-1|1|0", + "bases": [], + "derived": [1], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:1-7:9|-1|1|4"] + }, { + "id": 1, + "usr": 218068462278884837, + "detailed_name": "function", + "short_name": "function", + "kind": 5, + "declarations": [], + "spell": "5:7-5:15|-1|1|2", + "extent": "4:1-5:30|-1|1|0", + "bases": [0], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["7:1-7:9|-1|1|4"] + }, { + "id": 2, + "usr": 10862637711685426953, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "4:19-4:20|-1|1|2", + "extent": "4:10-4:20|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:16-5:17|-1|1|4"] + }, { + "id": 3, + "usr": 756188769017350739, + "detailed_name": "Args", + "short_name": "Args", + "kind": 26, + "declarations": [], + "spell": "4:34-4:38|-1|1|2", + "extent": "4:22-4:38|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:18-5:22|-1|1|4"] + }, { + "id": 4, + "usr": 15695704394170757108, + "detailed_name": "allocator", + "short_name": "allocator", + "kind": 5, + "declarations": ["9:28-9:37|-1|1|1", "11:39-11:48|-1|1|4"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 5, + "usr": 7440942986741176606, + "detailed_name": "vector", + "short_name": "vector", + "kind": 5, + "declarations": ["17:7-17:13|-1|1|4", "26:7-26:13|-1|1|4"], + "spell": "12:7-12:13|-1|1|2", + "extent": "12:1-14:2|-1|1|0", + "bases": [], + "derived": [6, 10], + "types": [], + "funcs": [0], + "vars": [], + "instances": [1, 3, 4], + "uses": ["30:1-30:7|-1|1|4", "31:1-31:7|-1|1|4", "32:1-32:7|-1|1|4", "33:1-33:7|-1|1|4"] + }, { + "id": 6, + "usr": 16155717907537731864, + "detailed_name": "vector", + "short_name": "vector", + "kind": 5, + "declarations": [], + "spell": "17:7-17:13|-1|1|2", + "extent": "16:1-17:20|-1|1|0", + "bases": [5], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["31:1-31:7|-1|1|4"] + }, { + "id": 7, + "usr": 3421332160420436276, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "16:19-16:20|-1|1|2", + "extent": "16:10-16:20|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["17:14-17:15|-1|1|4"] + }, { + "id": 8, + "usr": 5760043510674081814, + "detailed_name": "Z1", + "short_name": "Z1", + "kind": 23, + "declarations": [], + "spell": "19:8-19:10|-1|1|2", + "extent": "19:1-19:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["32:8-32:10|-1|1|4"] + }, { + "id": 9, + "usr": 10124869160135436852, + "detailed_name": "Z2", + "short_name": "Z2", + "kind": 23, + "declarations": ["26:14-26:16|-1|1|4"], + "spell": "23:8-23:10|-1|1|2", + "extent": "23:1-23:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["33:8-33:10|-1|1|4"] + }, { + "id": 10, + "usr": 1663022413889915338, + "detailed_name": "vector", + "short_name": "vector", + "kind": 5, + "declarations": [], + "spell": "26:7-26:13|-1|1|2", + "extent": "25:1-28:2|-1|1|0", + "bases": [5], + "derived": [], + "types": [], + "funcs": [1], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 11, + "usr": 9201299975592934124, + "detailed_name": "Enum", + "short_name": "Enum", + "kind": 10, + "declarations": [], + "spell": "35:6-35:10|-1|1|2", + "extent": "35:1-37:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 12, + "usr": 2461355892344618654, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "38:20-38:21|2|3|2", + "extent": "38:11-38:21|2|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["39:10-39:11|-1|1|4"] + }, { + "id": 13, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [8], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 18107614608385228556, + "detailed_name": "void vector::clear()", + "short_name": "clear", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "13:8-13:13|5|2|1", + "param_spellings": [] + }], + "declaring_type": 5, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 6113470698424012876, + "detailed_name": "void vector::clear()", + "short_name": "clear", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "27:8-27:13|10|2|1", + "param_spellings": [] + }], + "declaring_type": 10, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 17498190318698490707, + "detailed_name": "void foo(T Value)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "43:6-43:9|-1|1|1", + "param_spellings": ["43:44-43:49"] + }], + "spell": "39:6-39:9|-1|1|2", + "extent": "39:1-39:21|-1|1|0", + "bases": [], + "derived": [], + "vars": [7], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 2933643612409209903, + "detailed_name": "function f", + "short_name": "f", + "declarations": [], + "spell": "7:21-7:22|-1|1|2", + "extent": "7:1-7:22|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 5792869548777559988, + "detailed_name": "vector vc", + "short_name": "vc", + "declarations": [], + "spell": "30:14-30:16|-1|1|2", + "extent": "30:1-30:16|-1|1|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 86949563628772958, + "detailed_name": "vector vip", + "short_name": "vip", + "declarations": [], + "spell": "31:14-31:17|-1|1|2", + "extent": "31:1-31:17|-1|1|0", + "type": 6, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 3, + "usr": 3566687051827176322, + "detailed_name": "vector vz1", + "short_name": "vz1", + "declarations": [], + "spell": "32:12-32:15|-1|1|2", + "extent": "32:1-32:15|-1|1|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 4, + "usr": 15931696253641284761, + "detailed_name": "vector vz2", + "short_name": "vz2", + "declarations": [], + "spell": "33:12-33:15|-1|1|2", + "extent": "33:1-33:15|-1|1|0", + "type": 5, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 5, + "usr": 15477793821005285152, + "detailed_name": "Enum::Enum0", + "short_name": "Enum0", + "hover": "Enum::Enum0 = 0", + "declarations": [], + "spell": "36:3-36:8|11|2|2", + "extent": "36:3-36:8|11|2|0", + "type": 11, + "uses": ["43:20-43:25|-1|1|4"], + "kind": 22, + "storage": 0 + }, { + "id": 6, + "usr": 4917621020431490070, + "detailed_name": "Enum::Enum1", + "short_name": "Enum1", + "hover": "Enum::Enum1 = 1", + "declarations": [], + "spell": "36:10-36:15|11|2|2", + "extent": "36:10-36:15|11|2|0", + "type": 11, + "uses": [], + "kind": 22, + "storage": 0 + }, { + "id": 7, + "usr": 10307767688451422448, + "detailed_name": "T Value", + "short_name": "Value", + "declarations": [], + "spell": "39:12-39:17|2|3|2", + "extent": "39:10-39:17|2|3|0", + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 8, + "usr": 13914496963221806870, + "detailed_name": "const int kOnst", + "short_name": "kOnst", + "hover": "const int kOnst = 7", + "declarations": [], + "spell": "41:18-41:23|-1|1|2", + "extent": "41:1-41:27|-1|1|0", + "type": 13, + "uses": ["43:27-43:32|-1|1|4"], + "kind": 13, + "storage": 3 + }] +} +*/ diff --git a/index_tests/templates/specialized_func_definition.cc b/index_tests/templates/specialized_func_definition.cc new file mode 100644 index 00000000..e39308f9 --- /dev/null +++ b/index_tests/templates/specialized_func_definition.cc @@ -0,0 +1,81 @@ +template +class Template { + void Foo(); +}; + +template +void Template::Foo() {} + +template<> +void Template::Foo() {} + + +/* +// TODO: usage information on Template is bad. +// TODO: Foo() should have multiple definitions. + +EXTRA_FLAGS: +-fms-compatibility +-fdelayed-template-parsing + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17107291254533526269, + "detailed_name": "Template", + "short_name": "Template", + "kind": 5, + "declarations": [], + "spell": "2:7-2:15|-1|1|2", + "extent": "2:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["7:6-7:14|-1|1|4", "10:6-10:14|-1|1|4"] + }, { + "id": 1, + "usr": 17649312483543982122, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 11994188353303124840, + "detailed_name": "void Template::Foo()", + "short_name": "Foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "3:8-3:11|0|2|1", + "param_spellings": [] + }, { + "spell": "10:22-10:25|-1|1|1", + "param_spellings": [] + }], + "spell": "7:19-7:22|0|2|2", + "extent": "6:1-7:24|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/templates/template_class_func_usage_folded_into_one.cc b/index_tests/templates/template_class_func_usage_folded_into_one.cc new file mode 100644 index 00000000..733db96f --- /dev/null +++ b/index_tests/templates/template_class_func_usage_folded_into_one.cc @@ -0,0 +1,92 @@ +template +struct Foo { + static int foo() { + return 3; + } +}; + +int a = Foo::foo(); +int b = Foo::foo(); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:8-2:11|-1|1|2", + "extent": "2:1-6:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["8:9-8:12|-1|1|4", "9:9-9:12|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 8340731781048851399, + "detailed_name": "int Foo::foo()", + "short_name": "foo", + "kind": 254, + "storage": 3, + "declarations": [], + "spell": "3:14-3:17|0|2|2", + "extent": "3:3-5:4|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:19-8:22|-1|1|32", "9:20-9:23|-1|1|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = Foo::foo()", + "declarations": [], + "spell": "8:5-8:6|-1|1|2", + "extent": "8:1-8:24|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "int b", + "short_name": "b", + "hover": "int b = Foo::foo()", + "declarations": [], + "spell": "9:5-9:6|-1|1|2", + "extent": "9:1-9:25|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_class_template_func_usage_folded_into_one.cc b/index_tests/templates/template_class_template_func_usage_folded_into_one.cc new file mode 100644 index 00000000..7ee252b4 --- /dev/null +++ b/index_tests/templates/template_class_template_func_usage_folded_into_one.cc @@ -0,0 +1,93 @@ +template +struct Foo { + template + static int foo() { + return 3; + } +}; + +int a = Foo::foo(); +int b = Foo::foo(); + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:8-2:11|-1|1|2", + "extent": "2:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["9:9-9:12|-1|1|4", "10:9-10:12|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 9034026360701857235, + "detailed_name": "int Foo::foo()", + "short_name": "foo", + "kind": 254, + "storage": 3, + "declarations": [], + "spell": "4:14-4:17|0|2|2", + "extent": "4:3-6:4|0|2|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["9:19-9:22|-1|1|32", "10:20-10:23|-1|1|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = Foo::foo()", + "declarations": [], + "spell": "9:5-9:6|-1|1|2", + "extent": "9:1-9:31|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "int b", + "short_name": "b", + "hover": "int b = Foo::foo()", + "declarations": [], + "spell": "10:5-10:6|-1|1|2", + "extent": "10:1-10:33|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_class_type_usage_folded_into_one.cc b/index_tests/templates/template_class_type_usage_folded_into_one.cc new file mode 100644 index 00000000..c0b611ce --- /dev/null +++ b/index_tests/templates/template_class_type_usage_folded_into_one.cc @@ -0,0 +1,127 @@ +enum A {}; +enum B {}; + +template +struct Foo { + struct Inner {}; +}; + +Foo::Inner a; +Foo::Inner b; + +#if false +EnumDecl A +EnumDecl B +ClassTemplate Foo + TemplateTypeParameter T + StructDecl Inner +VarDecl a + TemplateRef Foo + TypeRef enum A + TypeRef struct Foo::Inner + CallExpr Inner +VarDecl b + TemplateRef Foo + TypeRef enum B + TypeRef struct Foo::Inner + CallExpr Inner +#endif + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": ["12:1-28:7"], + "types": [{ + "id": 0, + "usr": 6697181287623958829, + "detailed_name": "A", + "short_name": "A", + "kind": 10, + "declarations": [], + "spell": "1:6-1:7|-1|1|2", + "extent": "1:1-1:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["9:5-9:6|-1|1|4"] + }, { + "id": 1, + "usr": 13892793056005362145, + "detailed_name": "B", + "short_name": "B", + "kind": 10, + "declarations": [], + "spell": "2:6-2:7|-1|1|2", + "extent": "2:1-2:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["10:5-10:6|-1|1|4"] + }, { + "id": 2, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "5:8-5:11|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["9:1-9:4|-1|1|4", "10:1-10:4|-1|1|4"] + }, { + "id": 3, + "usr": 13938528237873543349, + "detailed_name": "Foo::Inner", + "short_name": "Inner", + "kind": 23, + "declarations": [], + "spell": "6:10-6:15|2|2|2", + "extent": "6:3-6:18|2|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["9:9-9:14|-1|1|4", "10:9-10:14|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "Foo::Inner a", + "short_name": "a", + "declarations": [], + "spell": "9:15-9:16|-1|1|2", + "extent": "9:1-9:16|-1|1|0", + "type": 3, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "Foo::Inner b", + "short_name": "b", + "declarations": [], + "spell": "10:15-10:16|-1|1|2", + "extent": "10:1-10:16|-1|1|0", + "type": 3, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_class_var_usage_folded_into_one.cc b/index_tests/templates/template_class_var_usage_folded_into_one.cc new file mode 100644 index 00000000..fa19a31d --- /dev/null +++ b/index_tests/templates/template_class_var_usage_folded_into_one.cc @@ -0,0 +1,85 @@ +template +struct Foo { + static constexpr int var = 3; +}; + +int a = Foo::var; +int b = Foo::var; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:8-2:11|-1|1|2", + "extent": "2:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["6:9-6:12|-1|1|4", "7:9-7:12|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 13545144895171991916, + "detailed_name": "const int Foo::var", + "short_name": "var", + "hover": "const int Foo::var = 3", + "declarations": ["3:24-3:27|0|2|1"], + "type": 1, + "uses": ["6:19-6:22|-1|1|4", "7:20-7:23|-1|1|4"], + "kind": 8, + "storage": 3 + }, { + "id": 1, + "usr": 16721564935990383768, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = Foo::var", + "declarations": [], + "spell": "6:5-6:6|-1|1|2", + "extent": "6:1-6:22|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 12028309045033782423, + "detailed_name": "int b", + "short_name": "b", + "hover": "int b = Foo::var", + "declarations": [], + "spell": "7:5-7:6|-1|1|2", + "extent": "7:1-7:23|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_func_usage_folded_into_one.cc b/index_tests/templates/template_func_usage_folded_into_one.cc new file mode 100644 index 00000000..79bca721 --- /dev/null +++ b/index_tests/templates/template_func_usage_folded_into_one.cc @@ -0,0 +1,76 @@ +template +static int foo() { + return 3; +} + +int a = foo(); +int b = foo(); + +// TODO: put template foo inside a namespace +// TODO: put template foo inside a template class inside a namespace + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 326583651986177228, + "detailed_name": "int foo()", + "short_name": "foo", + "kind": 12, + "storage": 3, + "declarations": [], + "spell": "2:12-2:15|-1|1|2", + "extent": "2:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:9-6:12|-1|1|32", "7:9-7:12|-1|1|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = foo()", + "declarations": [], + "spell": "6:5-6:6|-1|1|2", + "extent": "6:1-6:19|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "int b", + "short_name": "b", + "hover": "int b = foo()", + "declarations": [], + "spell": "7:5-7:6|-1|1|2", + "extent": "7:1-7:20|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_type_usage_folded_into_one.cc b/index_tests/templates/template_type_usage_folded_into_one.cc new file mode 100644 index 00000000..0cc76af9 --- /dev/null +++ b/index_tests/templates/template_type_usage_folded_into_one.cc @@ -0,0 +1,56 @@ +template +class Foo {}; + +Foo a; +Foo b; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "2:7-2:10|-1|1|2", + "extent": "2:1-2:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["4:1-4:4|-1|1|4", "5:1-5:4|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "Foo a", + "short_name": "a", + "declarations": [], + "spell": "4:10-4:11|-1|1|2", + "extent": "4:1-4:11|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 12028309045033782423, + "detailed_name": "Foo b", + "short_name": "b", + "declarations": [], + "spell": "5:11-5:12|-1|1|2", + "extent": "5:1-5:12|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/templates/template_var_usage_folded_into_one.cc b/index_tests/templates/template_var_usage_folded_into_one.cc new file mode 100644 index 00000000..8c8fed78 --- /dev/null +++ b/index_tests/templates/template_var_usage_folded_into_one.cc @@ -0,0 +1,125 @@ +enum A {}; +enum B {}; + +template +T var = T(); + +A a = var; +B b = var; + +// NOTE: libclang before 4.0 doesn't expose template usage on |var|. + +#if false +EnumDecl A +EnumDecl B +UnexposedDecl var +VarDecl a + UnexposedExpr var + UnexposedExpr var + DeclRefExpr var + TypeRef enum A +UnexposedDecl var +VarDecl b + UnexposedExpr var + UnexposedExpr var + DeclRefExpr var + TypeRef enum B +UnexposedDecl var +#endif + +/* +EXTRA_FLAGS: +-std=c++14 + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": ["12:1-28:7"], + "types": [{ + "id": 0, + "usr": 6697181287623958829, + "detailed_name": "A", + "short_name": "A", + "kind": 10, + "declarations": [], + "spell": "1:6-1:7|-1|1|2", + "extent": "1:1-1:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": ["7:1-7:2|-1|1|4", "7:11-7:12|-1|1|4"] + }, { + "id": 1, + "usr": 13892793056005362145, + "detailed_name": "B", + "short_name": "B", + "kind": 10, + "declarations": [], + "spell": "2:6-2:7|-1|1|2", + "extent": "2:1-2:10|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [2], + "uses": ["8:1-8:2|-1|1|4", "8:11-8:12|-1|1|4"] + }, { + "id": 2, + "usr": 8864163146308556810, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:1-5:2|-1|1|4", "5:9-5:10|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 8096973118640070624, + "detailed_name": "T var", + "short_name": "var", + "declarations": [], + "spell": "5:3-5:6|-1|1|2", + "extent": "5:1-5:12|-1|1|0", + "uses": ["7:7-7:10|-1|1|4", "8:7-8:10|-1|1|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 16721564935990383768, + "detailed_name": "A a", + "short_name": "a", + "hover": "A a = var", + "declarations": [], + "spell": "7:3-7:4|-1|1|2", + "extent": "7:1-7:13|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 2, + "usr": 12028309045033782423, + "detailed_name": "B b", + "short_name": "b", + "hover": "B b = var", + "declarations": [], + "spell": "8:3-8:4|-1|1|2", + "extent": "8:1-8:13|-1|1|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/types/anonymous_struct.cc b/index_tests/types/anonymous_struct.cc new file mode 100644 index 00000000..8a975693 --- /dev/null +++ b/index_tests/types/anonymous_struct.cc @@ -0,0 +1,109 @@ +union vector3 { + struct { float x, y, z; }; + float v[3]; +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17937907487590875128, + "detailed_name": "vector3", + "short_name": "vector3", + "kind": 23, + "declarations": [], + "spell": "1:7-1:14|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [3], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 1428566502523368801, + "detailed_name": "vector3::(anon struct)", + "short_name": "(anon struct)", + "kind": 23, + "declarations": [], + "spell": "2:3-2:9|0|2|2", + "extent": "2:3-2:28|0|2|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1, 2], + "instances": [], + "uses": [] + }, { + "id": 2, + "usr": 21, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2, 3], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 3348817847649945564, + "detailed_name": "float vector3::(anon struct)::x", + "short_name": "x", + "declarations": [], + "spell": "2:18-2:19|1|2|2", + "extent": "2:12-2:19|1|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 4821094820988543895, + "detailed_name": "float vector3::(anon struct)::y", + "short_name": "y", + "declarations": [], + "spell": "2:21-2:22|1|2|2", + "extent": "2:12-2:22|1|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 15292551660437765731, + "detailed_name": "float vector3::(anon struct)::z", + "short_name": "z", + "declarations": [], + "spell": "2:24-2:25|1|2|2", + "extent": "2:12-2:25|1|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 3, + "usr": 1963212417280098348, + "detailed_name": "float [3] vector3::v", + "short_name": "v", + "declarations": [], + "spell": "3:9-3:10|0|2|2", + "extent": "3:3-3:13|0|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/types/typedefs.cc b/index_tests/types/typedefs.cc new file mode 100644 index 00000000..b11c9eee --- /dev/null +++ b/index_tests/types/typedefs.cc @@ -0,0 +1,61 @@ +typedef int (func)(const int *a, const int *b); +static func g; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13838176792705659279, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 10383876566159302459, + "detailed_name": "func", + "short_name": "func", + "kind": 252, + "hover": "typedef int (func)(const int *a, const int *b)", + "declarations": [], + "spell": "1:14-1:18|-1|1|2", + "extent": "1:1-1:47|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["1:14-1:18|-1|1|4", "2:8-2:12|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 8105378401105136463, + "detailed_name": "func g", + "short_name": "g", + "kind": 12, + "storage": 3, + "declarations": [{ + "spell": "2:13-2:14|-1|1|1", + "param_spellings": ["2:13-2:13", "2:13-2:13"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ \ No newline at end of file diff --git a/index_tests/unions/union_decl.cc b/index_tests/unions/union_decl.cc new file mode 100644 index 00000000..e3e0c501 --- /dev/null +++ b/index_tests/unions/union_decl.cc @@ -0,0 +1,83 @@ +union Foo { + int a; + bool b; +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 8501689086387244262, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }, { + "id": 2, + "usr": 3, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 9529311430721959843, + "detailed_name": "int Foo::a", + "short_name": "a", + "declarations": [], + "spell": "2:7-2:8|0|2|2", + "extent": "2:3-2:8|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 8804696910588009104, + "detailed_name": "bool Foo::b", + "short_name": "b", + "declarations": [], + "spell": "3:8-3:9|0|2|2", + "extent": "3:3-3:9|0|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/unions/union_usage.cc b/index_tests/unions/union_usage.cc new file mode 100644 index 00000000..bdc57e03 --- /dev/null +++ b/index_tests/unions/union_usage.cc @@ -0,0 +1,120 @@ +union Foo { + int a : 5; + bool b : 3; +}; + +Foo f; + +void act(Foo*) { + f.a = 3; +} + +/* +// TODO: instantiations on Foo should include parameter? + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 8501689086387244262, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [2], + "uses": ["6:1-6:4|-1|1|4", "8:10-8:13|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }, { + "id": 2, + "usr": 3, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 13982179977217945200, + "detailed_name": "void act(Foo *)", + "short_name": "act", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "8:6-8:9|-1|1|2", + "extent": "8:1-10:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 9529311430721959843, + "detailed_name": "int Foo::a", + "short_name": "a", + "hover": "int Foo::a : 5", + "declarations": [], + "spell": "2:7-2:8|0|2|2", + "extent": "2:3-2:12|0|2|0", + "type": 1, + "uses": ["9:5-9:6|0|3|4"], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 8804696910588009104, + "detailed_name": "bool Foo::b", + "short_name": "b", + "hover": "bool Foo::b : 3", + "declarations": [], + "spell": "3:8-3:9|0|2|2", + "extent": "3:3-3:13|0|2|0", + "type": 2, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 2933643612409209903, + "detailed_name": "Foo f", + "short_name": "f", + "declarations": [], + "spell": "6:5-6:6|-1|1|2", + "extent": "6:1-6:6|-1|1|0", + "type": 0, + "uses": ["9:3-9:4|0|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/func_called_from_constructor.cc b/index_tests/usage/func_called_from_constructor.cc new file mode 100644 index 00000000..92cc9262 --- /dev/null +++ b/index_tests/usage/func_called_from_constructor.cc @@ -0,0 +1,70 @@ +void called() {} + +struct Foo { + Foo(); +}; + +Foo::Foo() { + called(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["4:3-4:6|-1|1|4", "7:6-7:9|-1|1|4"], + "spell": "3:8-3:11|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [1], + "vars": [], + "instances": [], + "uses": ["4:3-4:6|0|2|4", "7:6-7:9|-1|1|4", "7:1-7:4|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 468307235068920063, + "detailed_name": "void called()", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:12|-1|1|2", + "extent": "1:1-1:17|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:3-8:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 3385168158331140247, + "detailed_name": "void Foo::Foo()", + "short_name": "Foo", + "kind": 9, + "storage": 1, + "declarations": [{ + "spell": "4:3-4:6|0|2|1", + "param_spellings": [] + }], + "spell": "7:6-7:9|0|2|2", + "extent": "7:1-9:2|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["8:3-8:9|0|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/func_called_from_macro_argument.cc b/index_tests/usage/func_called_from_macro_argument.cc new file mode 100644 index 00000000..42adc325 --- /dev/null +++ b/index_tests/usage/func_called_from_macro_argument.cc @@ -0,0 +1,61 @@ +#define MACRO_CALL(e) e + +bool called(bool a, bool b); + +void caller() { + MACRO_CALL(called(true, true)); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 3787803219955606747, + "detailed_name": "bool called(bool a, bool b)", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "3:6-3:12|-1|1|1", + "param_spellings": ["3:18-3:19", "3:26-3:27"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:14-6:20|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 11404881820527069090, + "detailed_name": "void caller()", + "short_name": "caller", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:12|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["6:14-6:20|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 1290746656694198202, + "detailed_name": "MACRO_CALL", + "short_name": "MACRO_CALL", + "hover": "#define MACRO_CALL(e) e", + "declarations": [], + "spell": "1:9-1:19|-1|1|2", + "extent": "1:9-1:24|-1|1|0", + "uses": ["6:3-6:13|-1|1|4"], + "kind": 255, + "storage": 0 + }] +} +*/ \ No newline at end of file diff --git a/index_tests/usage/func_called_from_template.cc b/index_tests/usage/func_called_from_template.cc new file mode 100644 index 00000000..14e8e306 --- /dev/null +++ b/index_tests/usage/func_called_from_template.cc @@ -0,0 +1,69 @@ +void called(); + +template +void caller() { + called(); +} + +void foo() { + caller(); +} + +/* +// NOTE: without caller() instantation caller() is never visited so +// called() is never referenced. +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 468307235068920063, + "detailed_name": "void called()", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:12|-1|1|1", + "param_spellings": [] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["5:3-5:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 10177235824697315808, + "detailed_name": "void caller()", + "short_name": "caller", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "4:6-4:12|-1|1|2", + "extent": "4:1-6:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["9:3-9:9|2|3|32"], + "callees": ["5:3-5:9|0|3|32"] + }, { + "id": 2, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "8:6-8:9|-1|1|2", + "extent": "8:1-10:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["9:3-9:9|1|3|32"] + }], + "vars": [] +} +*/ \ No newline at end of file diff --git a/index_tests/usage/func_called_implicit_ctor.cc b/index_tests/usage/func_called_implicit_ctor.cc new file mode 100644 index 00000000..d22528e6 --- /dev/null +++ b/index_tests/usage/func_called_implicit_ctor.cc @@ -0,0 +1,83 @@ +struct Wrapper { + Wrapper(int i); +}; + +int called() { return 1; } + +Wrapper caller() { + return called(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13611487872560323389, + "detailed_name": "Wrapper", + "short_name": "Wrapper", + "kind": 23, + "declarations": ["2:3-2:10|-1|1|4"], + "spell": "1:8-1:15|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["2:3-2:10|0|2|4", "7:1-7:8|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 10544127002917214589, + "detailed_name": "void Wrapper::Wrapper(int i)", + "short_name": "Wrapper", + "kind": 9, + "storage": 1, + "declarations": [{ + "spell": "2:3-2:10|0|2|1", + "param_spellings": ["2:15-2:16"] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:10-8:18|2|3|288"], + "callees": [] + }, { + "id": 1, + "usr": 468307235068920063, + "detailed_name": "int called()", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:5-5:11|-1|1|2", + "extent": "5:1-5:27|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:10-8:16|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 11404881820527069090, + "detailed_name": "Wrapper caller()", + "short_name": "caller", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "7:9-7:15|-1|1|2", + "extent": "7:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["8:10-8:18|0|3|288", "8:10-8:16|1|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/func_usage_addr_func.cc b/index_tests/usage/func_usage_addr_func.cc new file mode 100644 index 00000000..6e5d8f31 --- /dev/null +++ b/index_tests/usage/func_usage_addr_func.cc @@ -0,0 +1,75 @@ +void consume(void (*)()) {} + +void used() {} + +void user() { + void (*x)() = &used; + consume(&used); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 12924914488846929470, + "detailed_name": "void consume(void (*)())", + "short_name": "consume", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:13|-1|1|2", + "extent": "1:1-1:28|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["7:3-7:10|2|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 5264867802674151787, + "detailed_name": "void used()", + "short_name": "used", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:10|-1|1|2", + "extent": "3:1-3:15|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:18-6:22|2|3|32", "7:12-7:16|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 9376923949268137283, + "detailed_name": "void user()", + "short_name": "user", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:10|-1|1|2", + "extent": "5:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["6:18-6:22|1|3|32", "6:18-6:22|1|3|32", "7:3-7:10|0|3|32", "7:12-7:16|1|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 13681544683892648258, + "detailed_name": "void (*)() x", + "short_name": "x", + "declarations": [], + "spell": "6:10-6:11|2|3|2", + "extent": "6:3-6:22|2|3|0", + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/func_usage_addr_method.cc b/index_tests/usage/func_usage_addr_method.cc new file mode 100644 index 00000000..faeec595 --- /dev/null +++ b/index_tests/usage/func_usage_addr_method.cc @@ -0,0 +1,78 @@ +struct Foo { + void Used(); +}; + +void user() { + auto x = &Foo::Used; +} + + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [], + "uses": ["6:13-6:16|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 18417145003926999463, + "detailed_name": "void Foo::Used()", + "short_name": "Used", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:12|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:18-6:22|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 9376923949268137283, + "detailed_name": "void user()", + "short_name": "user", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:10|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["6:18-6:22|0|3|32", "6:18-6:22|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 8436636043513449412, + "detailed_name": "void (Foo::*)() x", + "short_name": "x", + "declarations": [], + "spell": "6:8-6:9|1|3|2", + "extent": "6:3-6:22|1|3|0", + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/func_usage_call_func.cc b/index_tests/usage/func_usage_call_func.cc new file mode 100644 index 00000000..57410853 --- /dev/null +++ b/index_tests/usage/func_usage_call_func.cc @@ -0,0 +1,45 @@ +void called() {} +void caller() { + called(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 468307235068920063, + "detailed_name": "void called()", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:12|-1|1|2", + "extent": "1:1-1:17|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["3:3-3:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 11404881820527069090, + "detailed_name": "void caller()", + "short_name": "caller", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "2:6-2:12|-1|1|2", + "extent": "2:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["3:3-3:9|0|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/func_usage_call_method.cc b/index_tests/usage/func_usage_call_method.cc new file mode 100644 index 00000000..088a737a --- /dev/null +++ b/index_tests/usage/func_usage_call_method.cc @@ -0,0 +1,80 @@ +struct Foo { + void Used(); +}; + +void user() { + Foo* f = nullptr; + f->Used(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [0], + "uses": ["6:3-6:6|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 18417145003926999463, + "detailed_name": "void Foo::Used()", + "short_name": "Used", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:12|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["7:6-7:10|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 9376923949268137283, + "detailed_name": "void user()", + "short_name": "user", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:10|-1|1|2", + "extent": "5:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["7:6-7:10|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 3014406561587537195, + "detailed_name": "Foo *f", + "short_name": "f", + "hover": "Foo *f = nullptr", + "declarations": [], + "spell": "6:8-6:9|1|3|2", + "extent": "6:3-6:19|1|3|0", + "type": 0, + "uses": ["7:3-7:4|1|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/func_usage_class_inline_var_def.cc b/index_tests/usage/func_usage_class_inline_var_def.cc new file mode 100644 index 00000000..c3f1b85c --- /dev/null +++ b/index_tests/usage/func_usage_class_inline_var_def.cc @@ -0,0 +1,76 @@ +static int helper() { + return 5; +} + +class Foo { + int x = helper(); +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "5:7-5:10|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 9630503130605430498, + "detailed_name": "int helper()", + "short_name": "helper", + "kind": 12, + "storage": 3, + "declarations": [], + "spell": "1:12-1:18|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:11-6:17|0|2|32"], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 4220150017963593039, + "detailed_name": "int Foo::x", + "short_name": "x", + "hover": "int Foo::x = helper()", + "declarations": [], + "spell": "6:7-6:8|0|2|2", + "extent": "6:3-6:19|0|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/usage/func_usage_forward_decl_func.cc b/index_tests/usage/func_usage_forward_decl_func.cc new file mode 100644 index 00000000..caec7c49 --- /dev/null +++ b/index_tests/usage/func_usage_forward_decl_func.cc @@ -0,0 +1,46 @@ +void foo(); + +void usage() { + foo(); +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:9|-1|1|1", + "param_spellings": [] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["4:3-4:6|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 6767773193109753523, + "detailed_name": "void usage()", + "short_name": "usage", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:11|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["4:3-4:6|0|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/func_usage_forward_decl_method.cc b/index_tests/usage/func_usage_forward_decl_method.cc new file mode 100644 index 00000000..b34f9875 --- /dev/null +++ b/index_tests/usage/func_usage_forward_decl_method.cc @@ -0,0 +1,79 @@ +struct Foo { + void foo(); +}; + +void usage() { + Foo* f = nullptr; + f->foo(); +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [0], + "uses": ["6:3-6:6|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 17922201480358737771, + "detailed_name": "void Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:11|0|2|1", + "param_spellings": [] + }], + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [], + "uses": ["7:6-7:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 6767773193109753523, + "detailed_name": "void usage()", + "short_name": "usage", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:11|-1|1|2", + "extent": "5:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["7:6-7:9|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 12410753116854389823, + "detailed_name": "Foo *f", + "short_name": "f", + "hover": "Foo *f = nullptr", + "declarations": [], + "spell": "6:8-6:9|1|3|2", + "extent": "6:3-6:19|1|3|0", + "type": 0, + "uses": ["7:3-7:4|1|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/func_usage_template_func.cc b/index_tests/usage/func_usage_template_func.cc new file mode 100644 index 00000000..ddfe668a --- /dev/null +++ b/index_tests/usage/func_usage_template_func.cc @@ -0,0 +1,65 @@ +template +void accept(T); + +void foo() { + accept(1); + accept(true); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13420564603121289209, + "detailed_name": "T", + "short_name": "T", + "kind": 26, + "declarations": [], + "spell": "1:19-1:20|0|3|2", + "extent": "1:10-1:20|0|3|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:13-2:14|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 10585861037135727329, + "detailed_name": "void accept(T)", + "short_name": "accept", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "2:6-2:12|-1|1|1", + "param_spellings": ["2:14-2:14"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["5:3-5:9|1|3|32", "6:3-6:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "4:6-4:9|-1|1|2", + "extent": "4:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["5:3-5:9|0|3|32", "6:3-6:9|0|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/type_usage_as_template_parameter.cc b/index_tests/usage/type_usage_as_template_parameter.cc new file mode 100644 index 00000000..5752413b --- /dev/null +++ b/index_tests/usage/type_usage_as_template_parameter.cc @@ -0,0 +1,105 @@ +template +class unique_ptr {}; + +struct S {}; + +static unique_ptr f0; +static unique_ptr f1; + +unique_ptr* return_type() { + unique_ptr* local; + return nullptr; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 3286534761799572592, + "detailed_name": "unique_ptr", + "short_name": "unique_ptr", + "kind": 5, + "declarations": [], + "spell": "2:7-2:17|-1|1|2", + "extent": "2:1-2:20|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2], + "uses": ["6:8-6:18|-1|1|4", "7:8-7:18|-1|1|4", "9:1-9:11|-1|1|4", "10:3-10:13|-1|1|4"] + }, { + "id": 1, + "usr": 4750332761459066907, + "detailed_name": "S", + "short_name": "S", + "kind": 23, + "declarations": [], + "spell": "4:8-4:9|-1|1|2", + "extent": "4:1-4:12|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["7:19-7:20|-1|1|4", "9:12-9:13|-1|1|4", "10:14-10:15|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 16359708726068806331, + "detailed_name": "unique_ptr *return_type()", + "short_name": "return_type", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "9:16-9:27|-1|1|2", + "extent": "9:1-12:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [2], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 12857919739649552168, + "detailed_name": "unique_ptr f0", + "short_name": "f0", + "declarations": [], + "spell": "6:25-6:27|-1|1|2", + "extent": "6:1-6:27|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 3 + }, { + "id": 1, + "usr": 18075066956054788088, + "detailed_name": "unique_ptr f1", + "short_name": "f1", + "declarations": [], + "spell": "7:22-7:24|-1|1|2", + "extent": "7:1-7:24|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 3 + }, { + "id": 2, + "usr": 2462000803278878465, + "detailed_name": "unique_ptr *local", + "short_name": "local", + "declarations": [], + "spell": "10:18-10:23|0|3|2", + "extent": "10:3-10:23|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_as_template_parameter_complex.cc b/index_tests/usage/type_usage_as_template_parameter_complex.cc new file mode 100644 index 00000000..50e7690d --- /dev/null +++ b/index_tests/usage/type_usage_as_template_parameter_complex.cc @@ -0,0 +1,234 @@ +template +class unique_ptr; + +struct S1; +struct S2; + +#if false +VarDecl f + TemplateRef unique_ptr + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 + TypeRef struct S2 +#endif +extern unique_ptr, S2> f; + +#if false +FunctionDecl as_return_type + TemplateRef unique_ptr + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 + TypeRef struct S2 + ParmDecl + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 + CompoundStmt + ReturnStmt + UnexposedExpr + CXXNullPtrLiteralExpr +#endif +unique_ptr, S2>* as_return_type(unique_ptr*) { return nullptr; } + +#if false +FunctionDecl no_return_type + ParmDecl + CompoundStmt +#endif +void no_return_type(int) {} + +#if false +FunctionDecl empty + CompoundStmt + DeclStmt + VarDecl local + TemplateRef unique_ptr + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 + TypeRef struct S2 +#endif +void empty() { + unique_ptr, S2>* local; +} + +#if false +ClassDecl Foo + CXXMethod foo + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 +#endif +class Foo { + unique_ptr* foo(); +}; + +#if false +CXXMethod foo + TemplateRef unique_ptr + TypeRef struct S1 + TypeRef struct S2 + TypeRef class Foo + CompoundStmt + ReturnStmt + UnexposedExpr + CXXNullPtrLiteralExpr +#endif +unique_ptr* Foo::foo() { return nullptr; } + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": ["7:1-14:7", "17:1-32:7", "35:1-39:7", "42:1-52:7", "57:1-63:7", "68:1-78:7"], + "types": [{ + "id": 0, + "usr": 14209198335088845323, + "detailed_name": "unique_ptr", + "short_name": "unique_ptr", + "kind": 5, + "declarations": ["2:7-2:17|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["15:8-15:18|-1|1|4", "15:19-15:29|-1|1|4", "33:1-33:11|-1|1|4", "33:12-33:22|-1|1|4", "33:52-33:62|-1|1|4", "54:3-54:13|-1|1|4", "54:14-54:24|-1|1|4", "65:3-65:13|-1|1|4", "79:1-79:11|-1|1|4"] + }, { + "id": 1, + "usr": 4310164820010458371, + "detailed_name": "S1", + "short_name": "S1", + "kind": 23, + "declarations": ["4:8-4:10|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["15:30-15:32|-1|1|4", "33:23-33:25|-1|1|4", "33:63-33:65|-1|1|4", "54:25-54:27|-1|1|4", "65:14-65:16|-1|1|4", "79:12-79:14|-1|1|4"] + }, { + "id": 2, + "usr": 12728490517004312484, + "detailed_name": "S2", + "short_name": "S2", + "kind": 23, + "declarations": ["5:8-5:10|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["15:34-15:36|-1|1|4", "15:39-15:41|-1|1|4", "33:27-33:29|-1|1|4", "33:32-33:34|-1|1|4", "33:67-33:69|-1|1|4", "54:29-54:31|-1|1|4", "54:34-54:36|-1|1|4", "65:18-65:20|-1|1|4", "79:16-79:18|-1|1|4"] + }, { + "id": 3, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "64:7-64:10|-1|1|2", + "extent": "64:1-66:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [3], + "vars": [], + "instances": [], + "uses": ["79:21-79:24|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 1246637699196435450, + "detailed_name": "unique_ptr, S2> *as_return_type(unique_ptr *)", + "short_name": "as_return_type", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "33:37-33:51|-1|1|2", + "extent": "33:1-33:92|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 13067214284561914253, + "detailed_name": "void no_return_type(int)", + "short_name": "no_return_type", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "40:6-40:20|-1|1|2", + "extent": "40:1-40:28|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 18320186404467436976, + "detailed_name": "void empty()", + "short_name": "empty", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "53:6-53:11|-1|1|2", + "extent": "53:1-55:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [1], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 17922201480358737771, + "detailed_name": "unique_ptr *Foo::foo()", + "short_name": "foo", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "65:23-65:26|3|2|1", + "param_spellings": [] + }], + "spell": "79:26-79:29|3|2|2", + "extent": "79:1-79:51|-1|1|0", + "declaring_type": 3, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 2933643612409209903, + "detailed_name": "unique_ptr, S2> f", + "short_name": "f", + "declarations": ["15:43-15:44|-1|1|1"], + "type": 0, + "uses": [], + "kind": 13, + "storage": 2 + }, { + "id": 1, + "usr": 11547294959889394856, + "detailed_name": "unique_ptr, S2> *local", + "short_name": "local", + "declarations": [], + "spell": "54:39-54:44|2|3|2", + "extent": "54:3-54:44|2|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_as_template_parameter_simple.cc b/index_tests/usage/type_usage_as_template_parameter_simple.cc new file mode 100644 index 00000000..20ee51d3 --- /dev/null +++ b/index_tests/usage/type_usage_as_template_parameter_simple.cc @@ -0,0 +1,59 @@ +template +class unique_ptr {}; + +struct S; + +static unique_ptr foo; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 3286534761799572592, + "detailed_name": "unique_ptr", + "short_name": "unique_ptr", + "kind": 5, + "declarations": [], + "spell": "2:7-2:17|-1|1|2", + "extent": "2:1-2:20|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["6:8-6:18|-1|1|4"] + }, { + "id": 1, + "usr": 4750332761459066907, + "detailed_name": "S", + "short_name": "S", + "kind": 23, + "declarations": ["4:8-4:9|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["6:19-6:20|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 3398408600781120939, + "detailed_name": "unique_ptr foo", + "short_name": "foo", + "declarations": [], + "spell": "6:22-6:25|-1|1|2", + "extent": "6:1-6:25|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 3 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_extern.cc b/index_tests/usage/type_usage_declare_extern.cc new file mode 100644 index 00000000..a89d1064 --- /dev/null +++ b/index_tests/usage/type_usage_declare_extern.cc @@ -0,0 +1,39 @@ +struct T {}; + +extern T t; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 5673439900521455039, + "detailed_name": "T", + "short_name": "T", + "kind": 23, + "declarations": [], + "spell": "1:8-1:9|-1|1|2", + "extent": "1:1-1:12|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["3:8-3:9|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 1346710425945444872, + "detailed_name": "T t", + "short_name": "t", + "declarations": ["3:10-3:11|-1|1|1"], + "type": 0, + "uses": [], + "kind": 13, + "storage": 2 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_field.cc b/index_tests/usage/type_usage_declare_field.cc new file mode 100644 index 00000000..5876efe6 --- /dev/null +++ b/index_tests/usage/type_usage_declare_field.cc @@ -0,0 +1,88 @@ +struct ForwardType; +struct ImplementedType {}; + +struct Foo { + ForwardType* a; + ImplementedType b; +}; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13749354388332789217, + "detailed_name": "ForwardType", + "short_name": "ForwardType", + "kind": 23, + "declarations": ["1:8-1:19|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["5:3-5:14|-1|1|4"] + }, { + "id": 1, + "usr": 8508299082070213750, + "detailed_name": "ImplementedType", + "short_name": "ImplementedType", + "kind": 23, + "declarations": [], + "spell": "2:8-2:23|-1|1|2", + "extent": "2:1-2:26|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": ["6:3-6:18|-1|1|4"] + }, { + "id": 2, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "4:8-4:11|-1|1|2", + "extent": "4:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 14314859014962085433, + "detailed_name": "ForwardType *Foo::a", + "short_name": "a", + "declarations": [], + "spell": "5:16-5:17|2|2|2", + "extent": "5:3-5:17|2|2|0", + "type": 0, + "uses": [], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 14727441168849658842, + "detailed_name": "ImplementedType Foo::b", + "short_name": "b", + "declarations": [], + "spell": "6:19-6:20|2|2|2", + "extent": "6:3-6:20|2|2|0", + "type": 1, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_local.cc b/index_tests/usage/type_usage_declare_local.cc new file mode 100644 index 00000000..0503fbc6 --- /dev/null +++ b/index_tests/usage/type_usage_declare_local.cc @@ -0,0 +1,87 @@ +struct ForwardType; +struct ImplementedType {}; + +void Foo() { + ForwardType* a; + ImplementedType b; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13749354388332789217, + "detailed_name": "ForwardType", + "short_name": "ForwardType", + "kind": 23, + "declarations": ["1:8-1:19|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["5:3-5:14|-1|1|4"] + }, { + "id": 1, + "usr": 8508299082070213750, + "detailed_name": "ImplementedType", + "short_name": "ImplementedType", + "kind": 23, + "declarations": [], + "spell": "2:8-2:23|-1|1|2", + "extent": "2:1-2:26|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": ["6:3-6:18|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 4654328188330986029, + "detailed_name": "void Foo()", + "short_name": "Foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "4:6-4:9|-1|1|2", + "extent": "4:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 11033478034711123650, + "detailed_name": "ForwardType *a", + "short_name": "a", + "declarations": [], + "spell": "5:16-5:17|0|3|2", + "extent": "5:3-5:17|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 8949902309768550158, + "detailed_name": "ImplementedType b", + "short_name": "b", + "declarations": [], + "spell": "6:19-6:20|0|3|2", + "extent": "6:3-6:20|0|3|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_param.cc b/index_tests/usage/type_usage_declare_param.cc new file mode 100644 index 00000000..24fd0927 --- /dev/null +++ b/index_tests/usage/type_usage_declare_param.cc @@ -0,0 +1,84 @@ +struct ForwardType; +struct ImplementedType {}; + +void foo(ForwardType* f, ImplementedType a) {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13749354388332789217, + "detailed_name": "ForwardType", + "short_name": "ForwardType", + "kind": 23, + "declarations": ["1:8-1:19|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["4:10-4:21|-1|1|4"] + }, { + "id": 1, + "usr": 8508299082070213750, + "detailed_name": "ImplementedType", + "short_name": "ImplementedType", + "kind": 23, + "declarations": [], + "spell": "2:8-2:23|-1|1|2", + "extent": "2:1-2:26|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [1], + "uses": ["4:26-4:41|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 1699390678058422036, + "detailed_name": "void foo(ForwardType *f, ImplementedType a)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "4:6-4:9|-1|1|2", + "extent": "4:1-4:47|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 2584795197111552890, + "detailed_name": "ForwardType *f", + "short_name": "f", + "declarations": [], + "spell": "4:23-4:24|0|3|2", + "extent": "4:10-4:24|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 5136230284979460117, + "detailed_name": "ImplementedType a", + "short_name": "a", + "declarations": [], + "spell": "4:42-4:43|0|3|2", + "extent": "4:26-4:43|0|3|0", + "type": 1, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_param_prototype.cc b/index_tests/usage/type_usage_declare_param_prototype.cc new file mode 100644 index 00000000..711054df --- /dev/null +++ b/index_tests/usage/type_usage_declare_param_prototype.cc @@ -0,0 +1,64 @@ +struct Foo; + +void foo(Foo* f, Foo*); +void foo(Foo* f, Foo*) {} + +/* +// TODO: No interesting usage on prototype. But maybe that's ok! +// TODO: We should have the same variable declared for both prototype and +// declaration. So it should have a usage marker on both. Then we could +// rename parameters! + +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["1:8-1:11|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["3:10-3:13|-1|1|4", "3:18-3:21|-1|1|4", "4:10-4:13|-1|1|4", "4:18-4:21|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 8908726657907936744, + "detailed_name": "void foo(Foo *f, Foo *)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "3:6-3:9|-1|1|1", + "param_spellings": ["3:15-3:16", "3:22-3:22"] + }], + "spell": "4:6-4:9|-1|1|2", + "extent": "4:1-4:26|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 2161866804398917919, + "detailed_name": "Foo *f", + "short_name": "f", + "declarations": [], + "spell": "4:15-4:16|0|3|2", + "extent": "4:10-4:16|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_param_unnamed.cc b/index_tests/usage/type_usage_declare_param_unnamed.cc new file mode 100644 index 00000000..2af6a192 --- /dev/null +++ b/index_tests/usage/type_usage_declare_param_unnamed.cc @@ -0,0 +1,41 @@ +struct ForwardType; +void foo(ForwardType*) {} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13749354388332789217, + "detailed_name": "ForwardType", + "short_name": "ForwardType", + "kind": 23, + "declarations": ["1:8-1:19|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:10-2:21|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 15327735280790448926, + "detailed_name": "void foo(ForwardType *)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "2:6-2:9|-1|1|2", + "extent": "2:1-2:26|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/type_usage_declare_qualifiers.cc b/index_tests/usage/type_usage_declare_qualifiers.cc new file mode 100644 index 00000000..5c31c5e1 --- /dev/null +++ b/index_tests/usage/type_usage_declare_qualifiers.cc @@ -0,0 +1,122 @@ +struct Type {}; + +void foo(Type& a0, const Type& a1) { + Type a2; + Type* a3; + const Type* a4; + const Type* const a5 = nullptr; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13487927231218873822, + "detailed_name": "Type", + "short_name": "Type", + "kind": 23, + "declarations": [], + "spell": "1:8-1:12|-1|1|2", + "extent": "1:1-1:15|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2, 3, 4, 5], + "uses": ["3:10-3:14|-1|1|4", "3:26-3:30|-1|1|4", "4:3-4:7|-1|1|4", "5:3-5:7|-1|1|4", "6:9-6:13|-1|1|4", "7:9-7:13|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 16858540520096802573, + "detailed_name": "void foo(Type &a0, const Type &a1)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1, 2, 3, 4, 5], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 16414210592877294238, + "detailed_name": "Type &a0", + "short_name": "a0", + "declarations": [], + "spell": "3:16-3:18|0|3|2", + "extent": "3:10-3:18|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 11558141642862804306, + "detailed_name": "const Type &a1", + "short_name": "a1", + "declarations": [], + "spell": "3:32-3:34|0|3|2", + "extent": "3:20-3:34|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 2, + "usr": 1536316608590232194, + "detailed_name": "Type a2", + "short_name": "a2", + "declarations": [], + "spell": "4:8-4:10|0|3|2", + "extent": "4:3-4:10|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 3, + "usr": 316760354845869406, + "detailed_name": "Type *a3", + "short_name": "a3", + "declarations": [], + "spell": "5:9-5:11|0|3|2", + "extent": "5:3-5:11|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 4, + "usr": 12321730890779907974, + "detailed_name": "const Type *a4", + "short_name": "a4", + "declarations": [], + "spell": "6:15-6:17|0|3|2", + "extent": "6:3-6:17|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 5, + "usr": 4771437488905761633, + "detailed_name": "const Type *const a5", + "short_name": "a5", + "hover": "const Type *const a5 = nullptr", + "declarations": [], + "spell": "7:21-7:23|0|3|2", + "extent": "7:3-7:33|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/type_usage_declare_static.cc b/index_tests/usage/type_usage_declare_static.cc new file mode 100644 index 00000000..0e570fee --- /dev/null +++ b/index_tests/usage/type_usage_declare_static.cc @@ -0,0 +1,40 @@ +struct Type {}; +static Type t; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13487927231218873822, + "detailed_name": "Type", + "short_name": "Type", + "kind": 23, + "declarations": [], + "spell": "1:8-1:12|-1|1|2", + "extent": "1:1-1:15|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["2:8-2:12|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 6601831367240627080, + "detailed_name": "Type t", + "short_name": "t", + "declarations": [], + "spell": "2:13-2:14|-1|1|2", + "extent": "2:1-2:14|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 3 + }] +} +*/ diff --git a/index_tests/usage/type_usage_on_return_type.cc b/index_tests/usage/type_usage_on_return_type.cc new file mode 100644 index 00000000..cdd5c090 --- /dev/null +++ b/index_tests/usage/type_usage_on_return_type.cc @@ -0,0 +1,152 @@ +struct Type; + +Type* foo(); +Type* foo(); +Type* foo() { return nullptr; } + +class Foo { + Type* Get(int); + void Empty(); +}; + +Type* Foo::Get(int) { return nullptr; } +void Foo::Empty() {} + +extern const Type& external(); + +static Type* bar(); +static Type* bar() { return nullptr; } + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 13487927231218873822, + "detailed_name": "Type", + "short_name": "Type", + "kind": 23, + "declarations": ["1:8-1:12|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["3:1-3:5|-1|1|4", "4:1-4:5|-1|1|4", "5:1-5:5|-1|1|4", "8:3-8:7|-1|1|4", "12:1-12:5|-1|1|4", "15:14-15:18|-1|1|4", "17:8-17:12|-1|1|4", "18:8-18:12|-1|1|4"] + }, { + "id": 1, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "7:7-7:10|-1|1|2", + "extent": "7:1-10:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [1, 2], + "vars": [], + "instances": [], + "uses": ["12:7-12:10|-1|1|4", "13:6-13:9|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "Type *foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "3:7-3:10|-1|1|1", + "param_spellings": [] + }, { + "spell": "4:7-4:10|-1|1|1", + "param_spellings": [] + }], + "spell": "5:7-5:10|-1|1|2", + "extent": "5:1-5:32|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 13402221340333431092, + "detailed_name": "Type *Foo::Get(int)", + "short_name": "Get", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "8:9-8:12|1|2|1", + "param_spellings": ["8:16-8:16"] + }], + "spell": "12:12-12:15|1|2|2", + "extent": "12:1-12:40|-1|1|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 4240751906910175539, + "detailed_name": "void Foo::Empty()", + "short_name": "Empty", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "9:8-9:13|1|2|1", + "param_spellings": [] + }], + "spell": "13:11-13:16|1|2|2", + "extent": "13:1-13:21|-1|1|0", + "declaring_type": 1, + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 7746867874366499515, + "detailed_name": "const Type &external()", + "short_name": "external", + "kind": 12, + "storage": 2, + "declarations": [{ + "spell": "15:20-15:28|-1|1|1", + "param_spellings": [] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 4, + "usr": 18408440185620243373, + "detailed_name": "Type *bar()", + "short_name": "bar", + "kind": 12, + "storage": 3, + "declarations": [{ + "spell": "17:14-17:17|-1|1|1", + "param_spellings": [] + }], + "spell": "18:14-18:17|-1|1|2", + "extent": "18:1-18:39|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/type_usage_typedef_and_using.cc b/index_tests/usage/type_usage_typedef_and_using.cc new file mode 100644 index 00000000..a732a4f6 --- /dev/null +++ b/index_tests/usage/type_usage_typedef_and_using.cc @@ -0,0 +1,181 @@ +struct Foo; +using Foo1 = Foo*; +typedef Foo Foo2; +using Foo3 = Foo1; +using Foo4 = int; + +void accept(Foo*) {} +void accept1(Foo1*) {} +void accept2(Foo2*) {} +void accept3(Foo3*) {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["1:8-1:11|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:14-2:17|-1|1|4", "3:9-3:12|-1|1|4", "7:13-7:16|-1|1|4"] + }, { + "id": 1, + "usr": 1544499294580512394, + "detailed_name": "Foo1", + "short_name": "Foo1", + "kind": 252, + "hover": "using Foo1 = Foo*", + "declarations": [], + "spell": "2:7-2:11|-1|1|2", + "extent": "2:1-2:18|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:7-2:11|-1|1|4", "4:14-4:18|-1|1|4", "8:14-8:18|-1|1|4"] + }, { + "id": 2, + "usr": 15466821155413653804, + "detailed_name": "Foo2", + "short_name": "Foo2", + "kind": 252, + "hover": "typedef Foo Foo2", + "declarations": [], + "spell": "3:13-3:17|-1|1|2", + "extent": "3:1-3:17|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["3:13-3:17|-1|1|4", "9:14-9:18|-1|1|4"] + }, { + "id": 3, + "usr": 17897026942631673064, + "detailed_name": "Foo3", + "short_name": "Foo3", + "kind": 252, + "hover": "using Foo3 = Foo1", + "declarations": [], + "spell": "4:7-4:11|-1|1|2", + "extent": "4:1-4:18|-1|1|0", + "alias_of": 1, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:7-4:11|-1|1|4", "10:14-10:18|-1|1|4"] + }, { + "id": 4, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 5, + "usr": 2638219001294786365, + "detailed_name": "Foo4", + "short_name": "Foo4", + "kind": 252, + "hover": "using Foo4 = int", + "declarations": [], + "spell": "5:7-5:11|-1|1|2", + "extent": "5:1-5:17|-1|1|0", + "alias_of": 4, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:7-5:11|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 9119341505144503905, + "detailed_name": "void accept(Foo *)", + "short_name": "accept", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "7:6-7:12|-1|1|2", + "extent": "7:1-7:21|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 1, + "usr": 558620830317390922, + "detailed_name": "void accept1(Foo1 *)", + "short_name": "accept1", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "8:6-8:13|-1|1|2", + "extent": "8:1-8:23|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 2, + "usr": 10523262907746124479, + "detailed_name": "void accept2(Foo2 *)", + "short_name": "accept2", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "9:6-9:13|-1|1|2", + "extent": "9:1-9:23|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }, { + "id": 3, + "usr": 14986366321326974406, + "detailed_name": "void accept3(Foo3 *)", + "short_name": "accept3", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "10:6-10:13|-1|1|2", + "extent": "10:1-10:23|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/type_usage_typedef_and_using_template.cc b/index_tests/usage/type_usage_typedef_and_using_template.cc new file mode 100644 index 00000000..fb536eab --- /dev/null +++ b/index_tests/usage/type_usage_typedef_and_using_template.cc @@ -0,0 +1,66 @@ +template +struct Foo; + +using Foo1 = Foo; +typedef Foo Foo2; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 10528472276654770367, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": ["2:8-2:11|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:14-4:17|-1|1|4", "5:9-5:12|-1|1|4"] + }, { + "id": 1, + "usr": 1544499294580512394, + "detailed_name": "Foo1", + "short_name": "Foo1", + "kind": 252, + "hover": "using Foo1 = Foo", + "declarations": [], + "spell": "4:7-4:11|-1|1|2", + "extent": "4:1-4:22|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["4:7-4:11|-1|1|4", "5:13-5:17|-1|1|4"] + }, { + "id": 2, + "usr": 15933698173231330933, + "detailed_name": "Foo2", + "short_name": "Foo2", + "kind": 252, + "hover": "typedef Foo Foo2", + "declarations": [], + "spell": "5:19-5:23|-1|1|2", + "extent": "5:1-5:23|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["5:19-5:23|-1|1|4"] + }], + "funcs": [], + "vars": [] +} +*/ diff --git a/index_tests/usage/type_usage_various.cc b/index_tests/usage/type_usage_various.cc new file mode 100644 index 00000000..ba72ffad --- /dev/null +++ b/index_tests/usage/type_usage_various.cc @@ -0,0 +1,78 @@ +class Foo { + Foo* make(); +}; + +Foo* Foo::make() { + Foo f; + return nullptr; +} + +extern Foo foo; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [0], + "vars": [], + "instances": [0, 1], + "uses": ["2:3-2:6|-1|1|4", "5:1-5:4|-1|1|4", "5:6-5:9|-1|1|4", "6:3-6:6|-1|1|4", "10:8-10:11|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 9488177941273031343, + "detailed_name": "Foo *Foo::make()", + "short_name": "make", + "kind": 6, + "storage": 1, + "declarations": [{ + "spell": "2:8-2:12|0|2|1", + "param_spellings": [] + }], + "spell": "5:11-5:15|0|2|2", + "extent": "5:1-8:2|-1|1|0", + "declaring_type": 0, + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 14873619387499024780, + "detailed_name": "Foo f", + "short_name": "f", + "declarations": [], + "spell": "6:7-6:8|0|3|2", + "extent": "6:3-6:8|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 14455976355866885943, + "detailed_name": "Foo foo", + "short_name": "foo", + "declarations": ["10:12-10:15|-1|1|1"], + "type": 0, + "uses": [], + "kind": 13, + "storage": 2 + }] +} +*/ diff --git a/index_tests/usage/usage_inside_of_call.cc b/index_tests/usage/usage_inside_of_call.cc new file mode 100644 index 00000000..2bec1cb6 --- /dev/null +++ b/index_tests/usage/usage_inside_of_call.cc @@ -0,0 +1,141 @@ +void called(int a); + +int gen(); + +struct Foo { + static int static_var; + int field_var; +}; + +int Foo::static_var = 0; + +void foo() { + int a = 5; + called(a + gen() + Foo().field_var + Foo::static_var); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "5:8-5:11|-1|1|2", + "extent": "5:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [1, 0], + "instances": [], + "uses": ["10:5-10:8|-1|1|4", "14:22-14:25|-1|1|4", "14:40-14:43|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1, 2], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 18319417758892371313, + "detailed_name": "void called(int a)", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:12|-1|1|1", + "param_spellings": ["1:17-1:18"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["14:3-14:9|2|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 11404602816585117695, + "detailed_name": "int gen()", + "short_name": "gen", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "3:5-3:8|-1|1|1", + "param_spellings": [] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["14:14-14:17|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "12:6-12:9|-1|1|2", + "extent": "12:1-15:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [2], + "uses": [], + "callees": ["14:3-14:9|0|3|32", "14:14-14:17|1|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 11489549839875479478, + "detailed_name": "int Foo::static_var", + "short_name": "static_var", + "hover": "int Foo::static_var = 0", + "declarations": ["6:14-6:24|0|2|1"], + "spell": "10:10-10:20|0|2|2", + "extent": "10:1-10:24|-1|1|0", + "type": 1, + "uses": ["14:45-14:55|2|3|4"], + "kind": 8, + "storage": 1 + }, { + "id": 1, + "usr": 9648311402855509901, + "detailed_name": "int Foo::field_var", + "short_name": "field_var", + "declarations": [], + "spell": "7:7-7:16|0|2|2", + "extent": "7:3-7:16|0|2|0", + "type": 1, + "uses": ["14:28-14:37|2|3|4"], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 13284113377394221067, + "detailed_name": "int a", + "short_name": "a", + "hover": "int a = 5", + "declarations": [], + "spell": "13:7-13:8|2|3|2", + "extent": "13:3-13:12|2|3|0", + "type": 1, + "uses": ["14:10-14:11|2|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/usage_inside_of_call_simple.cc b/index_tests/usage/usage_inside_of_call_simple.cc new file mode 100644 index 00000000..b5336d11 --- /dev/null +++ b/index_tests/usage/usage_inside_of_call_simple.cc @@ -0,0 +1,64 @@ +void called(int a); + +int gen() { return 1; } + +void foo() { + called(gen() * gen()); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 18319417758892371313, + "detailed_name": "void called(int a)", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "1:6-1:12|-1|1|1", + "param_spellings": ["1:17-1:18"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:3-6:9|2|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 11404602816585117695, + "detailed_name": "int gen()", + "short_name": "gen", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:5-3:8|-1|1|2", + "extent": "3:1-3:24|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["6:10-6:13|2|3|32", "6:18-6:21|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "5:6-5:9|-1|1|2", + "extent": "5:1-7:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["6:3-6:9|0|3|32", "6:10-6:13|1|3|32", "6:18-6:21|1|3|32"] + }], + "vars": [] +} +*/ diff --git a/index_tests/usage/var_usage_call_function.cc b/index_tests/usage/var_usage_call_function.cc new file mode 100644 index 00000000..e5cbf423 --- /dev/null +++ b/index_tests/usage/var_usage_call_function.cc @@ -0,0 +1,60 @@ +void called() {} + +void caller() { + auto x = &called; + x(); + + called(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 468307235068920063, + "detailed_name": "void called()", + "short_name": "called", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:12|-1|1|2", + "extent": "1:1-1:17|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": ["4:13-4:19|1|3|32", "7:3-7:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 11404881820527069090, + "detailed_name": "void caller()", + "short_name": "caller", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:12|-1|1|2", + "extent": "3:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": ["4:13-4:19|0|3|32", "4:13-4:19|0|3|32", "7:3-7:9|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 3510529098767253033, + "detailed_name": "void (*)() x", + "short_name": "x", + "declarations": [], + "spell": "4:8-4:9|1|3|2", + "extent": "4:3-4:19|1|3|0", + "uses": ["5:3-5:4|1|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_class_member.cc b/index_tests/usage/var_usage_class_member.cc new file mode 100644 index 00000000..37a09761 --- /dev/null +++ b/index_tests/usage/var_usage_class_member.cc @@ -0,0 +1,142 @@ +class Foo { +public: + int x; + int y; +}; + +void accept(int); +void accept(int*); + +void foo() { + Foo f; + f.x = 3; + f.x += 5; + accept(f.x); + accept(f.x + 20); + accept(&f.x); + accept(f.y); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0, 1], + "instances": [2], + "uses": ["11:3-11:6|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17175780305784503374, + "detailed_name": "void accept(int)", + "short_name": "accept", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "7:6-7:12|-1|1|1", + "param_spellings": ["7:16-7:16"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["14:3-14:9|2|3|32", "15:3-15:9|2|3|32", "17:3-17:9|2|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 12086644540399881766, + "detailed_name": "void accept(int *)", + "short_name": "accept", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "8:6-8:12|-1|1|1", + "param_spellings": ["8:17-8:17"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["16:3-16:9|2|3|32"], + "callees": [] + }, { + "id": 2, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "10:6-10:9|-1|1|2", + "extent": "10:1-18:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [2], + "uses": [], + "callees": ["14:3-14:9|0|3|32", "15:3-15:9|0|3|32", "16:3-16:9|1|3|32", "17:3-17:9|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 4220150017963593039, + "detailed_name": "int Foo::x", + "short_name": "x", + "declarations": [], + "spell": "3:7-3:8|0|2|2", + "extent": "3:3-3:8|0|2|0", + "type": 1, + "uses": ["12:5-12:6|2|3|4", "13:5-13:6|2|3|4", "14:12-14:13|2|3|4", "15:12-15:13|2|3|4", "16:13-16:14|2|3|4"], + "kind": 8, + "storage": 0 + }, { + "id": 1, + "usr": 3873837747174060388, + "detailed_name": "int Foo::y", + "short_name": "y", + "declarations": [], + "spell": "4:7-4:8|0|2|2", + "extent": "4:3-4:8|0|2|0", + "type": 1, + "uses": ["17:12-17:13|2|3|4"], + "kind": 8, + "storage": 0 + }, { + "id": 2, + "usr": 16303259148898744165, + "detailed_name": "Foo f", + "short_name": "f", + "declarations": [], + "spell": "11:7-11:8|2|3|2", + "extent": "11:3-11:8|2|3|0", + "type": 0, + "uses": ["12:3-12:4|2|3|4", "13:3-13:4|2|3|4", "14:10-14:11|2|3|4", "15:10-15:11|2|3|4", "16:11-16:12|2|3|4", "17:10-17:11|2|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_class_member_static.cc b/index_tests/usage/var_usage_class_member_static.cc new file mode 100644 index 00000000..1ad13233 --- /dev/null +++ b/index_tests/usage/var_usage_class_member_static.cc @@ -0,0 +1,91 @@ +struct Foo { + static int x; +}; + +void accept(int); + +void foo() { + accept(Foo::x); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": [], + "spell": "1:8-1:11|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["8:10-8:13|-1|1|4"] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 17175780305784503374, + "detailed_name": "void accept(int)", + "short_name": "accept", + "kind": 12, + "storage": 1, + "declarations": [{ + "spell": "5:6-5:12|-1|1|1", + "param_spellings": ["5:16-5:16"] + }], + "bases": [], + "derived": [], + "vars": [], + "uses": ["8:3-8:9|1|3|32"], + "callees": [] + }, { + "id": 1, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "7:6-7:9|-1|1|2", + "extent": "7:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": ["8:3-8:9|0|3|32"] + }], + "vars": [{ + "id": 0, + "usr": 8599782646965457351, + "detailed_name": "int Foo::x", + "short_name": "x", + "declarations": ["2:14-2:15|0|2|1"], + "type": 1, + "uses": ["8:15-8:16|1|3|4"], + "kind": 8, + "storage": 3 + }] +} +*/ diff --git a/index_tests/usage/var_usage_cstyle_cast.cc b/index_tests/usage/var_usage_cstyle_cast.cc new file mode 100644 index 00000000..ecf60930 --- /dev/null +++ b/index_tests/usage/var_usage_cstyle_cast.cc @@ -0,0 +1,133 @@ +enum VarType {}; + +struct Holder { + static constexpr VarType static_var = (VarType)0x0; +}; + +const VarType Holder::static_var; + + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 5792006888140599735, + "detailed_name": "VarType", + "short_name": "VarType", + "kind": 10, + "declarations": [], + "spell": "1:6-1:13|-1|1|2", + "extent": "1:1-1:16|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["4:20-4:27|-1|1|4", "4:42-4:49|-1|1|4", "7:7-7:14|-1|1|4"] + }, { + "id": 1, + "usr": 10028537921178202800, + "detailed_name": "Holder", + "short_name": "Holder", + "kind": 23, + "declarations": [], + "spell": "3:8-3:14|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [], + "uses": ["7:15-7:21|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 7057400933868440116, + "detailed_name": "const VarType Holder::static_var", + "short_name": "static_var", + "hover": "const VarType Holder::static_var = (VarType)0x0", + "declarations": ["4:28-4:38|1|2|1"], + "spell": "7:23-7:33|1|2|2", + "extent": "7:1-7:33|-1|1|0", + "type": 0, + "uses": [], + "kind": 8, + "storage": 1 + }] +} +*/ + + + + + + + + + + + + + + + + + + + + + + + + + +//#include +//#include + +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include diff --git a/index_tests/usage/var_usage_extern.cc b/index_tests/usage/var_usage_extern.cc new file mode 100644 index 00000000..412c8551 --- /dev/null +++ b/index_tests/usage/var_usage_extern.cc @@ -0,0 +1,54 @@ +extern int a; + +void foo() { + a = 5; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 16721564935990383768, + "detailed_name": "int a", + "short_name": "a", + "declarations": ["1:12-1:13|-1|1|1"], + "type": 0, + "uses": ["4:3-4:4|0|3|4"], + "kind": 13, + "storage": 2 + }] +} +*/ diff --git a/index_tests/usage/var_usage_func_parameter.cc b/index_tests/usage/var_usage_func_parameter.cc new file mode 100644 index 00000000..26341c49 --- /dev/null +++ b/index_tests/usage/var_usage_func_parameter.cc @@ -0,0 +1,54 @@ +void foo(int a) { + a += 10; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 11998306017310352355, + "detailed_name": "void foo(int a)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 10063793875496522529, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "1:14-1:15|0|3|2", + "extent": "1:10-1:15|0|3|0", + "type": 0, + "uses": ["2:3-2:4|0|3|4"], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_local.cc b/index_tests/usage/var_usage_local.cc new file mode 100644 index 00000000..f9c0124e --- /dev/null +++ b/index_tests/usage/var_usage_local.cc @@ -0,0 +1,55 @@ +void foo() { + int x; + x = 3; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-4:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 8534460107894911680, + "detailed_name": "int x", + "short_name": "x", + "declarations": [], + "spell": "2:7-2:8|0|3|2", + "extent": "2:3-2:8|0|3|0", + "type": 0, + "uses": ["3:3-3:4|0|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_shadowed_local.cc b/index_tests/usage/var_usage_shadowed_local.cc new file mode 100644 index 00000000..db857206 --- /dev/null +++ b/index_tests/usage/var_usage_shadowed_local.cc @@ -0,0 +1,72 @@ +void foo() { + int a; + a = 1; + { + int a; + a = 2; + } + a = 3; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 17941402366659878910, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "2:7-2:8|0|3|2", + "extent": "2:3-2:8|0|3|0", + "type": 0, + "uses": ["3:3-3:4|0|3|4", "8:3-8:4|0|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 11094102496276744608, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "5:9-5:10|0|3|2", + "extent": "5:5-5:10|0|3|0", + "type": 0, + "uses": ["6:5-6:6|0|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_shadowed_parameter.cc b/index_tests/usage/var_usage_shadowed_parameter.cc new file mode 100644 index 00000000..e5c784ac --- /dev/null +++ b/index_tests/usage/var_usage_shadowed_parameter.cc @@ -0,0 +1,72 @@ +void foo(int a) { + a = 1; + { + int a; + a = 2; + } + a = 3; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 11998306017310352355, + "detailed_name": "void foo(int a)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-8:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 11608231465452906059, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "1:14-1:15|0|3|2", + "extent": "1:10-1:15|0|3|0", + "type": 0, + "uses": ["2:3-2:4|0|3|4", "7:3-7:4|0|3|4"], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 8011559936501990179, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "4:9-4:10|0|3|2", + "extent": "4:5-4:10|0|3|0", + "type": 0, + "uses": ["5:5-5:6|0|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/usage/var_usage_static.cc b/index_tests/usage/var_usage_static.cc new file mode 100644 index 00000000..ab456631 --- /dev/null +++ b/index_tests/usage/var_usage_static.cc @@ -0,0 +1,57 @@ +static int a; + +void foo() { + a = 3; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 11823161916242867318, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "1:12-1:13|-1|1|2", + "extent": "1:1-1:13|-1|1|0", + "type": 0, + "uses": ["4:3-4:4|0|3|4"], + "kind": 13, + "storage": 3 + }] +} +*/ diff --git a/index_tests/vars/class_member.cc b/index_tests/vars/class_member.cc new file mode 100644 index 00000000..cf676c63 --- /dev/null +++ b/index_tests/vars/class_member.cc @@ -0,0 +1,41 @@ +class Foo { + Foo* member; +}; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [0], + "uses": ["2:3-2:6|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 13799811842374292251, + "detailed_name": "Foo *Foo::member", + "short_name": "member", + "declarations": [], + "spell": "2:8-2:14|0|2|2", + "extent": "2:3-2:14|0|2|0", + "type": 0, + "uses": [], + "kind": 8, + "storage": 0 + }] +} +*/ diff --git a/index_tests/vars/class_static_member.cc b/index_tests/vars/class_static_member.cc new file mode 100644 index 00000000..6b5d1208 --- /dev/null +++ b/index_tests/vars/class_static_member.cc @@ -0,0 +1,44 @@ +class Foo { + static Foo* member; +}; +Foo* Foo::member = nullptr; + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [0], + "instances": [0], + "uses": ["2:10-2:13|-1|1|4", "4:1-4:4|-1|1|4", "4:6-4:9|-1|1|4"] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 5844987037615239736, + "detailed_name": "Foo *Foo::member", + "short_name": "member", + "hover": "Foo *Foo::member = nullptr", + "declarations": ["2:15-2:21|0|2|1"], + "spell": "4:11-4:17|0|2|2", + "extent": "4:1-4:27|-1|1|0", + "type": 0, + "uses": [], + "kind": 8, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/class_static_member_decl_only.cc b/index_tests/vars/class_static_member_decl_only.cc new file mode 100644 index 00000000..a7ea0afa --- /dev/null +++ b/index_tests/vars/class_static_member_decl_only.cc @@ -0,0 +1,53 @@ +class Foo { + static int member; +}; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": [] + }, { + "id": 1, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 5844987037615239736, + "detailed_name": "int Foo::member", + "short_name": "member", + "declarations": ["2:14-2:20|0|2|1"], + "type": 1, + "uses": [], + "kind": 8, + "storage": 3 + }] +} +*/ diff --git a/index_tests/vars/deduce_auto_type.cc b/index_tests/vars/deduce_auto_type.cc new file mode 100644 index 00000000..42f6d581 --- /dev/null +++ b/index_tests/vars/deduce_auto_type.cc @@ -0,0 +1,71 @@ +class Foo {}; +void f() { + auto x = new Foo(); + auto* y = new Foo(); +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 5, + "declarations": [], + "spell": "1:7-1:10|-1|1|2", + "extent": "1:1-1:13|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["3:16-3:19|-1|1|4", "4:17-4:20|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 880549676430489861, + "detailed_name": "void f()", + "short_name": "f", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "2:6-2:7|-1|1|2", + "extent": "2:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 9275666070987716270, + "detailed_name": "Foo *x", + "short_name": "x", + "declarations": [], + "spell": "3:8-3:9|0|3|2", + "extent": "3:3-3:21|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 16202433437488621027, + "detailed_name": "Foo *y", + "short_name": "y", + "declarations": [], + "spell": "4:9-4:10|0|3|2", + "extent": "4:3-4:22|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/function_local.cc b/index_tests/vars/function_local.cc new file mode 100644 index 00000000..6f0adec7 --- /dev/null +++ b/index_tests/vars/function_local.cc @@ -0,0 +1,57 @@ +struct Foo; + +void foo() { + Foo* a; +} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["1:8-1:11|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["4:3-4:6|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 10782632605670042066, + "detailed_name": "Foo *a", + "short_name": "a", + "declarations": [], + "spell": "4:8-4:9|0|3|2", + "extent": "4:3-4:9|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/function_param.cc b/index_tests/vars/function_param.cc new file mode 100644 index 00000000..cc61eff7 --- /dev/null +++ b/index_tests/vars/function_param.cc @@ -0,0 +1,67 @@ +struct Foo; + +void foo(Foo* p0, Foo* p1) {} + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 15041163540773201510, + "detailed_name": "Foo", + "short_name": "Foo", + "kind": 23, + "declarations": ["1:8-1:11|-1|1|1"], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": ["3:10-3:13|-1|1|4", "3:19-3:22|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 8908726657907936744, + "detailed_name": "void foo(Foo *p0, Foo *p1)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-3:30|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 4580260577538694711, + "detailed_name": "Foo *p0", + "short_name": "p0", + "declarations": [], + "spell": "3:15-3:17|0|3|2", + "extent": "3:10-3:17|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 12071725611268840435, + "detailed_name": "Foo *p1", + "short_name": "p1", + "declarations": [], + "spell": "3:24-3:26|0|3|2", + "extent": "3:19-3:26|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/function_param_unnamed.cc b/index_tests/vars/function_param_unnamed.cc new file mode 100644 index 00000000..aa3fd2a7 --- /dev/null +++ b/index_tests/vars/function_param_unnamed.cc @@ -0,0 +1,26 @@ +void foo(int, int) {} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [], + "funcs": [{ + "id": 0, + "usr": 2747674671862363334, + "detailed_name": "void foo(int, int)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-1:22|-1|1|0", + "bases": [], + "derived": [], + "vars": [], + "uses": [], + "callees": [] + }], + "vars": [] +} +*/ diff --git a/index_tests/vars/function_shadow_local.cc b/index_tests/vars/function_shadow_local.cc new file mode 100644 index 00000000..0c4fa4a1 --- /dev/null +++ b/index_tests/vars/function_shadow_local.cc @@ -0,0 +1,72 @@ +void foo() { + int a; + a = 1; + { + int a; + a = 2; + } + a = 3; +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 4259594751088586730, + "detailed_name": "void foo()", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-9:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 3440226937504376525, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "2:7-2:8|0|3|2", + "extent": "2:3-2:8|0|3|0", + "type": 0, + "uses": ["3:3-3:4|0|3|4", "8:3-8:4|0|3|4"], + "kind": 13, + "storage": 1 + }, { + "id": 1, + "usr": 14700715011944976607, + "detailed_name": "int a", + "short_name": "a", + "declarations": [], + "spell": "5:9-5:10|0|3|2", + "extent": "5:5-5:10|0|3|0", + "type": 0, + "uses": ["6:5-6:6|0|3|4"], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/function_shadow_param.cc b/index_tests/vars/function_shadow_param.cc new file mode 100644 index 00000000..5f8a9988 --- /dev/null +++ b/index_tests/vars/function_shadow_param.cc @@ -0,0 +1,67 @@ +void foo(int p) { + { int p = 0; } +} +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0, 1], + "uses": [] + }], + "funcs": [{ + "id": 0, + "usr": 11998306017310352355, + "detailed_name": "void foo(int p)", + "short_name": "foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "1:6-1:9|-1|1|2", + "extent": "1:1-3:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0, 1], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 5875271969926422921, + "detailed_name": "int p", + "short_name": "p", + "declarations": [], + "spell": "1:14-1:15|0|3|2", + "extent": "1:10-1:15|0|3|0", + "type": 0, + "uses": [], + "kind": 253, + "storage": 1 + }, { + "id": 1, + "usr": 2147918703972955240, + "detailed_name": "int p", + "short_name": "p", + "hover": "int p = 0", + "declarations": [], + "spell": "2:9-2:10|0|3|2", + "extent": "2:5-2:14|0|3|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/index_tests/vars/global_variable.cc b/index_tests/vars/global_variable.cc new file mode 100644 index 00000000..5d061ff7 --- /dev/null +++ b/index_tests/vars/global_variable.cc @@ -0,0 +1,38 @@ +static int global = 0; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 6834525061342585382, + "detailed_name": "int global", + "short_name": "global", + "hover": "int global = 0", + "declarations": [], + "spell": "1:12-1:18|-1|1|2", + "extent": "1:1-1:22|-1|1|0", + "type": 0, + "uses": [], + "kind": 13, + "storage": 3 + }] +} +*/ diff --git a/index_tests/vars/global_variable_decl_only.cc b/index_tests/vars/global_variable_decl_only.cc new file mode 100644 index 00000000..f70c21bc --- /dev/null +++ b/index_tests/vars/global_variable_decl_only.cc @@ -0,0 +1,35 @@ +extern int global; +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 17, + "detailed_name": "", + "short_name": "", + "kind": 0, + "declarations": [], + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": [] + }], + "funcs": [], + "vars": [{ + "id": 0, + "usr": 9937941849651546906, + "detailed_name": "int global", + "short_name": "global", + "declarations": ["1:12-1:18|-1|1|1"], + "type": 0, + "uses": [], + "kind": 13, + "storage": 2 + }] +} +*/ diff --git a/index_tests/vars/type_instance_on_using_type.cc b/index_tests/vars/type_instance_on_using_type.cc new file mode 100644 index 00000000..7d01422b --- /dev/null +++ b/index_tests/vars/type_instance_on_using_type.cc @@ -0,0 +1,79 @@ +struct S {}; +using F = S; +void Foo() { + F a; +} + +// TODO: Should we also add a usage to |S|? + +/* +OUTPUT: +{ + "includes": [], + "skipped_by_preprocessor": [], + "types": [{ + "id": 0, + "usr": 4750332761459066907, + "detailed_name": "S", + "short_name": "S", + "kind": 23, + "declarations": [], + "spell": "1:8-1:9|-1|1|2", + "extent": "1:1-1:12|-1|1|0", + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [], + "uses": ["2:11-2:12|-1|1|4"] + }, { + "id": 1, + "usr": 7434820806199665424, + "detailed_name": "F", + "short_name": "F", + "kind": 252, + "hover": "using F = S", + "declarations": [], + "spell": "2:7-2:8|-1|1|2", + "extent": "2:1-2:12|-1|1|0", + "alias_of": 0, + "bases": [], + "derived": [], + "types": [], + "funcs": [], + "vars": [], + "instances": [0], + "uses": ["2:7-2:8|-1|1|4", "4:3-4:4|-1|1|4"] + }], + "funcs": [{ + "id": 0, + "usr": 4654328188330986029, + "detailed_name": "void Foo()", + "short_name": "Foo", + "kind": 12, + "storage": 1, + "declarations": [], + "spell": "3:6-3:9|-1|1|2", + "extent": "3:1-5:2|-1|1|0", + "bases": [], + "derived": [], + "vars": [0], + "uses": [], + "callees": [] + }], + "vars": [{ + "id": 0, + "usr": 7730100248624586522, + "detailed_name": "F a", + "short_name": "a", + "declarations": [], + "spell": "4:5-4:6|0|3|2", + "extent": "4:3-4:6|0|3|0", + "type": 1, + "uses": [], + "kind": 13, + "storage": 1 + }] +} +*/ diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 520e9dcf..4ae4e55b 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -25,15 +25,15 @@ struct RealCacheManager : ICacheManager { WriteToFile(AppendSerializationFormat(cache_path), indexed_content); } - optional LoadCachedFileContents( + std::optional LoadCachedFileContents( const std::string& path) override { return ReadContent(GetCachePath(path)); } std::unique_ptr RawCacheLoad(const std::string& path) override { std::string cache_path = GetCachePath(path); - optional file_content = ReadContent(cache_path); - optional serialized_indexed_content = + std::optional file_content = ReadContent(cache_path); + std::optional serialized_indexed_content = ReadContent(AppendSerializationFormat(cache_path)); if (!file_content || !serialized_indexed_content) return nullptr; @@ -77,7 +77,7 @@ struct FakeCacheManager : ICacheManager { void WriteToCache(IndexFile& file) override { assert(false); } - optional LoadCachedFileContents( + std::optional LoadCachedFileContents( const std::string& path) override { for (const FakeCacheEntry& entry : entries_) { if (entry.path == path) { @@ -85,14 +85,14 @@ struct FakeCacheManager : ICacheManager { } } - return nullopt; + return std::nullopt; } std::unique_ptr RawCacheLoad(const std::string& path) override { for (const FakeCacheEntry& entry : entries_) { if (entry.path == path) { return Deserialize(SerializeFormat::Json, path, entry.json, "", - nullopt); + std::nullopt); } } diff --git a/src/cache_manager.h b/src/cache_manager.h index e5fd9672..f175544b 100644 --- a/src/cache_manager.h +++ b/src/cache_manager.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -38,7 +38,7 @@ struct ICacheManager { virtual void WriteToCache(IndexFile& file) = 0; - virtual optional LoadCachedFileContents( + virtual std::optional LoadCachedFileContents( const std::string& path) = 0; // Iterate over all loaded caches. diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 8584b5ad..1ac65e46 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -29,7 +29,7 @@ unsigned Flags() { unsigned GetCompletionPriority(const CXCompletionString& str, CXCursorKind result_kind, - const optional& typedText) { + const std::optional& typedText) { unsigned priority = clang_getCompletionPriority(str); // XXX: What happens if priority overflows? @@ -396,7 +396,7 @@ void TryEnsureDocumentParsed(ClangCompleteManager* manager, std::vector ls_diagnostics; unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu); for (unsigned i = 0; i < num_diagnostics; ++i) { - optional diagnostic = BuildAndDisposeDiagnostic( + std::optional diagnostic = BuildAndDisposeDiagnostic( clang_getDiagnostic((*tu)->cx_tu, i), session->file.filename); // Filter messages like "too many errors emitted, stopping now // [-ferror-limit=]" which has line = 0 and got subtracted by 1 after @@ -501,7 +501,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { { if (request->on_complete) { std::vector ls_result; - // this is a guess but can be larger in case of optional parameters, + // this is a guess but can be larger in case of std::optional parameters, // as they may be expanded into multiple items ls_result.reserve(cx_results->NumResults); @@ -605,7 +605,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { ls_diagnostics.reserve(num_diagnostics); for (unsigned i = 0; i < num_diagnostics; ++i) { CXDiagnostic cx_diag = clang_getDiagnostic(session->tu->cx_tu, i); - optional diagnostic = + std::optional diagnostic = BuildAndDisposeDiagnostic(cx_diag, path); // Filter messages like "too many errors emitted, stopping now // [-ferror-limit=]" which has line = 0 and got subtracted by 1 after diff --git a/src/clang_complete.h b/src/clang_complete.h index 03197a60..0ed45896 100644 --- a/src/clang_complete.h +++ b/src/clang_complete.h @@ -23,7 +23,7 @@ struct CompletionSession ClangIndex index; // When |tu| was last parsed. - optional> + std::optional> tu_last_parsed_at; // Acquired when |tu| is being used. @@ -67,7 +67,7 @@ struct ClangCompleteManager { lsRequestId id; lsTextDocumentIdentifier document; - optional position; + std::optional position; OnComplete on_complete; // May be null/empty. bool emit_diagnostics = false; }; diff --git a/src/clang_cursor.h b/src/clang_cursor.h index 23eed1bb..53f94cfa 100644 --- a/src/clang_cursor.h +++ b/src/clang_cursor.h @@ -4,7 +4,7 @@ #include "position.h" #include -#include +#include #include #include diff --git a/src/clang_indexer.cc b/src/clang_indexer.cc index fbbdf396..f4240df3 100644 --- a/src/clang_indexer.cc +++ b/src/clang_indexer.cc @@ -212,7 +212,7 @@ struct ConstructorCache { // Tries to lookup a constructor in |type_usr| that takes arguments most // closely aligned to |param_type_desc|. - optional TryFindConstructorUsr( + std::optional TryFindConstructorUsr( Usr type_usr, const std::vector& param_type_desc) { auto count_matching_prefix_length = [](const char* a, const char* b) { @@ -235,10 +235,10 @@ struct ConstructorCache { // available, return an empty result. auto ctors_it = constructors_.find(type_usr); if (ctors_it == constructors_.end()) - return nullopt; + return std::nullopt; const std::vector& ctors = ctors_it->second; if (ctors.empty()) - return nullopt; + return std::nullopt; Usr best_usr = ctors[0].usr; int best_score = INT_MIN; @@ -352,7 +352,7 @@ IndexFile* ConsumeFile(IndexParam* param, CXFile file) { param->seen_files.push_back(file_name); // Set modification time. - optional modification_time = GetLastModificationTime(file_name); + std::optional modification_time = GetLastModificationTime(file_name); LOG_IF_S(ERROR, !modification_time) << "Failed fetching modification time for " << file_name; if (modification_time) @@ -426,7 +426,7 @@ std::string GetDocumentContentInRange(CXTranslationUnit cx_tu, unsigned num_tokens; clang_tokenize(cx_tu, range, &tokens, &num_tokens); - optional previous_token_range; + std::optional previous_token_range; for (unsigned i = 0; i < num_tokens; ++i) { // Add whitespace between the previous token and this one. @@ -537,7 +537,7 @@ void SetTypeName(IndexType* type, // strips // qualifies from |cursor| (ie, Foo* => Foo) and removes template arguments // (ie, Foo => Foo<*,*>). -optional ResolveToDeclarationType(IndexFile* db, +std::optional ResolveToDeclarationType(IndexFile* db, ClangCursor cursor, IndexParam* param) { ClangType type = cursor.get_type(); @@ -561,7 +561,7 @@ optional ResolveToDeclarationType(IndexFile* db, const char* str_usr = clang_getCString(cx_usr); if (!str_usr || str_usr[0] == '\0') { clang_disposeString(cx_usr); - return nullopt; + return std::nullopt; } Usr usr = HashUsr(str_usr); clang_disposeString(cx_usr); @@ -633,8 +633,8 @@ void SetVarDetail(IndexVar* var, clang_getResultType(deref).kind == CXType_Invalid && clang_getElementType(deref).kind == CXType_Invalid) { const FileContents& fc = param->file_contents[db->path]; - optional spell_end = fc.ToOffset(cursor.get_spell().end); - optional extent_end = fc.ToOffset(cursor.get_extent().end); + std::optional spell_end = fc.ToOffset(cursor.get_spell().end); + std::optional extent_end = fc.ToOffset(cursor.get_extent().end); if (extent_end && *spell_end < *extent_end) def.hover = std::string(def.detailed_name.c_str()) + fc.content.substr(*spell_end, *extent_end - *spell_end); @@ -649,7 +649,7 @@ void SetVarDetail(IndexVar* var, def.short_name_size = short_name.size(); if (is_first_seen) { - optional var_type = + std::optional var_type = ResolveToDeclarationType(db, cursor, param); if (var_type) { // Don't treat enum definition variables as instantiations. @@ -844,7 +844,7 @@ void OnIndexDiagnostic(CXClientData client_data, continue; // Build diagnostic. - optional ls_diagnostic = + std::optional ls_diagnostic = BuildAndDisposeDiagnostic(diagnostic, db->path); if (ls_diagnostic) db->diagnostics_.push_back(*ls_diagnostic); @@ -898,14 +898,14 @@ void Dump(ClangCursor cursor) { struct FindChildOfKindParam { CXCursorKind target_kind; - optional result; + std::optional result; FindChildOfKindParam(CXCursorKind target_kind) : target_kind(target_kind) {} }; ClangCursor::VisitResult FindTypeVisitor(ClangCursor cursor, ClangCursor parent, - optional* result) { + std::optional* result) { switch (cursor.get_kind()) { case CXCursor_TypeRef: case CXCursor_TemplateRef: @@ -918,8 +918,8 @@ ClangCursor::VisitResult FindTypeVisitor(ClangCursor cursor, return ClangCursor::VisitResult::Recurse; } -optional FindType(ClangCursor cursor) { - optional result; +std::optional FindType(ClangCursor cursor) { + std::optional result; cursor.VisitChildren(&FindTypeVisitor, &result); return result; } @@ -932,12 +932,12 @@ bool IsTypeDefinition(const CXIdxContainerInfo* container) { struct VisitDeclForTypeUsageParam { IndexFile* db; - optional toplevel_type; + std::optional toplevel_type; int has_processed_any = false; - optional previous_cursor; - optional initial_type; + std::optional previous_cursor; + std::optional initial_type; - VisitDeclForTypeUsageParam(IndexFile* db, optional toplevel_type) + VisitDeclForTypeUsageParam(IndexFile* db, std::optional toplevel_type) : db(db), toplevel_type(toplevel_type) {} }; @@ -964,7 +964,7 @@ void VisitDeclForTypeUsageVisitorHandler(ClangCursor cursor, std::string name = cursor.get_referenced().get_spell_name(); if (name == ref_type->def.ShortName()) { AddUseSpell(db, ref_type->uses, cursor); - param->toplevel_type = nullopt; + param->toplevel_type = std::nullopt; return; } } @@ -1035,10 +1035,10 @@ ClangCursor::VisitResult VisitDeclForTypeUsageVisitor( // template. // We use |toplevel_type| to attribute the use to the specialized template // instead of the primary template. -optional AddDeclTypeUsages( +std::optional AddDeclTypeUsages( IndexFile* db, ClangCursor decl_cursor, - optional toplevel_type, + std::optional toplevel_type, const CXIdxContainerInfo* semantic_container, const CXIdxContainerInfo* lexical_container) { // @@ -1161,7 +1161,7 @@ optional AddDeclTypeUsages( return param.initial_type; CXType cx_under = clang_getTypedefDeclUnderlyingType(decl_cursor.cx_cursor); if (cx_under.kind == CXType_Invalid) - return nullopt; + return std::nullopt; return db->ToTypeId(ClangType(cx_under).strip_qualifiers().get_usr_hash()); } @@ -1320,7 +1320,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor, // The cursor extent includes `type name`, not just `name`. There // seems no way to extract the spelling range of `type` and we do // not want to do subtraction here. - // See https://github.com/jacobdufault/cquery/issues/252 + // See https://github.com/cquery-project/cquery/issues/252 AddUse(db, ref_type_index->uses, ref_cursor.get_extent(), ref_cursor.get_lexical_parent()); } @@ -1555,7 +1555,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { SetVarDetail(var, std::string(decl->entityInfo->name), decl->cursor, decl->semanticContainer, !decl->isRedeclaration, db, param); - // FIXME https://github.com/jacobdufault/cquery/issues/239 + // FIXME https://github.com/jacobdufault/ccls/issues/239 var->def.kind = GetSymbolKind(decl->entityInfo->kind); if (var->def.kind == lsSymbolKind::Variable && decl->cursor.kind == CXCursor_ParmDecl) @@ -1631,7 +1631,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // We don't actually need to know the return type, but we need to mark it // as an interesting usage. - AddDeclTypeUsages(db, cursor, nullopt, decl->semanticContainer, + AddDeclTypeUsages(db, cursor, std::nullopt, decl->semanticContainer, decl->lexicalContainer); // Add definition or declaration. This is a bit tricky because we treat @@ -1753,8 +1753,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // Note we want to fetch the first TypeRef. Running // ResolveCursorType(decl->cursor) would return // the type of the typedef/using, not the type of the referenced type. - optional alias_of = AddDeclTypeUsages( - db, cursor, nullopt, decl->semanticContainer, decl->lexicalContainer); + std::optional alias_of = AddDeclTypeUsages( + db, cursor, std::nullopt, decl->semanticContainer, decl->lexicalContainer); IndexTypeId type_id = db->ToTypeId(HashUsr(decl->entityInfo->USR)); IndexType* type = db->Resolve(type_id); @@ -1777,11 +1777,11 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // For Typedef/CXXTypeAlias spanning a few lines, display the declaration // line, with spelling name replaced with qualified name. // TODO Think how to display multi-line declaration like `typedef struct { - // ... } foo;` https://github.com/jacobdufault/cquery/issues/29 + // ... } foo;` https://github.com/jacobdufault/ccls/issues/29 if (extent.end.line - extent.start.line < kMaxLinesDisplayTypeAliasDeclarations) { FileContents& fc = param->file_contents[db->path]; - optional extent_start = fc.ToOffset(extent.start), + std::optional extent_start = fc.ToOffset(extent.start), spell_start = fc.ToOffset(spell.start), spell_end = fc.ToOffset(spell.end), extent_end = fc.ToOffset(extent.end); @@ -1863,7 +1863,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { origin->def.kind = type->def.kind; } // TODO The name may be assigned in |ResolveToDeclarationType| but - // |spell| is nullopt. + // |spell| is std::nullopt. CXFile origin_file; Range origin_spell = origin_cursor.get_spell(&origin_file); if (!origin->def.spell && file == origin_file) { @@ -1905,9 +1905,9 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { for (unsigned int i = 0; i < class_info->numBases; ++i) { const CXIdxBaseClassInfo* base_class = class_info->bases[i]; - AddDeclTypeUsages(db, base_class->cursor, nullopt, + AddDeclTypeUsages(db, base_class->cursor, std::nullopt, decl->semanticContainer, decl->lexicalContainer); - optional parent_type_id = + std::optional parent_type_id = ResolveToDeclarationType(db, base_class->cursor, param); // type_def ptr could be invalidated by ResolveToDeclarationType and // TemplateVisitor. @@ -1924,7 +1924,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { } } -// https://github.com/jacobdufault/cquery/issues/174 +// https://github.com/jacobdufault/ccls/issues/174 // Type-dependent member access expressions do not have accurate spelling // ranges. // @@ -1946,7 +1946,7 @@ void CheckTypeDependentMemberRefExpr(Range* spell, cursor.get_spell_name().empty()) { *spell = cursor.get_extent().RemovePrefix(spell->end); const FileContents& fc = param->file_contents[db->path]; - optional maybe_period = fc.ToOffset(spell->start); + std::optional maybe_period = fc.ToOffset(spell->start); if (maybe_period) { int i = *maybe_period; if (fc.content[i] == '.') @@ -2114,7 +2114,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { str_begin("make", ref->referencedEntity->name)) { // Try to find the return type of called function. That type will have // the constructor function we add a usage to. - optional opt_found_type = FindType(ref->cursor); + std::optional opt_found_type = FindType(ref->cursor); if (opt_found_type) { Usr ctor_type_usr = opt_found_type->get_referenced().get_usr_hash(); ClangCursor call_cursor = ref->cursor; @@ -2129,7 +2129,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { } // Try to find the constructor and add a reference. - optional ctor_usr = + std::optional ctor_usr = param->ctors.TryFindConstructorUsr(ctor_type_usr, call_type_desc); if (ctor_usr) { IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr)); @@ -2164,7 +2164,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { } } -optional>> Parse( +std::optional>> Parse( Config* config, FileConsumerSharedState* file_consumer_shared, std::string file, @@ -2174,7 +2174,7 @@ optional>> Parse( ClangIndex* index, bool dump_ast) { if (!config->index.enabled) - return nullopt; + return std::nullopt; file = NormalizePath(file); @@ -2194,7 +2194,7 @@ optional>> Parse( CXTranslationUnit_KeepGoing | CXTranslationUnit_DetailedPreprocessingRecord); if (!tu) - return nullopt; + return std::nullopt; perf->index_parse = timer.ElapsedMicrosecondsAndReset(); @@ -2205,7 +2205,7 @@ optional>> Parse( args, unsaved_files); } -optional>> ParseWithTu( +std::optional>> ParseWithTu( Config* config, FileConsumerSharedState* file_consumer_shared, PerformanceImportFile* perf, @@ -2250,7 +2250,7 @@ optional>> ParseWithTu( if (index_result != CXError_Success) { LOG_S(ERROR) << "Indexing " << file << " failed with errno=" << index_result; - return nullopt; + return std::nullopt; } clang_IndexAction_dispose(index_action); diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index 88365f23..6062e417 100644 --- a/src/clang_translation_unit.cc +++ b/src/clang_translation_unit.cc @@ -87,7 +87,7 @@ std::unique_ptr ClangTranslationUnit::Create( // -fsyntax-only so they don't do a full compile. auto make_msg = [&]() { return "Please try running the following, identify which flag causes the " - "issue, and report a bug. cquery will then filter the flag for you " + "issue, and report a bug. ccls will then filter the flag for you " " automatically:\n$ " + StringJoin(args, " ") + " -fsyntax-only"; }; diff --git a/src/clang_utils.cc b/src/clang_utils.cc index 03a35d75..d89f7856 100644 --- a/src/clang_utils.cc +++ b/src/clang_utils.cc @@ -23,7 +23,7 @@ lsRange GetLsRangeForFixIt(const CXSourceRange& range) { } // namespace // See clang_formatDiagnostic -optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, +std::optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, const std::string& path) { // Get diagnostic location. CXFile file; @@ -33,7 +33,7 @@ optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, if (file && path != FileName(file)) { clang_disposeDiagnostic(diagnostic); - return nullopt; + return std::nullopt; } unsigned end_line = start_line, end_column = start_column, diff --git a/src/clang_utils.h b/src/clang_utils.h index 24175efd..65236876 100644 --- a/src/clang_utils.h +++ b/src/clang_utils.h @@ -6,11 +6,11 @@ #if USE_CLANG_CXX #include #endif -#include +#include #include -optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, +std::optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, const std::string& path); // Returns the absolute path to |file|. diff --git a/src/code_complete_cache.h b/src/code_complete_cache.h index 76ed6104..39696f1b 100644 --- a/src/code_complete_cache.h +++ b/src/code_complete_cache.h @@ -2,7 +2,7 @@ #include "lsp_completion.h" -#include +#include #include @@ -11,8 +11,8 @@ // that happens. struct CodeCompleteCache { // NOTE: Make sure to access these variables under |WithLock|. - optional cached_path_; - optional cached_completion_position_; + std::optional cached_path_; + std::optional cached_completion_position_; std::vector cached_results_; std::mutex mutex_; diff --git a/src/command_line.cc b/src/command_line.cc index 91f96e0d..700e5b10 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -61,18 +61,18 @@ std::vector kEmptyArgs; bool ShouldDisplayMethodTiming(MethodType type) { return type != kMethodType_TextDocumentPublishDiagnostics && - type != kMethodType_CqueryPublishInactiveRegions && + type != kMethodType_CclsPublishInactiveRegions && type != kMethodType_Unknown; } void PrintHelp() { std::cout - << R"help(cquery is a low-latency C/C++/Objective-C language server. + << R"help(ccls is a low-latency C/C++/Objective-C language server. Mode: --clang-sanity-check Run a simple index test. Verifies basic clang functionality. - Needs to be executed from the cquery root checkout directory. + Needs to be executed from the ccls root checkout directory. --test-unit Run unit tests. --test-index Run index tests. opt_filter_path can be used to specify which @@ -281,7 +281,7 @@ void LaunchStdinLoop(Config* config, auto* queue = QueueManager::instance(); while (true) { std::unique_ptr message; - optional err = + std::optional err = MessageRegistry::instance()->ReadMessageFromStdin(&message); // Message parsing can fail if we don't recognize the method. diff --git a/src/config.h b/src/config.h index 9030a903..d7353f81 100644 --- a/src/config.h +++ b/src/config.h @@ -6,12 +6,12 @@ /* The language client plugin needs to send initialization options in the -`initialize` request to the cquery language server. The only required option is +`initialize` request to the ccls language server. The only required option is `cacheDirectory`, which is where index files will be stored. { "initializationOptions": { - "cacheDirectory": "/tmp/cquery" + "cacheDirectory": "/tmp/ccls" } } @@ -42,11 +42,11 @@ struct Config { // takes only 60% of the corresponding JSON size, but is difficult to inspect. // msgpack does not store map keys and you need to re-index whenever a struct // member has changed. - SerializeFormat cacheFormat = SerializeFormat::Json; + SerializeFormat cacheFormat = SerializeFormat::MessagePack; // Value to use for clang -resource-dir if not present in // compile_commands.json. // - // cquery includes a resource directory, this should not need to be configured + // ccls includes a resource directory, this should not need to be configured // unless you're using an esoteric configuration. Consider reporting a bug and // fixing upstream instead of configuring this. // @@ -56,8 +56,8 @@ struct Config { // Additional arguments to pass to clang. std::vector extraClangArguments; - // If true, cquery will send progress reports while indexing - // How often should cquery send progress report messages? + // If true, ccls will send progress reports while indexing + // How often should ccls send progress report messages? // -1: never // 0: as often as possible // xxx: at most every xxx milliseconds @@ -66,7 +66,7 @@ struct Config { // available and may exceed this value. // // This does not guarantee a progress report will be delivered every - // interval; it could take significantly longer if cquery is completely idle. + // interval; it could take significantly longer if ccls is completely idle. int progressReportFrequencyMs = 500; // If true, document links are reported for #include directives. @@ -74,7 +74,7 @@ struct Config { // Version of the client. If undefined the version check is skipped. Used to // inform users their vscode client is too old and needs to be updated. - optional clientVersion; + std::optional clientVersion; struct ClientCapability { // TextDocumentClientCapabilities.completion.completionItem.snippetSupport @@ -107,13 +107,13 @@ struct Config { // items can end up truncated by the UIs. bool detailedLabel = false; - // On large projects, completion can take a long time. By default if cquery + // On large projects, completion can take a long time. By default if ccls // receives multiple completion requests while completion is still running // it will only service the newest request. If this is set to false then all // completion requests will be serviced. bool dropOldRequests = true; - // If true, filter and sort completion response. cquery filters and sorts + // If true, filter and sort completion response. ccls filters and sorts // completions to try to be nicer to clients that can't handle big numbers // of completion candidates. This behaviour can be disabled by specifying // false for the option. This option is the most useful for LSP clients @@ -146,7 +146,7 @@ struct Config { // blacklisted files. std::vector blacklist; - // How often should cquery publish diagnostics in completion? + // How often should ccls publish diagnostics in completion? // -1: never // 0: as often as possible // xxx: at most every xxx milliseconds @@ -172,7 +172,7 @@ struct Config { // hueristics. // // For example, this will show constructor calls for std::make_unique - // invocations. Specifically, cquery will try to attribute a ctor call + // invocations. Specifically, ccls will try to attribute a ctor call // whenever the function name starts with make (ignoring case). bool attributeMakeCallsToCtor = true; diff --git a/src/file_consumer.cc b/src/file_consumer.cc index 13042d79..3b1d6759 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -9,11 +9,11 @@ namespace { -optional GetFileContents(const std::string& path, +std::optional GetFileContents(const std::string& path, FileContentsMap* file_contents) { auto it = file_contents->find(path); if (it == file_contents->end()) { - optional content = ReadContent(path); + std::optional content = ReadContent(path); if (content) (*file_contents)[path] = FileContents(path, *content); return content; @@ -75,7 +75,7 @@ IndexFile* FileConsumer::TryConsumeFile(CXFile file, } // Read the file contents, if we fail then we cannot index the file. - optional contents = + std::optional contents = GetFileContents(file_name, file_contents_map); if (!contents) { *is_first_ownership = false; diff --git a/src/file_contents.cc b/src/file_contents.cc index 4e716e65..5a7bc0f4 100644 --- a/src/file_contents.cc +++ b/src/file_contents.cc @@ -11,19 +11,19 @@ FileContents::FileContents(const std::string& path, const std::string& content) } } -optional FileContents::ToOffset(Position p) const { +std::optional FileContents::ToOffset(Position p) const { if (0 <= p.line && size_t(p.line) < line_offsets_.size()) { int ret = line_offsets_[p.line] + p.column; if (size_t(ret) < content.size()) return ret; } - return nullopt; + return std::nullopt; } -optional FileContents::ContentsInRange(Range range) const { - optional start_offset = ToOffset(range.start), +std::optional FileContents::ContentsInRange(Range range) const { + std::optional start_offset = ToOffset(range.start), end_offset = ToOffset(range.end); if (start_offset && end_offset && *start_offset < *end_offset) return content.substr(*start_offset, *end_offset - *start_offset); - return nullopt; + return std::nullopt; } diff --git a/src/file_contents.h b/src/file_contents.h index 0a6cffb5..21c484d4 100644 --- a/src/file_contents.h +++ b/src/file_contents.h @@ -2,9 +2,8 @@ #include "position.h" -#include "optional.h" - #include +#include #include #include @@ -12,8 +11,8 @@ struct FileContents { FileContents(); FileContents(const std::string& path, const std::string& content); - optional ToOffset(Position p) const; - optional ContentsInRange(Range range) const; + std::optional ToOffset(Position p) const; + std::optional ContentsInRange(Range range) const; std::string path; std::string content; diff --git a/src/fuzzy_match.h b/src/fuzzy_match.h index 336815b7..52a89986 100644 --- a/src/fuzzy_match.h +++ b/src/fuzzy_match.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/src/iindexer.cc b/src/iindexer.cc index e0758410..16085bc3 100644 --- a/src/iindexer.cc +++ b/src/iindexer.cc @@ -6,7 +6,7 @@ namespace { struct ClangIndexer : IIndexer { ~ClangIndexer() override = default; - optional>> Index( + std::optional>> Index( Config* config, FileConsumerSharedState* file_consumer_shared, std::string file, @@ -50,7 +50,7 @@ struct TestIndexer : IIndexer { ~TestIndexer() override = default; - optional>> Index( + std::optional>> Index( Config* config, FileConsumerSharedState* file_consumer_shared, std::string file, @@ -61,7 +61,7 @@ struct TestIndexer : IIndexer { if (it == indexes.end()) { // Don't return any indexes for unexpected data. assert(false && "no indexes"); - return nullopt; + return std::nullopt; } // FIXME: allow user to control how many times we return the index for a diff --git a/src/iindexer.h b/src/iindexer.h index f8a45347..d6648990 100644 --- a/src/iindexer.h +++ b/src/iindexer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -34,7 +34,7 @@ struct IIndexer { std::initializer_list entries); virtual ~IIndexer() = default; - virtual optional>> Index( + virtual std::optional>> Index( Config* config, FileConsumerSharedState* file_consumer_shared, std::string file, diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 4c0102ba..9c087ef4 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -33,7 +33,7 @@ struct Out_Progress : public lsOutMessage { int onIndexedCount = 0; int activeThreads = 0; }; - std::string method = "$cquery/progress"; + std::string method = "$ccls/progress"; Params params; }; MAKE_REFLECT_STRUCT(Out_Progress::Params, @@ -63,23 +63,23 @@ struct IterationLoop { struct IModificationTimestampFetcher { virtual ~IModificationTimestampFetcher() = default; - virtual optional GetModificationTime(const std::string& path) = 0; + virtual std::optional GetModificationTime(const std::string& path) = 0; }; struct RealModificationTimestampFetcher : IModificationTimestampFetcher { ~RealModificationTimestampFetcher() override = default; // IModificationTimestamp: - optional GetModificationTime(const std::string& path) override { + std::optional GetModificationTime(const std::string& path) override { return GetLastModificationTime(path); } }; struct FakeModificationTimestampFetcher : IModificationTimestampFetcher { - std::unordered_map> entries; + std::unordered_map> entries; ~FakeModificationTimestampFetcher() override = default; // IModificationTimestamp: - optional GetModificationTime(const std::string& path) override { + std::optional GetModificationTime(const std::string& path) override { auto it = entries.find(path); assert(it != entries.end()); return it->second; @@ -159,8 +159,8 @@ ShouldParse FileNeedsParse( IndexFile* opt_previous_index, const std::string& path, const std::vector& args, - const optional& from) { - auto unwrap_opt = [](const optional& opt) -> std::string { + const std::optional& from) { + auto unwrap_opt = [](const std::optional& opt) -> std::string { if (opt) return " (via " + *opt + ")"; return ""; @@ -173,14 +173,14 @@ ShouldParse FileNeedsParse( return ShouldParse::No; } - optional modification_timestamp = + std::optional modification_timestamp = modification_timestamp_fetcher->GetModificationTime(path); // Cannot find file. if (!modification_timestamp) return ShouldParse::NoSuchFile; - optional last_cached_modification = + std::optional last_cached_modification = timestamp_manager->GetLastCachedModificationTime(cache_manager.get(), path); @@ -236,7 +236,7 @@ CacheLoadResult TryLoadFromCache( ShouldParse path_state = FileNeedsParse( is_interactive, timestamp_manager, modification_timestamp_fetcher, import_manager, cache_manager, previous_index, path_to_index, entry.args, - nullopt); + std::nullopt); if (path_state == ShouldParse::Yes) file_consumer_shared->Reset(path_to_index); @@ -327,14 +327,14 @@ std::vector PreloadFileContents( // still valid. if so, we can use it, otherwise we need to load from disk. auto get_latest_content = [](const std::string& path, int64_t cached_time, const std::string& cached) -> std::string { - optional mod_time = GetLastModificationTime(path); + std::optional mod_time = GetLastModificationTime(path); if (!mod_time) return ""; if (*mod_time == cached_time) return cached; - optional fresh_content = ReadContent(path); + std::optional fresh_content = ReadContent(path); if (!fresh_content) { LOG_S(ERROR) << "Failed to load content for " << path; return ""; @@ -437,7 +437,7 @@ bool IndexMain_DoParse( ImportManager* import_manager, IIndexer* indexer) { auto* queue = QueueManager::instance(); - optional request = queue->index_request.TryPopFront(); + std::optional request = queue->index_request.TryPopFront(); if (!request) return false; @@ -456,7 +456,7 @@ bool IndexMain_DoCreateIndexUpdate(TimestampManager* timestamp_manager) { bool did_work = false; IterationLoop loop; while (loop.Next()) { - optional response = queue->on_id_mapped.TryPopFront(); + std::optional response = queue->on_id_mapped.TryPopFront(); if (!response) return did_work; @@ -524,7 +524,7 @@ bool IndexMain_DoCreateIndexUpdate(TimestampManager* timestamp_manager) { bool IndexMain_LoadPreviousIndex() { auto* queue = QueueManager::instance(); - optional response = queue->load_previous_index.TryPopFront(); + std::optional response = queue->load_previous_index.TryPopFront(); if (!response) return false; @@ -540,14 +540,14 @@ bool IndexMain_LoadPreviousIndex() { bool IndexMergeIndexUpdates() { auto* queue = QueueManager::instance(); - optional root = queue->on_indexed.TryPopBack(); + std::optional root = queue->on_indexed.TryPopBack(); if (!root) return false; bool did_merge = false; IterationLoop loop; while (loop.Next()) { - optional to_join = queue->on_indexed.TryPopBack(); + std::optional to_join = queue->on_indexed.TryPopBack(); if (!to_join) break; did_merge = true; @@ -767,7 +767,7 @@ bool QueryDb_ImportMain(Config* config, IterationLoop loop; while (loop.Next()) { - optional request = queue->do_id_map.TryPopFront(); + std::optional request = queue->do_id_map.TryPopFront(); if (!request) break; did_work = true; @@ -776,7 +776,7 @@ bool QueryDb_ImportMain(Config* config, loop.Reset(); while (loop.Next()) { - optional response = queue->on_indexed.TryPopFront(); + std::optional response = queue->on_indexed.TryPopFront(); if (!response) break; did_work = true; @@ -839,7 +839,7 @@ TEST_SUITE("ImportPipeline") { opt_previous_index = std::make_unique("---.cc", ""); opt_previous_index->args = old_args; } - optional from; + std::optional from; if (is_dependency) from = std::string("---.cc"); return FileNeedsParse(is_interactive /*is_interactive*/, @@ -850,7 +850,7 @@ TEST_SUITE("ImportPipeline") { // A file with no timestamp is not imported, since this implies the file no // longer exists on disk. - modification_timestamp_fetcher.entries["bar.h"] = nullopt; + modification_timestamp_fetcher.entries["bar.h"] = std::nullopt; REQUIRE(check("bar.h", false /*is_dependency*/) == ShouldParse::NoSuchFile); // A dependency is only imported once. diff --git a/src/include_complete.cc b/src/include_complete.cc index f063d6d6..19f48c8e 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -211,12 +211,12 @@ void IncludeComplete::InsertStlIncludes() { } } -optional IncludeComplete::FindCompletionItemForAbsolutePath( +std::optional IncludeComplete::FindCompletionItemForAbsolutePath( const std::string& absolute_path) { std::lock_guard lock(completion_items_mutex); auto it = absolute_path_to_completion_item.find(absolute_path); if (it == absolute_path_to_completion_item.end()) - return nullopt; + return std::nullopt; return completion_items[it->second]; } diff --git a/src/include_complete.h b/src/include_complete.h index 9806cffe..47438113 100644 --- a/src/include_complete.h +++ b/src/include_complete.h @@ -24,7 +24,7 @@ struct IncludeComplete { bool use_angle_brackets); void InsertStlIncludes(); - optional FindCompletionItemForAbsolutePath( + std::optional FindCompletionItemForAbsolutePath( const std::string& absolute_path); // Insert item to |completion_items|. diff --git a/src/indexer.h b/src/indexer.h index 922e7524..025a2712 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -16,8 +16,8 @@ #include "symbol.h" #include "utils.h" -#include -#include +#include +#include #include #include @@ -192,7 +192,7 @@ struct TypeDefDefinitionData { return std::string_view(detailed_name.c_str() + short_name_offset, short_name_size); } - // Used by cquery_inheritance_hierarchy.cc:Expand generic lambda + // Used by ccls_inheritance_hierarchy.cc:Expand generic lambda std::string_view DetailedName(bool) const { return detailed_name; } }; template @@ -464,7 +464,7 @@ struct IndexFile { // For MessagePack cache files. // JSON has good forward compatibility because field addition/deletion do not // harm but currently no efforts have been made to make old MessagePack cache - // files accepted by newer cquery. + // files accepted by newer ccls. static const int kMinorVersion; std::string path; @@ -519,7 +519,7 @@ struct NamespaceHelper { // |desired_index_file| is the (h or cc) file which has actually changed. // |dependencies| are the existing dependencies of |import_file| if this is a // reparse. -optional>> Parse( +std::optional>> Parse( Config* config, FileConsumerSharedState* file_consumer_shared, std::string file, @@ -528,7 +528,7 @@ optional>> Parse( PerformanceImportFile* perf, ClangIndex* index, bool dump_ast = false); -optional>> ParseWithTu( +std::optional>> ParseWithTu( Config* config, FileConsumerSharedState* file_consumer_shared, PerformanceImportFile* perf, diff --git a/src/lex_utils.cc b/src/lex_utils.cc index ebbe496a..ff040688 100644 --- a/src/lex_utils.cc +++ b/src/lex_utils.cc @@ -47,7 +47,7 @@ lsPosition CharPos(std::string_view search, } // TODO: eliminate |line_number| param. -optional ExtractQuotedRange(int line_number, const std::string& line) { +std::optional ExtractQuotedRange(int line_number, const std::string& line) { // Find starting and ending quote. int start = 0; while (start < (int)line.size()) { @@ -57,7 +57,7 @@ optional ExtractQuotedRange(int line_number, const std::string& line) { break; } if (start == (int)line.size()) - return nullopt; + return std::nullopt; int end = (int)line.size(); while (end > 0) { @@ -68,14 +68,14 @@ optional ExtractQuotedRange(int line_number, const std::string& line) { } if (start >= end) - return nullopt; + return std::nullopt; return lsRange(lsPosition(line_number, start), lsPosition(line_number, end)); } void LexFunctionDeclaration(const std::string& buffer_content, lsPosition declaration_spelling, - optional type_name, + std::optional type_name, std::string* insert_text, int* newlines_after_name) { int name_start = GetOffsetForPosition(declaration_spelling, buffer_content); @@ -245,7 +245,7 @@ TEST_SUITE("LexFunctionDeclaration") { std::string insert_text; int newlines_after_name = 0; - LexFunctionDeclaration(buffer_content, declaration, nullopt, &insert_text, + LexFunctionDeclaration(buffer_content, declaration, std::nullopt, &insert_text, &newlines_after_name); REQUIRE(insert_text == "void Foo() {\n}"); REQUIRE(newlines_after_name == 0); @@ -286,7 +286,7 @@ TEST_SUITE("LexFunctionDeclaration") { std::string insert_text; int newlines_after_name = 0; - LexFunctionDeclaration(buffer_content, declaration, nullopt, &insert_text, + LexFunctionDeclaration(buffer_content, declaration, std::nullopt, &insert_text, &newlines_after_name); REQUIRE(insert_text == "std::vector Foo() {\n}"); REQUIRE(newlines_after_name == 0); @@ -303,7 +303,7 @@ TEST_SUITE("LexFunctionDeclaration") { std::string insert_text; int newlines_after_name = 0; - LexFunctionDeclaration(buffer_content, declaration, nullopt, &insert_text, + LexFunctionDeclaration(buffer_content, declaration, std::nullopt, &insert_text, &newlines_after_name); REQUIRE(insert_text == "std::function < int() > \n Foo() {\n}"); REQUIRE(newlines_after_name == 0); @@ -320,7 +320,7 @@ TEST_SUITE("LexFunctionDeclaration") { std::string insert_text; int newlines_after_name = 0; - LexFunctionDeclaration(buffer_content, declaration, nullopt, &insert_text, + LexFunctionDeclaration(buffer_content, declaration, std::nullopt, &insert_text, &newlines_after_name); REQUIRE(insert_text == "void Foo(int a,\n\n int b) {\n}"); REQUIRE(newlines_after_name == 2); diff --git a/src/lex_utils.h b/src/lex_utils.h index 7d860ace..6fbc6864 100644 --- a/src/lex_utils.h +++ b/src/lex_utils.h @@ -2,7 +2,7 @@ #include "lsp.h" -#include +#include #include #include @@ -15,11 +15,11 @@ lsPosition CharPos(std::string_view search, int character_offset = 0); // TODO: eliminate |line_number| param. -optional ExtractQuotedRange(int line_number, const std::string& line); +std::optional ExtractQuotedRange(int line_number, const std::string& line); void LexFunctionDeclaration(const std::string& buffer_content, lsPosition declaration_spelling, - optional type_name, + std::optional type_name, std::string* insert_text, int* newlines_after_name); diff --git a/src/lsp.cc b/src/lsp.cc index 07daebe6..bebe3cf8 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -20,16 +20,16 @@ lsVersionedTextDocumentIdentifier::AsTextDocumentIdentifier() const { } // Reads a JsonRpc message. |read| returns the next input character. -optional ReadJsonRpcContentFrom( - std::function()> read) { +std::optional ReadJsonRpcContentFrom( + std::function()> read) { // Read the content length. It is terminated by the "\r\n" sequence. int exit_seq = 0; std::string stringified_content_length; while (true) { - optional opt_c = read(); + std::optional opt_c = read(); if (!opt_c) { LOG_S(INFO) << "No more input when reading content length header"; - return nullopt; + return std::nullopt; } char c = *opt_c; @@ -47,22 +47,22 @@ optional ReadJsonRpcContentFrom( // There is always a "\r\n" sequence before the actual content. auto expect_char = [&](char expected) { - optional opt_c = read(); + std::optional opt_c = read(); return opt_c && *opt_c == expected; }; if (!expect_char('\r') || !expect_char('\n')) { LOG_S(INFO) << "Unexpected token (expected \r\n sequence)"; - return nullopt; + return std::nullopt; } // Read content. std::string content; content.reserve(content_length); for (int i = 0; i < content_length; ++i) { - optional c = read(); + std::optional c = read(); if (!c) { LOG_S(INFO) << "No more input when reading content body"; - return nullopt; + return std::nullopt; } content += *c; } @@ -72,13 +72,13 @@ optional ReadJsonRpcContentFrom( return content; } -std::function()> MakeContentReader(std::string* content, +std::function()> MakeContentReader(std::string* content, bool can_be_empty) { - return [content, can_be_empty]() -> optional { + return [content, can_be_empty]() -> std::optional { if (!can_be_empty) REQUIRE(!content->empty()); if (content->empty()) - return nullopt; + return std::nullopt; char c = (*content)[0]; content->erase(content->begin()); return c; @@ -94,7 +94,7 @@ TEST_SUITE("FindIncludeLine") { return got.value(); }; - auto parse_incorrect = [](std::string content) -> optional { + auto parse_incorrect = [](std::string content) -> std::optional { auto reader = MakeContentReader(&content, true /*can_be_empty*/); return ReadJsonRpcContentFrom(reader); }; @@ -103,15 +103,15 @@ TEST_SUITE("FindIncludeLine") { REQUIRE(parse_correct("Content-Length: 1\r\n\r\na") == "a"); REQUIRE(parse_correct("Content-Length: 4\r\n\r\nabcd") == "abcd"); - REQUIRE(parse_incorrect("ggg") == optional()); + REQUIRE(parse_incorrect("ggg") == std::optional()); REQUIRE(parse_incorrect("Content-Length: 0\r\n") == - optional()); + std::optional()); REQUIRE(parse_incorrect("Content-Length: 5\r\n\r\nab") == - optional()); + std::optional()); } } -optional ReadCharFromStdinBlocking() { +std::optional ReadCharFromStdinBlocking() { // We do not use std::cin because it does not read bytes once stuck in // cin.bad(). We can call cin.clear() but C++ iostream has other annoyance // like std::{cin,cout} is tied by default, which causes undesired cout flush @@ -119,12 +119,12 @@ optional ReadCharFromStdinBlocking() { int c = getchar(); if (c >= 0) return c; - return nullopt; + return std::nullopt; } -optional MessageRegistry::ReadMessageFromStdin( +std::optional MessageRegistry::ReadMessageFromStdin( std::unique_ptr* message) { - optional content = + std::optional content = ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking); if (!content) { LOG_S(ERROR) << "Failed to read JsonRpc input; exiting"; @@ -139,7 +139,7 @@ optional MessageRegistry::ReadMessageFromStdin( return Parse(json_reader, message); } -optional MessageRegistry::Parse( +std::optional MessageRegistry::Parse( Reader& visitor, std::unique_ptr* message) { if (!visitor.HasMember("jsonrpc") || @@ -158,7 +158,7 @@ optional MessageRegistry::Parse( Allocator& allocator = allocators[method]; try { allocator(visitor, message); - return nullopt; + return std::nullopt; } catch (std::invalid_argument& e) { // *message is partially deserialized but some field (e.g. |id|) are likely // available. diff --git a/src/lsp.h b/src/lsp.h index 88e06358..32692db3 100644 --- a/src/lsp.h +++ b/src/lsp.h @@ -35,9 +35,9 @@ struct MessageRegistry { std::function*)>; std::unordered_map allocators; - optional ReadMessageFromStdin( + std::optional ReadMessageFromStdin( std::unique_ptr* message); - optional Parse(Reader& visitor, + std::optional Parse(Reader& visitor, std::unique_ptr* message); }; @@ -196,7 +196,7 @@ enum class lsSymbolKind : uint8_t { // non-type template parameters). TypeParameter = 26, - // cquery extensions + // ccls extensions // See also https://github.com/Microsoft/language-server-protocol/issues/344 // for new SymbolKind clang/Index/IndexSymbol.h clang::index::SymbolKind TypeAlias = 252, @@ -206,12 +206,12 @@ enum class lsSymbolKind : uint8_t { }; MAKE_REFLECT_TYPE_PROXY(lsSymbolKind); -// cquery extension +// ccls extension struct lsLocationEx : lsLocation { - optional containerName; - optional parentKind; + std::optional containerName; + std::optional parentKind; // Avoid circular dependency on symbol.h - optional role; + std::optional role; }; MAKE_REFLECT_STRUCT(lsLocationEx, uri, range, containerName, parentKind, role); @@ -240,7 +240,7 @@ struct lsCodeLens { // The range in which this code lens is valid. Should only span a single line. lsRange range; // The command this code lens represents. - optional> command; + std::optional> command; // A data entry field that is preserved on a code lens item between // a code lens and a code lens resolve request. TData data; @@ -337,7 +337,7 @@ MAKE_REFLECT_STRUCT(lsFormattingOptions, tabSize, insertSpaces); // MarkedString can be used to render human readable text. It is either a // markdown string or a code-block that provides a language and a code snippet. -// The language identifier is sematically equal to the optional language +// The language identifier is sematically equal to the std::optional language // identifier in fenced code blocks in GitHub issues. See // https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting // @@ -357,9 +357,9 @@ MAKE_REFLECT_STRUCT(lsMarkedString1, language, value); struct lsTextDocumentContentChangeEvent { // The range of the document that changed. - optional range; + std::optional range; // The length of the range that got replaced. - optional rangeLength; + std::optional rangeLength; // The new text of the range/document. std::string text; }; diff --git a/src/lsp_code_action.h b/src/lsp_code_action.h index 30c049a8..44aa1381 100644 --- a/src/lsp_code_action.h +++ b/src/lsp_code_action.h @@ -19,7 +19,7 @@ struct lsCodeLensCommandArguments { std::vector locations; }; -// FIXME Don't use array in vscode-cquery +// FIXME Don't use array in vscode-ccls inline void Reflect(Writer& visitor, lsCodeLensCommandArguments& value) { visitor.StartArray(3); Reflect(visitor, value.uri); diff --git a/src/lsp_completion.h b/src/lsp_completion.h index 04105f2c..1e49b39d 100644 --- a/src/lsp_completion.h +++ b/src/lsp_completion.h @@ -69,7 +69,7 @@ struct lsCompletionItem { std::string detail; // A human-readable string that represents a doc-comment. - optional documentation; + std::optional documentation; // Internal information to order candidates. int score_; @@ -84,7 +84,7 @@ struct lsCompletionItem { // A string that should be used when filtering a set of // completion items. When `falsy` the label is used. - optional filterText; + std::optional filterText; // A string that should be inserted a document when selecting // this completion. When `falsy` the label is used. @@ -99,14 +99,14 @@ struct lsCompletionItem { // // *Note:* The range of the edit must be a single line range and it must // contain the position at which completion has been requested. - optional textEdit; + std::optional textEdit; - // An optional array of additional text edits that are applied when + // An std::optional array of additional text edits that are applied when // selecting this completion. Edits must not overlap with the main edit // nor with themselves. // std::vector additionalTextEdits; - // An optional command that is executed *after* inserting this completion. + // An std::optional command that is executed *after* inserting this completion. // *Note* that additional modifications to the current document should be // described with the additionalTextEdits-property. Command command; diff --git a/src/lsp_diagnostic.h b/src/lsp_diagnostic.h index 000980cd..535047d5 100644 --- a/src/lsp_diagnostic.h +++ b/src/lsp_diagnostic.h @@ -20,14 +20,14 @@ struct lsDiagnostic { // The diagnostic's severity. Can be omitted. If omitted it is up to the // client to interpret diagnostics as error, warning, info or hint. - optional severity; + std::optional severity; // The diagnostic's code. Can be omitted. int code = 0; // A human-readable string describing the source of this // diagnostic, e.g. 'typescript' or 'super lint'. - std::string source = "cquery"; + std::string source = "ccls"; // The diagnostic's message. std::string message; @@ -63,7 +63,7 @@ struct Out_Error : public lsOutMessage { // A Primitive or Structured value that contains additional // information about the error. Can be omitted. - // optional data; + // std::optional data; }; lsRequestId id; diff --git a/src/match.cc b/src/match.cc index 21f0b55f..6f6bda56 100644 --- a/src/match.cc +++ b/src/match.cc @@ -6,7 +6,7 @@ #include // static -optional Matcher::Create(const std::string& search) { +std::optional Matcher::Create(const std::string& search) { /* std::string real_search; real_search.reserve(search.size() * 3 + 2); @@ -30,10 +30,10 @@ optional Matcher::Create(const std::string& search) { Out_ShowLogMessage out; out.display_type = Out_ShowLogMessage::DisplayType::Show; out.params.type = lsMessageType::Error; - out.params.message = "cquery: Parsing EMCAScript regex \"" + search + + out.params.message = "ccls: Parsing EMCAScript regex \"" + search + "\" failed; " + e.what(); QueueManager::WriteStdout(kMethodType_Unknown, out); - return nullopt; + return std::nullopt; } } @@ -46,12 +46,12 @@ bool Matcher::IsMatch(const std::string& value) const { GroupMatch::GroupMatch(const std::vector& whitelist, const std::vector& blacklist) { for (const std::string& entry : whitelist) { - optional m = Matcher::Create(entry); + std::optional m = Matcher::Create(entry); if (m) this->whitelist.push_back(*m); } for (const std::string& entry : blacklist) { - optional m = Matcher::Create(entry); + std::optional m = Matcher::Create(entry); if (m) this->blacklist.push_back(*m); } diff --git a/src/match.h b/src/match.h index 6e7be8f9..46b8610c 100644 --- a/src/match.h +++ b/src/match.h @@ -1,13 +1,13 @@ #pragma once -#include +#include #include #include #include struct Matcher { - static optional Create(const std::string& search); + static std::optional Create(const std::string& search); bool IsMatch(const std::string& value) const; diff --git a/src/maybe.h b/src/maybe.h index 09d07f8f..c26c9708 100644 --- a/src/maybe.h +++ b/src/maybe.h @@ -1,10 +1,10 @@ #pragma once -#include +#include #include -// Like optional, but the stored data is responsible for containing the empty +// Like std::optional, but the stored data is responsible for containing the empty // state. T should define a function `bool T::HasValueForMaybe_()`. template class Maybe { @@ -30,13 +30,13 @@ class Maybe { bool HasValue() const { return storage.HasValueForMaybe_(); } explicit operator bool() const { return HasValue(); } - operator optional() const { + operator std::optional() const { if (HasValue()) return storage; - return nullopt; + return std::nullopt; } - void operator=(optional&& o) { storage = o ? *o : T(); } + void operator=(std::optional&& o) { storage = o ? *o : T(); } // Does not test if has_value() bool operator==(const Maybe& o) const { return storage == o.storage; } diff --git a/src/message_handler.cc b/src/message_handler.cc index e06e9f4d..bcb97837 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -12,23 +12,23 @@ namespace { -struct Out_CquerySetInactiveRegion - : public lsOutMessage { +struct Out_CclsSetInactiveRegion + : public lsOutMessage { struct Params { lsDocumentUri uri; std::vector inactiveRegions; }; - std::string method = "$cquery/setInactiveRegions"; + std::string method = "$ccls/setInactiveRegions"; Params params; }; -MAKE_REFLECT_STRUCT(Out_CquerySetInactiveRegion::Params, uri, inactiveRegions); -MAKE_REFLECT_STRUCT(Out_CquerySetInactiveRegion, jsonrpc, method, params); +MAKE_REFLECT_STRUCT(Out_CclsSetInactiveRegion::Params, uri, inactiveRegions); +MAKE_REFLECT_STRUCT(Out_CclsSetInactiveRegion, jsonrpc, method, params); struct ScanLineEvent { lsPosition pos; lsPosition end_pos; // Second key when there is a tie for insertion events. int id; - Out_CqueryPublishSemanticHighlighting::Symbol* symbol; + Out_CclsPublishSemanticHighlighting::Symbol* symbol; bool operator<(const ScanLineEvent& other) const { // See the comments below when insertion/deletion events are inserted. if (!(pos == other.pos)) @@ -55,7 +55,7 @@ std::vector* MessageHandler::message_handlers = nullptr; bool FindFileOrFail(QueryDatabase* db, const Project* project, - optional id, + std::optional id, const std::string& absolute_path, QueryFile** out_query_file, QueryFileId* out_file_id) { @@ -107,14 +107,14 @@ bool FindFileOrFail(QueryDatabase* db, void EmitInactiveLines(WorkingFile* working_file, const std::vector& inactive_regions) { - Out_CquerySetInactiveRegion out; + Out_CclsSetInactiveRegion out; out.params.uri = lsDocumentUri::FromPath(working_file->filename); for (Range skipped : inactive_regions) { - optional ls_skipped = GetLsRange(working_file, skipped); + std::optional ls_skipped = GetLsRange(working_file, skipped); if (ls_skipped) out.params.inactiveRegions.push_back(*ls_skipped); } - QueueManager::WriteStdout(kMethodType_CqueryPublishInactiveRegions, out); + QueueManager::WriteStdout(kMethodType_CclsPublishInactiveRegions, out); } void EmitSemanticHighlighting(QueryDatabase* db, @@ -128,7 +128,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, semantic_cache->GetCacheForFile(file->def->path); // Group symbols together. - std::unordered_map + std::unordered_map grouped_symbols; for (SymbolRef sym : file->def->all_symbols) { std::string_view detailed_name; @@ -214,13 +214,13 @@ void EmitSemanticHighlighting(QueryDatabase* db, continue; // applies to for loop } - optional loc = GetLsRange(working_file, sym.range); + std::optional loc = GetLsRange(working_file, sym.range); if (loc) { auto it = grouped_symbols.find(sym); if (it != grouped_symbols.end()) { it->second.ranges.push_back(*loc); } else { - Out_CqueryPublishSemanticHighlighting::Symbol symbol; + Out_CclsPublishSemanticHighlighting::Symbol symbol; symbol.stableId = semantic_cache_for_file->GetStableId( sym.kind, std::string(detailed_name)); symbol.parentKind = parent_kind; @@ -236,7 +236,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, std::vector events; int id = 0; for (auto& entry : grouped_symbols) { - Out_CqueryPublishSemanticHighlighting::Symbol& symbol = entry.second; + Out_CclsPublishSemanticHighlighting::Symbol& symbol = entry.second; for (auto& loc : symbol.ranges) { // For ranges sharing the same start point, the one with leftmost end // point comes first. @@ -272,12 +272,12 @@ void EmitSemanticHighlighting(QueryDatabase* db, } // Publish. - Out_CqueryPublishSemanticHighlighting out; + Out_CclsPublishSemanticHighlighting out; out.params.uri = lsDocumentUri::FromPath(working_file->filename); for (auto& entry : grouped_symbols) if (entry.second.ranges.size()) out.params.symbols.push_back(entry.second); - QueueManager::WriteStdout(kMethodType_CqueryPublishSemanticHighlighting, out); + QueueManager::WriteStdout(kMethodType_CclsPublishSemanticHighlighting, out); } bool ShouldIgnoreFileForIndexing(const std::string& path) { diff --git a/src/message_handler.h b/src/message_handler.h index e838bfb1..49165a59 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -4,7 +4,7 @@ #include "method.h" #include "query.h" -#include +#include #include #include @@ -25,8 +25,8 @@ struct TimestampManager; struct WorkingFile; struct WorkingFiles; -struct Out_CqueryPublishSemanticHighlighting - : public lsOutMessage { +struct Out_CclsPublishSemanticHighlighting + : public lsOutMessage { struct Symbol { int stableId = 0; lsSymbolKind parentKind; @@ -38,19 +38,19 @@ struct Out_CqueryPublishSemanticHighlighting lsDocumentUri uri; std::vector symbols; }; - std::string method = "$cquery/publishSemanticHighlighting"; + std::string method = "$ccls/publishSemanticHighlighting"; Params params; }; -MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol, +MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol, stableId, parentKind, kind, storage, ranges); -MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params, +MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params, uri, symbols); -MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting, +MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting, jsonrpc, method, params); @@ -107,7 +107,7 @@ struct BaseMessageHandler : MessageHandler { bool FindFileOrFail(QueryDatabase* db, const Project* project, - optional id, + std::optional id, const std::string& absolute_path, QueryFile** out_query_file, QueryFileId* out_file_id = nullptr); diff --git a/src/messages/cquery_base.cc b/src/messages/ccls_base.cc similarity index 80% rename from src/messages/cquery_base.cc rename to src/messages/ccls_base.cc index c3831433..f1c31f29 100644 --- a/src/messages/cquery_base.cc +++ b/src/messages/ccls_base.cc @@ -4,20 +4,20 @@ namespace { -MethodType kMethodType = "$cquery/base"; +MethodType kMethodType = "$ccls/base"; -struct In_CqueryBase : public RequestInMessage { +struct In_CclsBase : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; -MAKE_REFLECT_STRUCT(In_CqueryBase, id, params); -REGISTER_IN_MESSAGE(In_CqueryBase); +MAKE_REFLECT_STRUCT(In_CclsBase, id, params); +REGISTER_IN_MESSAGE(In_CclsBase); -struct Handler_CqueryBase : BaseMessageHandler { +struct Handler_CclsBase : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryBase* request) override { + void Run(In_CclsBase* request) override { QueryFile* file; if (!FindFileOrFail(db, project, request->id, request->params.textDocument.uri.GetPath(), &file)) { @@ -48,5 +48,5 @@ struct Handler_CqueryBase : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryBase); +REGISTER_MESSAGE_HANDLER(Handler_CclsBase); } // namespace diff --git a/src/messages/cquery_call_hierarchy.cc b/src/messages/ccls_call_hierarchy.cc similarity index 85% rename from src/messages/cquery_call_hierarchy.cc rename to src/messages/ccls_call_hierarchy.cc index 9f6e576f..04e117f8 100644 --- a/src/messages/cquery_call_hierarchy.cc +++ b/src/messages/ccls_call_hierarchy.cc @@ -6,7 +6,7 @@ namespace { -MethodType kMethodType = "$cquery/callHierarchy"; +MethodType kMethodType = "$ccls/callHierarchy"; enum class CallType : uint8_t { Direct = 0, @@ -20,7 +20,7 @@ bool operator&(CallType lhs, CallType rhs) { return uint8_t(lhs) & uint8_t(rhs); } -struct In_CqueryCallHierarchy : public RequestInMessage { +struct In_CclsCallHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { @@ -43,7 +43,7 @@ struct In_CqueryCallHierarchy : public RequestInMessage { Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryCallHierarchy::Params, +MAKE_REFLECT_STRUCT(In_CclsCallHierarchy::Params, textDocument, position, id, @@ -51,10 +51,10 @@ MAKE_REFLECT_STRUCT(In_CqueryCallHierarchy::Params, callType, detailedName, levels); -MAKE_REFLECT_STRUCT(In_CqueryCallHierarchy, id, params); -REGISTER_IN_MESSAGE(In_CqueryCallHierarchy); +MAKE_REFLECT_STRUCT(In_CclsCallHierarchy, id, params); +REGISTER_IN_MESSAGE(In_CclsCallHierarchy); -struct Out_CqueryCallHierarchy : public lsOutMessage { +struct Out_CclsCallHierarchy : public lsOutMessage { struct Entry { QueryFuncId id; std::string_view name; @@ -66,19 +66,19 @@ struct Out_CqueryCallHierarchy : public lsOutMessage { }; lsRequestId id; - optional result; + std::optional result; }; -MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy::Entry, +MAKE_REFLECT_STRUCT(Out_CclsCallHierarchy::Entry, id, name, location, callType, numChildren, children); -MAKE_REFLECT_STRUCT(Out_CqueryCallHierarchy, jsonrpc, id, result); +MAKE_REFLECT_STRUCT(Out_CclsCallHierarchy, jsonrpc, id, result); bool Expand(MessageHandler* m, - Out_CqueryCallHierarchy::Entry* entry, + Out_CclsCallHierarchy::Entry* entry, bool callee, CallType call_type, bool detailed_name, @@ -91,7 +91,7 @@ bool Expand(MessageHandler* m, auto handle = [&](Use use, CallType call_type) { entry->numChildren++; if (levels > 0) { - Out_CqueryCallHierarchy::Entry entry1; + Out_CclsCallHierarchy::Entry entry1; entry1.id = QueryFuncId(use.id); if (auto loc = GetLsLocation(m->db, m->working_files, use)) entry1.location = *loc; @@ -159,11 +159,11 @@ bool Expand(MessageHandler* m, return true; } -struct Handler_CqueryCallHierarchy - : BaseMessageHandler { +struct Handler_CclsCallHierarchy + : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - optional BuildInitial(QueryFuncId root_id, + std::optional BuildInitial(QueryFuncId root_id, bool callee, CallType call_type, bool detailed_name, @@ -172,11 +172,11 @@ struct Handler_CqueryCallHierarchy if (!def) return {}; - Out_CqueryCallHierarchy::Entry entry; + Out_CclsCallHierarchy::Entry entry; entry.id = root_id; entry.callType = CallType::Direct; if (def->spell) { - if (optional loc = + if (std::optional loc = GetLsLocation(db, working_files, *def->spell)) entry.location = *loc; } @@ -184,13 +184,13 @@ struct Handler_CqueryCallHierarchy return entry; } - void Run(In_CqueryCallHierarchy* request) override { + void Run(In_CclsCallHierarchy* request) override { const auto& params = request->params; - Out_CqueryCallHierarchy out; + Out_CclsCallHierarchy out; out.id = request->id; if (params.id) { - Out_CqueryCallHierarchy::Entry entry; + Out_CclsCallHierarchy::Entry entry; entry.id = *params.id; entry.callType = CallType::Direct; if (entry.id.id < db->funcs.size()) @@ -218,6 +218,6 @@ struct Handler_CqueryCallHierarchy QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryCallHierarchy); +REGISTER_MESSAGE_HANDLER(Handler_CclsCallHierarchy); } // namespace diff --git a/src/messages/cquery_callers.cc b/src/messages/ccls_callers.cc similarity index 78% rename from src/messages/cquery_callers.cc rename to src/messages/ccls_callers.cc index 701aefbe..0e7904fc 100644 --- a/src/messages/cquery_callers.cc +++ b/src/messages/ccls_callers.cc @@ -3,18 +3,18 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/callers"; +MethodType kMethodType = "$ccls/callers"; -struct In_CqueryCallers : public RequestInMessage { +struct In_CclsCallers : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; -MAKE_REFLECT_STRUCT(In_CqueryCallers, id, params); -REGISTER_IN_MESSAGE(In_CqueryCallers); +MAKE_REFLECT_STRUCT(In_CclsCallers, id, params); +REGISTER_IN_MESSAGE(In_CclsCallers); -struct Handler_CqueryCallers : BaseMessageHandler { +struct Handler_CclsCallers : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryCallers* request) override { + void Run(In_CclsCallers* request) override { QueryFile* file; if (!FindFileOrFail(db, project, request->id, request->params.textDocument.uri.GetPath(), &file)) { @@ -44,5 +44,5 @@ struct Handler_CqueryCallers : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryCallers); +REGISTER_MESSAGE_HANDLER(Handler_CclsCallers); } // namespace diff --git a/src/messages/cquery_derived.cc b/src/messages/ccls_derived.cc similarity index 78% rename from src/messages/cquery_derived.cc rename to src/messages/ccls_derived.cc index 9700e88f..ad415ace 100644 --- a/src/messages/cquery_derived.cc +++ b/src/messages/ccls_derived.cc @@ -3,18 +3,18 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/derived"; +MethodType kMethodType = "$ccls/derived"; -struct In_CqueryDerived : public RequestInMessage { +struct In_CclsDerived : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; -MAKE_REFLECT_STRUCT(In_CqueryDerived, id, params); -REGISTER_IN_MESSAGE(In_CqueryDerived); +MAKE_REFLECT_STRUCT(In_CclsDerived, id, params); +REGISTER_IN_MESSAGE(In_CclsDerived); -struct Handler_CqueryDerived : BaseMessageHandler { +struct Handler_CclsDerived : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryDerived* request) override { + void Run(In_CclsDerived* request) override { QueryFile* file; if (!FindFileOrFail(db, project, request->id, request->params.textDocument.uri.GetPath(), &file)) { @@ -45,5 +45,5 @@ struct Handler_CqueryDerived : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryDerived); +REGISTER_MESSAGE_HANDLER(Handler_CclsDerived); } // namespace diff --git a/src/messages/cquery_did_view.cc b/src/messages/ccls_did_view.cc similarity index 57% rename from src/messages/cquery_did_view.cc rename to src/messages/ccls_did_view.cc index 73da37da..ece233b3 100644 --- a/src/messages/cquery_did_view.cc +++ b/src/messages/ccls_did_view.cc @@ -3,30 +3,30 @@ #include "working_files.h" namespace { -MethodType kMethodType = "$cquery/textDocumentDidView"; +MethodType kMethodType = "$ccls/textDocumentDidView"; -struct In_CqueryTextDocumentDidView : public NotificationInMessage { +struct In_CclsTextDocumentDidView : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { lsDocumentUri textDocumentUri; }; Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryTextDocumentDidView::Params, textDocumentUri); -MAKE_REFLECT_STRUCT(In_CqueryTextDocumentDidView, params); -REGISTER_IN_MESSAGE(In_CqueryTextDocumentDidView); +MAKE_REFLECT_STRUCT(In_CclsTextDocumentDidView::Params, textDocumentUri); +MAKE_REFLECT_STRUCT(In_CclsTextDocumentDidView, params); +REGISTER_IN_MESSAGE(In_CclsTextDocumentDidView); -struct Handler_CqueryDidView - : BaseMessageHandler { +struct Handler_CclsDidView + : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryTextDocumentDidView* request) override { + void Run(In_CclsTextDocumentDidView* request) override { std::string path = request->params.textDocumentUri.GetPath(); WorkingFile* working_file = working_files->GetFileByFilename(path); if (!working_file) return; QueryFile* file = nullptr; - if (!FindFileOrFail(db, project, nullopt, path, &file)) + if (!FindFileOrFail(db, project, std::nullopt, path, &file)) return; clang_complete->NotifyView(path); @@ -36,5 +36,5 @@ struct Handler_CqueryDidView } } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryDidView); +REGISTER_MESSAGE_HANDLER(Handler_CclsDidView); } // namespace diff --git a/src/messages/cquery_file_info.cc b/src/messages/ccls_file_info.cc similarity index 65% rename from src/messages/cquery_file_info.cc rename to src/messages/ccls_file_info.cc index a72612d6..94475b69 100644 --- a/src/messages/cquery_file_info.cc +++ b/src/messages/ccls_file_info.cc @@ -3,36 +3,36 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/fileInfo"; +MethodType kMethodType = "$ccls/fileInfo"; struct lsDocumentSymbolParams { lsTextDocumentIdentifier textDocument; }; MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument); -struct In_CqueryFileInfo : public RequestInMessage { +struct In_CclsFileInfo : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsDocumentSymbolParams params; }; -MAKE_REFLECT_STRUCT(In_CqueryFileInfo, id, params); -REGISTER_IN_MESSAGE(In_CqueryFileInfo); +MAKE_REFLECT_STRUCT(In_CclsFileInfo, id, params); +REGISTER_IN_MESSAGE(In_CclsFileInfo); -struct Out_CqueryFileInfo : public lsOutMessage { +struct Out_CclsFileInfo : public lsOutMessage { lsRequestId id; QueryFile::Def result; }; -MAKE_REFLECT_STRUCT(Out_CqueryFileInfo, jsonrpc, id, result); +MAKE_REFLECT_STRUCT(Out_CclsFileInfo, jsonrpc, id, result); -struct Handler_CqueryFileInfo : BaseMessageHandler { +struct Handler_CclsFileInfo : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryFileInfo* request) override { + void Run(In_CclsFileInfo* request) override { QueryFile* file; if (!FindFileOrFail(db, project, request->id, request->params.textDocument.uri.GetPath(), &file)) { return; } - Out_CqueryFileInfo out; + Out_CclsFileInfo out; out.id = request->id; // Expose some fields of |QueryFile::Def|. out.result.path = file->def->path; @@ -43,5 +43,5 @@ struct Handler_CqueryFileInfo : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryFileInfo); +REGISTER_MESSAGE_HANDLER(Handler_CclsFileInfo); } // namespace diff --git a/src/messages/cquery_freshen_index.cc b/src/messages/ccls_freshen_index.cc similarity index 81% rename from src/messages/cquery_freshen_index.cc rename to src/messages/ccls_freshen_index.cc index e52b5236..8e25a7b2 100644 --- a/src/messages/cquery_freshen_index.cc +++ b/src/messages/ccls_freshen_index.cc @@ -13,9 +13,9 @@ #include namespace { -MethodType kMethodType = "$cquery/freshenIndex"; +MethodType kMethodType = "$ccls/freshenIndex"; -struct In_CqueryFreshenIndex : public NotificationInMessage { +struct In_CclsFreshenIndex : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { bool dependencies = true; @@ -24,16 +24,16 @@ struct In_CqueryFreshenIndex : public NotificationInMessage { }; Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryFreshenIndex::Params, +MAKE_REFLECT_STRUCT(In_CclsFreshenIndex::Params, dependencies, whitelist, blacklist); -MAKE_REFLECT_STRUCT(In_CqueryFreshenIndex, params); -REGISTER_IN_MESSAGE(In_CqueryFreshenIndex); +MAKE_REFLECT_STRUCT(In_CclsFreshenIndex, params); +REGISTER_IN_MESSAGE(In_CclsFreshenIndex); -struct Handler_CqueryFreshenIndex : BaseMessageHandler { +struct Handler_CclsFreshenIndex : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryFreshenIndex* request) override { + void Run(In_CclsFreshenIndex* request) override { LOG_S(INFO) << "Freshening " << project->entries.size() << " files"; // TODO: think about this flow and test it more. @@ -65,11 +65,11 @@ struct Handler_CqueryFreshenIndex : BaseMessageHandler { q.pop(); need_index.insert(file->def->path); - optional modification_timestamp = + std::optional modification_timestamp = GetLastModificationTime(file->def->path); if (!modification_timestamp) continue; - optional cached_modification = + std::optional cached_modification = timestamp_manager->GetLastCachedModificationTime(cache_manager.get(), file->def->path); if (modification_timestamp != cached_modification) @@ -89,8 +89,8 @@ struct Handler_CqueryFreshenIndex : BaseMessageHandler { // Send index requests for every file. project->Index(config, QueueManager::instance(), working_files, std::monostate()); - time.ResetAndPrint("[perf] Dispatched $cquery/freshenIndex index requests"); + time.ResetAndPrint("[perf] Dispatched $ccls/freshenIndex index requests"); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryFreshenIndex); +REGISTER_MESSAGE_HANDLER(Handler_CclsFreshenIndex); } // namespace diff --git a/src/messages/cquery_index_file.cc b/src/messages/ccls_index_file.cc similarity index 68% rename from src/messages/cquery_index_file.cc rename to src/messages/ccls_index_file.cc index 9e106558..4dfac696 100644 --- a/src/messages/cquery_index_file.cc +++ b/src/messages/ccls_index_file.cc @@ -6,9 +6,9 @@ #include namespace { -MethodType kMethodType = "$cquery/indexFile"; +MethodType kMethodType = "$ccls/indexFile"; -struct In_CqueryIndexFile : public NotificationInMessage { +struct In_CclsIndexFile : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { std::string path; @@ -18,17 +18,17 @@ struct In_CqueryIndexFile : public NotificationInMessage { }; Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryIndexFile::Params, +MAKE_REFLECT_STRUCT(In_CclsIndexFile::Params, path, args, is_interactive, contents); -MAKE_REFLECT_STRUCT(In_CqueryIndexFile, params); -REGISTER_IN_MESSAGE(In_CqueryIndexFile); +MAKE_REFLECT_STRUCT(In_CclsIndexFile, params); +REGISTER_IN_MESSAGE(In_CclsIndexFile); -struct Handler_CqueryIndexFile : BaseMessageHandler { +struct Handler_CclsIndexFile : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryIndexFile* request) override { + void Run(In_CclsIndexFile* request) override { LOG_S(INFO) << "Indexing file " << request->params.path; QueueManager::instance()->index_request.PushBack( Index_Request(NormalizePath(request->params.path), request->params.args, @@ -36,5 +36,5 @@ struct Handler_CqueryIndexFile : BaseMessageHandler { ICacheManager::Make(config))); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryIndexFile); +REGISTER_MESSAGE_HANDLER(Handler_CclsIndexFile); } // namespace diff --git a/src/messages/cquery_inheritance_hierarchy.cc b/src/messages/ccls_inheritance_hierarchy.cc similarity index 78% rename from src/messages/cquery_inheritance_hierarchy.cc rename to src/messages/ccls_inheritance_hierarchy.cc index 17a0b1ba..29b9ad5e 100644 --- a/src/messages/cquery_inheritance_hierarchy.cc +++ b/src/messages/ccls_inheritance_hierarchy.cc @@ -3,9 +3,9 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/inheritanceHierarchy"; +MethodType kMethodType = "$ccls/inheritanceHierarchy"; -struct In_CqueryInheritanceHierarchy : public RequestInMessage { +struct In_CclsInheritanceHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { // If id+kind are specified, expand a node; otherwise textDocument+position @@ -24,7 +24,7 @@ struct In_CqueryInheritanceHierarchy : public RequestInMessage { Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryInheritanceHierarchy::Params, +MAKE_REFLECT_STRUCT(In_CclsInheritanceHierarchy::Params, textDocument, position, id, @@ -32,11 +32,11 @@ MAKE_REFLECT_STRUCT(In_CqueryInheritanceHierarchy::Params, derived, detailedName, levels); -MAKE_REFLECT_STRUCT(In_CqueryInheritanceHierarchy, id, params); -REGISTER_IN_MESSAGE(In_CqueryInheritanceHierarchy); +MAKE_REFLECT_STRUCT(In_CclsInheritanceHierarchy, id, params); +REGISTER_IN_MESSAGE(In_CclsInheritanceHierarchy); -struct Out_CqueryInheritanceHierarchy - : public lsOutMessage { +struct Out_CclsInheritanceHierarchy + : public lsOutMessage { struct Entry { Id id; SymbolKind kind; @@ -49,26 +49,26 @@ struct Out_CqueryInheritanceHierarchy std::vector children; }; lsRequestId id; - optional result; + std::optional result; }; -MAKE_REFLECT_STRUCT(Out_CqueryInheritanceHierarchy::Entry, +MAKE_REFLECT_STRUCT(Out_CclsInheritanceHierarchy::Entry, id, kind, name, location, numChildren, children); -MAKE_REFLECT_STRUCT(Out_CqueryInheritanceHierarchy, jsonrpc, id, result); +MAKE_REFLECT_STRUCT(Out_CclsInheritanceHierarchy, jsonrpc, id, result); bool Expand(MessageHandler* m, - Out_CqueryInheritanceHierarchy::Entry* entry, + Out_CclsInheritanceHierarchy::Entry* entry, bool derived, bool detailed_name, int levels); template bool ExpandHelper(MessageHandler* m, - Out_CqueryInheritanceHierarchy::Entry* entry, + Out_CclsInheritanceHierarchy::Entry* entry, bool derived, bool detailed_name, int levels, @@ -83,14 +83,14 @@ bool ExpandHelper(MessageHandler* m, else entry->name = def->ShortName(); if (def->spell) { - if (optional loc = + if (std::optional loc = GetLsLocation(m->db, m->working_files, *def->spell)) entry->location = *loc; } if (derived) { if (levels > 0) { for (auto id : entity.derived) { - Out_CqueryInheritanceHierarchy::Entry entry1; + Out_CclsInheritanceHierarchy::Entry entry1; entry1.id = id; entry1.kind = entry->kind; if (Expand(m, &entry1, derived, detailed_name, levels - 1)) @@ -102,7 +102,7 @@ bool ExpandHelper(MessageHandler* m, } else { if (levels > 0) { for (auto id : def->bases) { - Out_CqueryInheritanceHierarchy::Entry entry1; + Out_CclsInheritanceHierarchy::Entry entry1; entry1.id = id; entry1.kind = entry->kind; if (Expand(m, &entry1, derived, detailed_name, levels - 1)) @@ -116,7 +116,7 @@ bool ExpandHelper(MessageHandler* m, } bool Expand(MessageHandler* m, - Out_CqueryInheritanceHierarchy::Entry* entry, + Out_CclsInheritanceHierarchy::Entry* entry, bool derived, bool detailed_name, int levels) { @@ -128,26 +128,26 @@ bool Expand(MessageHandler* m, m->db->types[entry->id.id]); } -struct Handler_CqueryInheritanceHierarchy - : BaseMessageHandler { +struct Handler_CclsInheritanceHierarchy + : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - optional + std::optional BuildInitial(SymbolRef sym, bool derived, bool detailed_name, int levels) { - Out_CqueryInheritanceHierarchy::Entry entry; + Out_CclsInheritanceHierarchy::Entry entry; entry.id = sym.id; entry.kind = sym.kind; Expand(this, &entry, derived, detailed_name, levels); return entry; } - void Run(In_CqueryInheritanceHierarchy* request) override { + void Run(In_CclsInheritanceHierarchy* request) override { const auto& params = request->params; - Out_CqueryInheritanceHierarchy out; + Out_CclsInheritanceHierarchy out; out.id = request->id; if (params.id) { - Out_CqueryInheritanceHierarchy::Entry entry; + Out_CclsInheritanceHierarchy::Entry entry; entry.id = *params.id; entry.kind = params.kind; if (((entry.kind == SymbolKind::Func && entry.id.id < db->funcs.size()) || @@ -177,6 +177,6 @@ struct Handler_CqueryInheritanceHierarchy QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryInheritanceHierarchy); +REGISTER_MESSAGE_HANDLER(Handler_CclsInheritanceHierarchy); } // namespace diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/ccls_member_hierarchy.cc similarity index 82% rename from src/messages/cquery_member_hierarchy.cc rename to src/messages/ccls_member_hierarchy.cc index e98e53d5..619b5153 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/ccls_member_hierarchy.cc @@ -3,9 +3,9 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/memberHierarchy"; +MethodType kMethodType = "$ccls/memberHierarchy"; -struct In_CqueryMemberHierarchy : public RequestInMessage { +struct In_CclsMemberHierarchy : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } struct Params { @@ -22,17 +22,17 @@ struct In_CqueryMemberHierarchy : public RequestInMessage { Params params; }; -MAKE_REFLECT_STRUCT(In_CqueryMemberHierarchy::Params, +MAKE_REFLECT_STRUCT(In_CclsMemberHierarchy::Params, textDocument, position, id, detailedName, levels); -MAKE_REFLECT_STRUCT(In_CqueryMemberHierarchy, id, params); -REGISTER_IN_MESSAGE(In_CqueryMemberHierarchy); +MAKE_REFLECT_STRUCT(In_CclsMemberHierarchy, id, params); +REGISTER_IN_MESSAGE(In_CclsMemberHierarchy); -struct Out_CqueryMemberHierarchy - : public lsOutMessage { +struct Out_CclsMemberHierarchy + : public lsOutMessage { struct Entry { QueryTypeId id; std::string_view name; @@ -45,38 +45,38 @@ struct Out_CqueryMemberHierarchy std::vector children; }; lsRequestId id; - optional result; + std::optional result; }; -MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry, +MAKE_REFLECT_STRUCT(Out_CclsMemberHierarchy::Entry, id, name, fieldName, location, numChildren, children); -MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result); +MAKE_REFLECT_STRUCT(Out_CclsMemberHierarchy, jsonrpc, id, result); bool Expand(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, + Out_CclsMemberHierarchy::Entry* entry, bool detailed_name, int levels); // Add a field to |entry| which is a Func/Type. void DoField(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, + Out_CclsMemberHierarchy::Entry* entry, const QueryVar& var, bool detailed_name, int levels) { const QueryVar::Def* def1 = var.AnyDef(); if (!def1) return; - Out_CqueryMemberHierarchy::Entry entry1; + Out_CclsMemberHierarchy::Entry entry1; if (detailed_name) entry1.fieldName = def1->DetailedName(false); else entry1.fieldName = std::string(def1->ShortName()); if (def1->spell) { - if (optional loc = + if (std::optional loc = GetLsLocation(m->db, m->working_files, *def1->spell)) entry1.location = *loc; } @@ -92,7 +92,7 @@ void DoField(MessageHandler* m, // Expand a type node by adding members recursively to it. bool Expand(MessageHandler* m, - Out_CqueryMemberHierarchy::Entry* entry, + Out_CclsMemberHierarchy::Entry* entry, bool detailed_name, int levels) { const QueryType& type = m->db->types[entry->id.id]; @@ -125,17 +125,17 @@ bool Expand(MessageHandler* m, }); if (def->alias_of) { const QueryType::Def* def1 = m->db->types[def->alias_of->id].AnyDef(); - Out_CqueryMemberHierarchy::Entry entry1; + Out_CclsMemberHierarchy::Entry entry1; entry1.id = *def->alias_of; if (def1 && def1->spell) { // The declaration of target type. - if (optional loc = + if (std::optional loc = GetLsLocation(m->db, m->working_files, *def1->spell)) entry1.location = *loc; } else if (def->spell) { // Builtin types have no declaration but the typedef declaration // itself is useful. - if (optional loc = + if (std::optional loc = GetLsLocation(m->db, m->working_files, *def->spell)) entry1.location = *loc; } @@ -160,25 +160,25 @@ bool Expand(MessageHandler* m, return true; } -struct Handler_CqueryMemberHierarchy - : BaseMessageHandler { +struct Handler_CclsMemberHierarchy + : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - optional BuildInitial(QueryFuncId root_id, + std::optional BuildInitial(QueryFuncId root_id, bool detailed_name, int levels) { const auto* def = db->funcs[root_id.id].AnyDef(); if (!def) return {}; - Out_CqueryMemberHierarchy::Entry entry; + Out_CclsMemberHierarchy::Entry entry; // Not type, |id| is invalid. if (detailed_name) entry.name = def->DetailedName(false); else entry.name = std::string(def->ShortName()); if (def->spell) { - if (optional loc = + if (std::optional loc = GetLsLocation(db, working_files, *def->spell)) entry.location = *loc; } @@ -188,17 +188,17 @@ struct Handler_CqueryMemberHierarchy return entry; } - optional BuildInitial(QueryTypeId root_id, + std::optional BuildInitial(QueryTypeId root_id, bool detailed_name, int levels) { const auto* def = db->types[root_id.id].AnyDef(); if (!def) return {}; - Out_CqueryMemberHierarchy::Entry entry; + Out_CclsMemberHierarchy::Entry entry; entry.id = root_id; if (def->spell) { - if (optional loc = + if (std::optional loc = GetLsLocation(db, working_files, *def->spell)) entry.location = *loc; } @@ -206,13 +206,13 @@ struct Handler_CqueryMemberHierarchy return entry; } - void Run(In_CqueryMemberHierarchy* request) override { + void Run(In_CclsMemberHierarchy* request) override { const auto& params = request->params; - Out_CqueryMemberHierarchy out; + Out_CclsMemberHierarchy out; out.id = request->id; if (params.id) { - Out_CqueryMemberHierarchy::Entry entry; + Out_CclsMemberHierarchy::Entry entry; entry.id = *request->params.id; // entry.name is empty as it is known by the client. if (entry.id.id < db->types.size() && @@ -253,6 +253,6 @@ struct Handler_CqueryMemberHierarchy QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryMemberHierarchy); +REGISTER_MESSAGE_HANDLER(Handler_CclsMemberHierarchy); } // namespace diff --git a/src/messages/cquery_random.cc b/src/messages/ccls_random.cc similarity index 91% rename from src/messages/cquery_random.cc rename to src/messages/ccls_random.cc index 7bbf0761..f24471e7 100644 --- a/src/messages/cquery_random.cc +++ b/src/messages/ccls_random.cc @@ -7,13 +7,13 @@ #include namespace { -MethodType kMethodType = "$cquery/random"; +MethodType kMethodType = "$ccls/random"; -struct In_CqueryRandom : public RequestInMessage { +struct In_CclsRandom : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } }; -MAKE_REFLECT_STRUCT(In_CqueryRandom, id); -REGISTER_IN_MESSAGE(In_CqueryRandom); +MAKE_REFLECT_STRUCT(In_CclsRandom, id); +REGISTER_IN_MESSAGE(In_CclsRandom); const double kDeclWeight = 3; const double kDamping = 0.1; @@ -46,10 +46,10 @@ void Add(const std::unordered_map& sym2id, } } -struct Handler_CqueryRandom : BaseMessageHandler { +struct Handler_CclsRandom : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryRandom* request) override { + void Run(In_CclsRandom* request) override { std::unordered_map sym2id; std::vector syms; int n = 0; @@ -144,5 +144,5 @@ struct Handler_CqueryRandom : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryRandom); +REGISTER_MESSAGE_HANDLER(Handler_CclsRandom); } // namespace diff --git a/src/messages/cquery_vars.cc b/src/messages/ccls_vars.cc similarity index 80% rename from src/messages/cquery_vars.cc rename to src/messages/ccls_vars.cc index 8ac9816f..b9426487 100644 --- a/src/messages/cquery_vars.cc +++ b/src/messages/ccls_vars.cc @@ -3,20 +3,20 @@ #include "queue_manager.h" namespace { -MethodType kMethodType = "$cquery/vars"; +MethodType kMethodType = "$ccls/vars"; -struct In_CqueryVars : public RequestInMessage { +struct In_CclsVars : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } lsTextDocumentPositionParams params; }; -MAKE_REFLECT_STRUCT(In_CqueryVars, id, params); -REGISTER_IN_MESSAGE(In_CqueryVars); +MAKE_REFLECT_STRUCT(In_CclsVars, id, params); +REGISTER_IN_MESSAGE(In_CclsVars); -struct Handler_CqueryVars : BaseMessageHandler { +struct Handler_CclsVars : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CqueryVars* request) override { + void Run(In_CclsVars* request) override { QueryFile* file; if (!FindFileOrFail(db, project, request->id, request->params.textDocument.uri.GetPath(), &file)) { @@ -53,5 +53,5 @@ struct Handler_CqueryVars : BaseMessageHandler { QueueManager::WriteStdout(kMethodType, out); } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryVars); +REGISTER_MESSAGE_HANDLER(Handler_CclsVars); } // namespace diff --git a/src/messages/cquery_wait.cc b/src/messages/ccls_wait.cc similarity index 82% rename from src/messages/cquery_wait.cc rename to src/messages/ccls_wait.cc index 3a05df75..1e9c9b3b 100644 --- a/src/messages/cquery_wait.cc +++ b/src/messages/ccls_wait.cc @@ -6,15 +6,15 @@ #include namespace { -MethodType kMethodType = "$cquery/wait"; +MethodType kMethodType = "$ccls/wait"; -struct In_CqueryWait : public NotificationInMessage { +struct In_CclsWait : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType; } }; -MAKE_REFLECT_EMPTY_STRUCT(In_CqueryWait); -REGISTER_IN_MESSAGE(In_CqueryWait); +MAKE_REFLECT_EMPTY_STRUCT(In_CclsWait); +REGISTER_IN_MESSAGE(In_CclsWait); -struct Handler_CqueryWait : MessageHandler { +struct Handler_CclsWait : MessageHandler { MethodType GetMethodType() const override { return kMethodType; } void Run(std::unique_ptr request) override { @@ -43,5 +43,5 @@ struct Handler_CqueryWait : MessageHandler { LOG_S(INFO) << "Done waiting for idle"; } }; -REGISTER_MESSAGE_HANDLER(Handler_CqueryWait); +REGISTER_MESSAGE_HANDLER(Handler_CclsWait); } // namespace diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 2edd6ff0..9d97b7c2 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -114,11 +114,11 @@ struct lsTextDocumentSyncOptions { // TextDocumentSyncKind.Full and TextDocumentSyncKindIncremental. lsTextDocumentSyncKind change = lsTextDocumentSyncKind::Incremental; // Will save notifications are sent to the server. - optional willSave; + std::optional willSave; // Will save wait until requests are sent to the server. - optional willSaveWaitUntil; + std::optional willSaveWaitUntil; // Save notifications are sent to the server. - optional save; + std::optional save; }; MAKE_REFLECT_STRUCT(lsTextDocumentSyncOptions, openClose, @@ -132,7 +132,7 @@ struct lsServerCapabilities { // defining each notification or for backwards compatibility the // TextDocumentSyncKind number. // TODO: It seems like the new API is broken and doesn't work. - // optional textDocumentSync; + // std::optional textDocumentSync; lsTextDocumentSyncKind textDocumentSync = lsTextDocumentSyncKind::Incremental; // The server provides hover support. @@ -162,7 +162,7 @@ struct lsServerCapabilities { // The server provides document range formatting. bool documentRangeFormattingProvider = false; // The server provides document formatting on typing. - optional documentOnTypeFormattingProvider; + std::optional documentOnTypeFormattingProvider; // The server provides rename support. bool renameProvider = true; // The server provides document link support. @@ -192,34 +192,34 @@ MAKE_REFLECT_STRUCT(lsServerCapabilities, // Workspace specific client capabilities. struct lsWorkspaceClientCapabilites { // The client supports applying batch edits to the workspace. - optional applyEdit; + std::optional applyEdit; struct lsWorkspaceEdit { // The client supports versioned document changes in `WorkspaceEdit`s - optional documentChanges; + std::optional documentChanges; }; // Capabilities specific to `WorkspaceEdit`s - optional workspaceEdit; + std::optional workspaceEdit; struct lsGenericDynamicReg { // Did foo notification supports dynamic registration. - optional dynamicRegistration; + std::optional dynamicRegistration; }; // Capabilities specific to the `workspace/didChangeConfiguration` // notification. - optional didChangeConfiguration; + std::optional didChangeConfiguration; // Capabilities specific to the `workspace/didChangeWatchedFiles` // notification. - optional didChangeWatchedFiles; + std::optional didChangeWatchedFiles; // Capabilities specific to the `workspace/symbol` request. - optional symbol; + std::optional symbol; // Capabilities specific to the `workspace/executeCommand` request. - optional executeCommand; + std::optional executeCommand; }; MAKE_REFLECT_STRUCT(lsWorkspaceClientCapabilites::lsWorkspaceEdit, @@ -238,25 +238,25 @@ MAKE_REFLECT_STRUCT(lsWorkspaceClientCapabilites, struct lsTextDocumentClientCapabilities { struct lsSynchronization { // Whether text document synchronization supports dynamic registration. - optional dynamicRegistration; + std::optional dynamicRegistration; // The client supports sending will save notifications. - optional willSave; + std::optional willSave; // The client supports sending a will save request and // waits for a response providing text edits which will // be applied to the document before it is saved. - optional willSaveWaitUntil; + std::optional willSaveWaitUntil; // The client supports did save notifications. - optional didSave; + std::optional didSave; }; lsSynchronization synchronization; struct lsCompletion { // Whether completion supports dynamic registration. - optional dynamicRegistration; + std::optional dynamicRegistration; struct lsCompletionItem { // Client supports snippets as insert text. @@ -265,50 +265,50 @@ struct lsTextDocumentClientCapabilities { // and `${3:foo}`. `$0` defines the final tab stop, it defaults to // the end of the snippet. Placeholders with equal identifiers are linked, // that is typing in one will update others too. - optional snippetSupport; + std::optional snippetSupport; }; // The client supports the following `CompletionItem` specific // capabilities. - optional completionItem; + std::optional completionItem; }; // Capabilities specific to the `textDocument/completion` - optional completion; + std::optional completion; struct lsGenericDynamicReg { // Whether foo supports dynamic registration. - optional dynamicRegistration; + std::optional dynamicRegistration; }; // Capabilities specific to the `textDocument/hover` - optional hover; + std::optional hover; // Capabilities specific to the `textDocument/signatureHelp` - optional signatureHelp; + std::optional signatureHelp; // Capabilities specific to the `textDocument/references` - optional references; + std::optional references; // Capabilities specific to the `textDocument/documentHighlight` - optional documentHighlight; + std::optional documentHighlight; // Capabilities specific to the `textDocument/documentSymbol` - optional documentSymbol; + std::optional documentSymbol; // Capabilities specific to the `textDocument/formatting` - optional formatting; + std::optional formatting; // Capabilities specific to the `textDocument/rangeFormatting` - optional rangeFormatting; + std::optional rangeFormatting; // Capabilities specific to the `textDocument/onTypeFormatting` - optional onTypeFormatting; + std::optional onTypeFormatting; // Capabilities specific to the `textDocument/definition` - optional definition; + std::optional definition; // Capabilities specific to the `textDocument/codeAction` - optional codeAction; + std::optional codeAction; struct CodeLensRegistrationOptions : public lsGenericDynamicReg { // Code lens has a resolve provider as well. @@ -316,13 +316,13 @@ struct lsTextDocumentClientCapabilities { }; // Capabilities specific to the `textDocument/codeLens` - optional codeLens; + std::optional codeLens; // Capabilities specific to the `textDocument/documentLink` - optional documentLink; + std::optional documentLink; // Capabilities specific to the `textDocument/rename` - optional rename; + std::optional rename; }; MAKE_REFLECT_STRUCT(lsTextDocumentClientCapabilities::lsSynchronization, @@ -361,10 +361,10 @@ MAKE_REFLECT_STRUCT(lsTextDocumentClientCapabilities, struct lsClientCapabilities { // Workspace specific client capabilities. - optional workspace; + std::optional workspace; // Text document specific client capabilities. - optional textDocument; + std::optional textDocument; /** * Experimental client capabilities. @@ -386,21 +386,21 @@ struct lsInitializeParams { // the server. Is null if the process has not been started by another process. // If the parent process is not alive then the server should exit (see exit // notification) its process. - optional processId; + std::optional processId; // The rootPath of the workspace. Is null // if no folder is open. // // @deprecated in favour of rootUri. - optional rootPath; + std::optional rootPath; // The rootUri of the workspace. Is null if no // folder is open. If both `rootPath` and `rootUri` are set // `rootUri` wins. - optional rootUri; + std::optional rootUri; // User provided initialization options. - optional initializationOptions; + std::optional initializationOptions; // The capabilities provided by the client (editor or tool) lsClientCapabilities capabilities; @@ -538,15 +538,15 @@ struct Handler_Initialize : BaseMessageHandler { out.display_type = Out_ShowLogMessage::DisplayType::Show; out.params.type = lsMessageType::Error; out.params.message = - "cquery client (v" + std::to_string(*config->clientVersion) + + "ccls client (v" + std::to_string(*config->clientVersion) + ") and server (v" + std::to_string(kExpectedClientVersion) + ") version mismatch. Please update "; if (config->clientVersion > kExpectedClientVersion) - out.params.message += "the cquery binary."; + out.params.message += "the ccls binary."; else out.params.message += "your extension client (VSIX file). Make sure to uninstall " - "the cquery extension and restart vscode before " + "the ccls extension and restart vscode before " "reinstalling."; out.Write(std::cout); } diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc deleted file mode 100644 index e3913a2f..00000000 --- a/src/messages/text_document_code_action.cc +++ /dev/null @@ -1,600 +0,0 @@ -#include "include_complete.h" -#include "lex_utils.h" -#include "lsp_code_action.h" -#include "message_handler.h" -#include "query_utils.h" -#include "queue_manager.h" - -#include - -#include -#include - -namespace { -MethodType kMethodType = "textDocument/codeAction"; - -optional FindIncludeLine(const std::vector& lines, - const std::string& full_include_line) { - // - // This returns an include line. For example, - // - // #include // 0 - // #include // 1 - // - // Given #include , this will return '1', which means that the - // #include text should be inserted at the start of line 1. Inserting - // at the start of a line allows insertion at both the top and bottom of the - // document. - // - // If the include line is already in the document this returns nullopt. - // - - optional last_include_line; - optional best_include_line; - - // 1 => include line is gt content (ie, it should go after) - // -1 => include line is lt content (ie, it should go before) - int last_line_compare = 1; - - for (int line = 0; line < (int)lines.size(); ++line) { - std::string text = Trim(lines[line]); - if (!StartsWith(text, "#include")) { - last_line_compare = 1; - continue; - } - - last_include_line = line; - - int current_line_compare = full_include_line.compare(text); - if (current_line_compare == 0) - return nullopt; - - if (last_line_compare == 1 && current_line_compare == -1) - best_include_line = line; - last_line_compare = current_line_compare; - } - - if (best_include_line) - return *best_include_line; - // If |best_include_line| didn't match that means we likely didn't find an - // include which was lt the new one, so put it at the end of the last include - // list. - if (last_include_line) - return *last_include_line + 1; - // No includes, use top of document. - return 0; -} - -optional GetImplementationFile(QueryDatabase* db, - QueryFileId file_id, - QueryFile* file) { - for (SymbolRef sym : file->def->outline) { - switch (sym.kind) { - case SymbolKind::Func: { - if (const auto* def = db->GetFunc(sym).AnyDef()) { - // Note: we ignore the definition if it is in the same file (ie, - // possibly a header). - if (def->extent) { - QueryFileId t = def->extent->file; - if (t != file_id) - return t; - } - } - break; - } - case SymbolKind::Var: { - const QueryVar::Def* def = db->GetVar(sym).AnyDef(); - // Note: we ignore the definition if it is in the same file (ie, - // possibly a header). - if (def && def->extent) { - QueryFileId t = def->extent->file; - if (t != file_id) - return t; - } - break; - } - default: - break; - } - } - - // No associated definition, scan the project for a file in the same - // directory with the same base-name. - NormalizedPath original_path(file->def->path); - std::string target_path = original_path.path; - size_t last = target_path.find_last_of('.'); - if (last != std::string::npos) { - target_path = target_path.substr(0, last); - } - - LOG_S(INFO) << "!! Looking for impl file that starts with " << target_path; - - for (auto& entry : db->usr_to_file) { - const NormalizedPath& path = entry.first; - - // Do not consider header files for implementation files. - // TODO: make file extensions configurable. - if (EndsWith(path.path, ".h") || EndsWith(path.path, ".hpp")) - continue; - - if (StartsWith(path.path, target_path) && path != original_path) { - return entry.second; - } - } - - return nullopt; -} - -void EnsureImplFile(QueryDatabase* db, - QueryFileId file_id, - optional& impl_uri, - optional& impl_file_id) { - if (!impl_uri.has_value()) { - QueryFile& file = db->files[file_id.id]; - assert(file.def); - - impl_file_id = GetImplementationFile(db, file_id, &file); - if (!impl_file_id.has_value()) - impl_file_id = file_id; - - QueryFile& impl_file = db->files[impl_file_id->id]; - if (impl_file.def) - impl_uri = lsDocumentUri::FromPath(impl_file.def->path); - else - impl_uri = lsDocumentUri::FromPath(file.def->path); - } -} - -optional BuildAutoImplementForFunction(QueryDatabase* db, - WorkingFiles* working_files, - WorkingFile* working_file, - int default_line, - QueryFileId decl_file_id, - QueryFileId impl_file_id, - QueryFunc& func) { - const QueryFunc::Def* def = func.AnyDef(); - assert(def); - for (Use decl : func.declarations) { - if (decl.file != decl_file_id) - continue; - - optional ls_decl = GetLsRange(working_file, decl.range); - if (!ls_decl) - continue; - - optional type_name; - optional same_file_insert_end; - if (def->declaring_type) { - QueryType& declaring_type = db->types[def->declaring_type->id]; - if (const auto* def1 = declaring_type.AnyDef()) { - type_name = std::string(def1->ShortName()); - optional ls_type_extent = - GetLsRange(working_file, def1->extent->range); - if (ls_type_extent) { - same_file_insert_end = ls_type_extent->end; - same_file_insert_end->character += 1; // move past semicolon. - } - } - } - - std::string insert_text; - int newlines_after_name = 0; - LexFunctionDeclaration(working_file->buffer_content, ls_decl->start, - type_name, &insert_text, &newlines_after_name); - - if (!same_file_insert_end) { - same_file_insert_end = ls_decl->end; - same_file_insert_end->line += newlines_after_name; - same_file_insert_end->character = 1000; - } - - lsTextEdit edit; - - if (decl_file_id == impl_file_id) { - edit.range.start = *same_file_insert_end; - edit.range.end = *same_file_insert_end; - edit.newText = "\n\n" + insert_text; - } else { - lsPosition best_pos; - best_pos.line = default_line; - int best_dist = INT_MAX; - - QueryFile& file = db->files[impl_file_id.id]; - assert(file.def); - for (SymbolRef sym : file.def->outline) { - switch (sym.kind) { - case SymbolKind::Func: { - QueryFunc& sym_func = db->GetFunc(sym); - const QueryFunc::Def* def1 = sym_func.AnyDef(); - if (!def1 || !def1->extent) - break; - - for (Use func_decl : sym_func.declarations) { - if (func_decl.file == decl_file_id) { - int dist = func_decl.range.start.line - decl.range.start.line; - if (abs(dist) < abs(best_dist)) { - optional def_loc = - GetLsLocation(db, working_files, *def1->extent); - if (!def_loc) - continue; - - best_dist = dist; - - if (dist > 0) - best_pos = def_loc->range.start; - else - best_pos = def_loc->range.end; - } - } - } - - break; - } - case SymbolKind::Var: { - // TODO: handle vars. - break; - } - case SymbolKind::Invalid: - case SymbolKind::File: - case SymbolKind::Type: - LOG_S(WARNING) << "Unexpected SymbolKind " - << static_cast(sym.kind); - break; - } - } - - edit.range.start = best_pos; - edit.range.end = best_pos; - if (best_dist < 0) - edit.newText = "\n\n" + insert_text; - else - edit.newText = insert_text + "\n\n"; - } - - return edit; - } - - return nullopt; -} - -struct In_TextDocumentCodeAction : public RequestInMessage { - MethodType GetMethodType() const override { return kMethodType; } - - // Contains additional diagnostic information about the context in which - // a code action is run. - struct lsCodeActionContext { - // An array of diagnostics. - std::vector diagnostics; - }; - // Params for the CodeActionRequest - struct lsCodeActionParams { - // The document in which the command was invoked. - lsTextDocumentIdentifier textDocument; - // The range for which the command was invoked. - lsRange range; - // Context carrying additional information. - lsCodeActionContext context; - }; - lsCodeActionParams params; -}; -MAKE_REFLECT_STRUCT(In_TextDocumentCodeAction::lsCodeActionContext, - diagnostics); -MAKE_REFLECT_STRUCT(In_TextDocumentCodeAction::lsCodeActionParams, - textDocument, - range, - context); -MAKE_REFLECT_STRUCT(In_TextDocumentCodeAction, id, params); -REGISTER_IN_MESSAGE(In_TextDocumentCodeAction); - -struct Out_TextDocumentCodeAction - : public lsOutMessage { - using Command = lsCommand; - - lsRequestId id; - std::vector result; -}; -MAKE_REFLECT_STRUCT(Out_TextDocumentCodeAction, jsonrpc, id, result); - -struct Handler_TextDocumentCodeAction - : BaseMessageHandler { - MethodType GetMethodType() const override { return kMethodType; } - - void Run(In_TextDocumentCodeAction* request) override { - // NOTE: This code snippet will generate some FixIts for testing: - // - // struct origin { int x, int y }; - // void foo() { - // point origin = { - // x: 0.0, - // y: 0.0 - // }; - // } - // - - QueryFileId file_id; - QueryFile* file; - if (!FindFileOrFail(db, project, request->id, - request->params.textDocument.uri.GetPath(), &file, - &file_id)) { - return; - } - - WorkingFile* working_file = working_files->GetFileByFilename( - request->params.textDocument.uri.GetPath()); - if (!working_file) { - // TODO: send error response. - LOG_S(WARNING) - << "[error] textDocument/codeAction could not find working file"; - return; - } - - Out_TextDocumentCodeAction out; - out.id = request->id; - - // TODO: auto-insert namespace? - - int default_line = (int)working_file->buffer_lines.size(); - - // Make sure to call EnsureImplFile before using these. We lazy load - // them because computing the values could involve an entire project - // scan. - optional impl_uri; - optional impl_file_id; - - std::vector syms = - FindSymbolsAtLocation(working_file, file, request->params.range.start); - for (SymbolRef sym : syms) { - switch (sym.kind) { - case SymbolKind::Type: { - QueryType& type = db->GetType(sym); - const QueryType::Def* def = type.AnyDef(); - if (!def) - break; - - int num_edits = 0; - - // Get implementation file. - Out_TextDocumentCodeAction::Command command; - - EachDefinedEntity(db->funcs, def->funcs, [&](QueryFunc& func_def) { - const QueryFunc::Def* def1 = func_def.AnyDef(); - if (def1->extent) - return; - EnsureImplFile(db, file_id, impl_uri /*out*/, impl_file_id /*out*/); - optional edit = BuildAutoImplementForFunction( - db, working_files, working_file, default_line, file_id, - *impl_file_id, func_def); - if (!edit) - return; - - ++num_edits; - - // Merge edits together if they are on the same line. - // TODO: be smarter about newline merging? ie, don't end up - // with foo()\n\n\n\nfoo(), we want foo()\n\nfoo()\n\n - // - if (!command.arguments.edits.empty() && - command.arguments.edits[command.arguments.edits.size() - 1] - .range.end.line == edit->range.start.line) { - command.arguments.edits[command.arguments.edits.size() - 1] - .newText += edit->newText; - } else { - command.arguments.edits.push_back(*edit); - } - }); - if (command.arguments.edits.empty()) - break; - - // If we're inserting at the end of the document, put a newline - // before the insertion. - if (command.arguments.edits[0].range.start.line >= default_line) - command.arguments.edits[0].newText.insert(0, "\n"); - - command.arguments.textDocumentUri = *impl_uri; - command.title = "Auto-Implement " + std::to_string(num_edits) + - " methods on " + std::string(def->ShortName()); - command.command = "cquery._autoImplement"; - out.result.push_back(command); - break; - } - - case SymbolKind::Func: { - QueryFunc& func = db->GetFunc(sym); - const QueryFunc::Def* def = func.AnyDef(); - if (!def || def->extent) - break; - - EnsureImplFile(db, file_id, impl_uri /*out*/, impl_file_id /*out*/); - - // Get implementation file. - Out_TextDocumentCodeAction::Command command; - command.title = "Auto-Implement " + std::string(def->ShortName()); - command.command = "cquery._autoImplement"; - command.arguments.textDocumentUri = *impl_uri; - optional edit = BuildAutoImplementForFunction( - db, working_files, working_file, default_line, file_id, - *impl_file_id, func); - if (!edit) - break; - - // If we're inserting at the end of the document, put a newline - // before the insertion. - if (edit->range.start.line >= default_line) - edit->newText.insert(0, "\n"); - command.arguments.edits.push_back(*edit); - out.result.push_back(command); - break; - } - default: - break; - } - - // Only show one auto-impl section. - if (!out.result.empty()) - break; - } - - std::vector diagnostics; - working_files->DoAction( - [&]() { diagnostics = working_file->diagnostics_; }); - for (lsDiagnostic& diag : diagnostics) { - if (diag.range.start.line != request->params.range.start.line) - continue; - - // For error diagnostics, provide an action to resolve an include. - // TODO: find a way to index diagnostic contents so line numbers - // don't get mismatched when actively editing a file. - std::string_view include_query = LexIdentifierAroundPos( - diag.range.start, working_file->buffer_content); - if (diag.severity == lsDiagnosticSeverity::Error && - !include_query.empty()) { - const size_t kMaxResults = 20; - - std::unordered_set include_absolute_paths; - - // Find include candidate strings. - for (size_t i = 0; i < db->symbols.size(); ++i) { - if (include_absolute_paths.size() > kMaxResults) - break; - if (db->GetSymbolDetailedName(i).find(include_query) == - std::string::npos) - continue; - - Maybe decl_file_id = - GetDeclarationFileForSymbol(db, db->symbols[i]); - if (!decl_file_id) - continue; - - QueryFile& decl_file = db->files[decl_file_id->id]; - if (!decl_file.def) - continue; - - include_absolute_paths.insert(decl_file.def->path); - } - - // Build include strings. - std::unordered_set include_insert_strings; - include_insert_strings.reserve(include_absolute_paths.size()); - - for (const std::string& path : include_absolute_paths) { - optional item = - include_complete->FindCompletionItemForAbsolutePath(path); - if (!item) - continue; - if (item->textEdit) - include_insert_strings.insert(item->textEdit->newText); - else if (!item->insertText.empty()) - include_insert_strings.insert(item->insertText); - else { - // FIXME https://github.com/cquery-project/cquery/issues/463 - LOG_S(WARNING) << "unable to determine insert string for include " - "completion item"; - } - } - - // Build code action. - if (!include_insert_strings.empty()) { - Out_TextDocumentCodeAction::Command command; - - // Build edits. - for (const std::string& include_insert_string : - include_insert_strings) { - lsTextEdit edit; - optional include_line = FindIncludeLine( - working_file->buffer_lines, include_insert_string); - if (!include_line) - continue; - - edit.range.start.line = *include_line; - edit.range.end.line = *include_line; - edit.newText = include_insert_string + "\n"; - command.arguments.edits.push_back(edit); - } - - // Setup metadata and send to client. - if (include_insert_strings.size() == 1) - command.title = "Insert " + *include_insert_strings.begin(); - else - command.title = "Pick one of " + - std::to_string(command.arguments.edits.size()) + - " includes to insert"; - command.command = "cquery._insertInclude"; - command.arguments.textDocumentUri = request->params.textDocument.uri; - out.result.push_back(command); - } - } - - // clang does not provide accurate enough column reporting for - // diagnostics to do good column filtering, so report all - // diagnostics on the line. - if (!diag.fixits_.empty()) { - Out_TextDocumentCodeAction::Command command; - command.title = "FixIt: " + diag.message; - command.command = "cquery._applyFixIt"; - command.arguments.textDocumentUri = request->params.textDocument.uri; - command.arguments.edits = diag.fixits_; - out.result.push_back(command); - } - } - - QueueManager::WriteStdout(kMethodType, out); - } -}; -REGISTER_MESSAGE_HANDLER(Handler_TextDocumentCodeAction); - -TEST_SUITE("FindIncludeLine") { - TEST_CASE("in document") { - std::vector lines = { - "#include ", // 0 - "#include " // 1 - }; - - REQUIRE(FindIncludeLine(lines, "#include ") == nullopt); - } - - TEST_CASE("insert before") { - std::vector lines = { - "#include ", // 0 - "#include " // 1 - }; - - REQUIRE(FindIncludeLine(lines, "#include ") == 0); - } - - TEST_CASE("insert middle") { - std::vector lines = { - "#include ", // 0 - "#include " // 1 - }; - - REQUIRE(FindIncludeLine(lines, "#include ") == 1); - } - - TEST_CASE("insert after") { - std::vector lines = { - "#include ", // 0 - "#include ", // 1 - "", // 2 - }; - - REQUIRE(FindIncludeLine(lines, "#include ") == 2); - } - - TEST_CASE("ignore header") { - std::vector lines = { - "// FOOBAR", // 0 - "// FOOBAR", // 1 - "// FOOBAR", // 2 - "// FOOBAR", // 3 - "", // 4 - "#include ", // 5 - "#include ", // 6 - "", // 7 - }; - - REQUIRE(FindIncludeLine(lines, "#include ") == 5); - REQUIRE(FindIncludeLine(lines, "#include ") == 6); - REQUIRE(FindIncludeLine(lines, "#include ") == 7); - } -} -} // namespace diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index 903abf11..521268c0 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -47,21 +47,21 @@ void AddCodeLens(const char* singular, const std::vector& uses, bool force_display) { TCodeLens code_lens; - optional range = GetLsRange(common->working_file, use.range); + std::optional range = GetLsRange(common->working_file, use.range); if (!range) return; if (use.file == QueryFileId()) return; code_lens.range = *range; code_lens.command = lsCommand(); - code_lens.command->command = "cquery.showReferences"; + code_lens.command->command = "ccls.showReferences"; code_lens.command->arguments.uri = GetLsDocumentUri(common->db, use.file); code_lens.command->arguments.position = code_lens.range.start; // Add unique uses. std::unordered_set unique_uses; for (Use use1 : uses) { - optional location = + std::optional location = GetLsLocation(common->db, common->working_files, use1); if (!location) continue; @@ -177,10 +177,10 @@ struct Handler_TextDocumentCodeLens Maybe base_loc = GetDefinitionSpell( db, SymbolIdx{def->bases[0], SymbolKind::Func}); if (base_loc) { - optional ls_base = + std::optional ls_base = GetLsLocation(db, working_files, *base_loc); if (ls_base) { - optional range = + std::optional range = GetLsRange(common.working_file, sym.range); if (range) { TCodeLens code_lens; @@ -188,7 +188,7 @@ struct Handler_TextDocumentCodeLens code_lens.range.start.character += offset++; code_lens.command = lsCommand(); code_lens.command->title = "Base"; - code_lens.command->command = "cquery.goto"; + code_lens.command->command = "ccls.goto"; code_lens.command->arguments.uri = ls_base->uri; code_lens.command->arguments.position = ls_base->range.start; out.result.push_back(code_lens); diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index 7229d65b..fd85c311 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -36,7 +36,7 @@ struct lsCompletionContext { // The trigger character (a single character) that has trigger code complete. // Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` - optional triggerCharacter; + std::optional triggerCharacter; }; MAKE_REFLECT_STRUCT(lsCompletionContext, triggerKind, triggerCharacter); @@ -44,7 +44,7 @@ struct lsCompletionParams : lsTextDocumentPositionParams { // The completion context. This is only available it the client specifies to // send this using // `ClientCapabilities.textDocument.completion.contextSupport === true` - optional context; + std::optional context; }; MAKE_REFLECT_STRUCT(lsCompletionParams, textDocument, position, context); @@ -92,7 +92,7 @@ void DecorateIncludePaths(const std::smatch& match, item.textEdit->newText = prefix + quote0 + item.textEdit->newText + quote1 + suffix; item.label = prefix + quote0 + item.label + quote1 + suffix; - item.filterText = nullopt; + item.filterText = std::nullopt; } } diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index cf887adb..95be3ab5 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -26,7 +26,7 @@ struct Handler_TextDocumentDidChange std::string path = request->params.textDocument.uri.GetPath(); working_files->OnChange(request->params); if (config->enableIndexOnDidChange) { - optional content = ReadContent(path); + std::optional content = ReadContent(path); if (!content) { LOG_S(ERROR) << "Unable to read file content after saving " << path; } else { diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index 770c9bcb..9b3ee9fb 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -19,9 +19,9 @@ struct In_TextDocumentDidOpen : public NotificationInMessage { struct Params { lsTextDocumentItem textDocument; - // cquery extension + // ccls extension // If specified (e.g. ["clang++", "-DM", "a.cc"]), it overrides the project - // entry (e.g. loaded from compile_commands.json or .cquery). + // entry (e.g. loaded from compile_commands.json or .ccls). std::vector args; }; Params params; @@ -45,13 +45,13 @@ struct Handler_TextDocumentDidOpen std::shared_ptr cache_manager = ICacheManager::Make(config); WorkingFile* working_file = working_files->OnOpen(params.textDocument); - optional cached_file_contents = + std::optional cached_file_contents = cache_manager->LoadCachedFileContents(path); if (cached_file_contents) working_file->SetIndexContent(*cached_file_contents); QueryFile* file = nullptr; - FindFileOrFail(db, project, nullopt, path, &file); + FindFileOrFail(db, project, std::nullopt, path, &file); if (file && file->def) { EmitInactiveLines(working_file, file->def->inactive_regions); EmitSemanticHighlighting(db, semantic_cache, working_file, file); diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index f187f018..751d4238 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -50,7 +50,7 @@ struct Handler_TextDocumentDidSave // if so, ignore that index response. // TODO: send as priority request if (!config->enableIndexOnDidChange) { - optional content = ReadContent(path); + std::optional content = ReadContent(path); if (!content) { LOG_S(ERROR) << "Unable to read file content after saving " << path; } else { diff --git a/src/messages/text_document_document_highlight.cc b/src/messages/text_document_document_highlight.cc index 42e74cdb..e3b1e4c6 100644 --- a/src/messages/text_document_document_highlight.cc +++ b/src/messages/text_document_document_highlight.cc @@ -44,7 +44,7 @@ struct Handler_TextDocumentDocumentHighlight EachOccurrence(db, sym, true, [&](Use use) { if (use.file != file_id) return; - if (optional ls_loc = + if (std::optional ls_loc = GetLsLocation(db, working_files, use)) { lsDocumentHighlight highlight; highlight.range = ls_loc->range; diff --git a/src/messages/text_document_document_link.cc b/src/messages/text_document_document_link.cc index 9a05365a..b44639df 100644 --- a/src/messages/text_document_document_link.cc +++ b/src/messages/text_document_document_link.cc @@ -26,7 +26,7 @@ struct lsDocumentLink { // The range this link applies to. lsRange range; // The uri this link points to. If missing a resolve request is sent later. - optional target; + std::optional target; }; MAKE_REFLECT_STRUCT(lsDocumentLink, range, target); @@ -59,14 +59,14 @@ struct Handler_TextDocumentDocumentLink return; } for (const IndexInclude& include : file->def->includes) { - optional buffer_line = working_file->GetBufferPosFromIndexPos( + std::optional buffer_line = working_file->GetBufferPosFromIndexPos( include.line, nullptr, false); if (!buffer_line) continue; // Subtract 1 from line because querydb stores 1-based lines but // vscode expects 0-based lines. - optional between_quotes = ExtractQuotedRange( + std::optional between_quotes = ExtractQuotedRange( *buffer_line, working_file->buffer_lines[*buffer_line]); if (!between_quotes) continue; diff --git a/src/messages/text_document_document_symbol.cc b/src/messages/text_document_document_symbol.cc index 2ec07533..09f6723b 100644 --- a/src/messages/text_document_document_symbol.cc +++ b/src/messages/text_document_document_symbol.cc @@ -40,7 +40,7 @@ struct Handler_TextDocumentDocumentSymbol } for (SymbolRef sym : file->def->outline) { - optional info = + std::optional info = GetSymbolInfo(db, working_files, sym, true /*use_short_name*/); if (!info) continue; @@ -56,7 +56,7 @@ struct Handler_TextDocumentDocumentSymbol continue; } - if (optional location = GetLsLocation( + if (std::optional location = GetLsLocation( db, working_files, Use(sym.range, sym.id, sym.kind, sym.role, file_id))) { info->location = *location; diff --git a/src/messages/text_document_formatting.cc b/src/messages/text_document_formatting.cc index 793c86d6..49290b54 100644 --- a/src/messages/text_document_formatting.cc +++ b/src/messages/text_document_formatting.cc @@ -49,7 +49,7 @@ struct Handler_TextDocumentFormatting working_file->buffer_content.size(), request->params.options)); #else - LOG_S(WARNING) << "You must compile cquery with --use-clang-cxx to use " + LOG_S(WARNING) << "You must compile ccls with --use-clang-cxx to use " "textDocument/formatting."; // TODO: Fallback to execute the clang-format binary? response.result = {}; diff --git a/src/messages/text_document_hover.cc b/src/messages/text_document_hover.cc index 6a852d8f..a5b51812 100644 --- a/src/messages/text_document_hover.cc +++ b/src/messages/text_document_hover.cc @@ -52,11 +52,11 @@ REGISTER_IN_MESSAGE(In_TextDocumentHover); struct Out_TextDocumentHover : public lsOutMessage { struct Result { std::vector contents; - optional range; + std::optional range; }; lsRequestId id; - optional result; + std::optional result; }; MAKE_REFLECT_STRUCT(Out_TextDocumentHover::Result, contents, range); void Reflect(Writer& visitor, Out_TextDocumentHover& value) { @@ -66,7 +66,7 @@ void Reflect(Writer& visitor, Out_TextDocumentHover& value) { if (value.result) REFLECT_MEMBER(result); else { - // Empty optional<> is elided by the default serializer, we need to write + // Empty std::optional<> is elided by the default serializer, we need to write // |null| to be compliant with the LSP. visitor.Key("result"); visitor.Null(); @@ -92,7 +92,7 @@ struct Handler_TextDocumentHover : BaseMessageHandler { for (SymbolRef sym : FindSymbolsAtLocation(working_file, file, request->params.position)) { // Found symbol. Return hover. - optional ls_range = GetLsRange( + std::optional ls_range = GetLsRange( working_files->GetFileByFilename(file->def->path), sym.range); if (!ls_range) continue; diff --git a/src/messages/text_document_range_formatting.cc b/src/messages/text_document_range_formatting.cc index 175dbb2a..bc860f67 100644 --- a/src/messages/text_document_range_formatting.cc +++ b/src/messages/text_document_range_formatting.cc @@ -58,7 +58,7 @@ struct Handler_TextDocumentRangeFormatting working_file->buffer_content, ClangFormatDocument(working_file, start, end, request->params.options)); #else - LOG_S(WARNING) << "You must compile cquery with --use-clang-cxx to use " + LOG_S(WARNING) << "You must compile ccls with --use-clang-cxx to use " "textDocument/rangeFormatting."; // TODO: Fallback to execute the clang-format binary? response.result = {}; diff --git a/src/messages/text_document_references.cc b/src/messages/text_document_references.cc index 19684cdb..40f99531 100644 --- a/src/messages/text_document_references.cc +++ b/src/messages/text_document_references.cc @@ -65,7 +65,7 @@ struct Handler_TextDocumentReferences db, sym, request->params.context.includeDeclaration, [&](Use use, lsSymbolKind parent_kind) { if (use.role & request->params.context.role) - if (optional ls_loc = + if (std::optional ls_loc = GetLsLocationEx(db, working_files, use, container)) { if (container) ls_loc->parentKind = parent_kind; diff --git a/src/messages/text_document_rename.cc b/src/messages/text_document_rename.cc index b8dcc9d9..6dc26450 100644 --- a/src/messages/text_document_rename.cc +++ b/src/messages/text_document_rename.cc @@ -12,7 +12,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, std::unordered_map path_to_edit; EachOccurrence(db, sym, true, [&](Use use) { - optional ls_location = GetLsLocation(db, working_files, use); + std::optional ls_location = GetLsLocation(db, working_files, use); if (!ls_location) return; diff --git a/src/messages/text_document_signature_help.cc b/src/messages/text_document_signature_help.cc index 8f23e5be..9ceb7410 100644 --- a/src/messages/text_document_signature_help.cc +++ b/src/messages/text_document_signature_help.cc @@ -25,7 +25,7 @@ struct lsParameterInformation { // The human-readable doc-comment of this parameter. Will be shown // in the UI but can be omitted. - optional documentation; + std::optional documentation; }; MAKE_REFLECT_STRUCT(lsParameterInformation, label, documentation); @@ -39,7 +39,7 @@ struct lsSignatureInformation { // The human-readable doc-comment of this signature. Will be shown // in the UI but can be omitted. - optional documentation; + std::optional documentation; // The parameters of this signature. std::vector parameters; @@ -60,7 +60,7 @@ struct lsSignatureHelp { // rely on a default value. // In future version of the protocol this property might become // mandantory to better express this. - optional activeSignature; + std::optional activeSignature; // The active parameter of the active signature. If omitted or the value // lies outside the range of `signatures[activeSignature].parameters` @@ -69,7 +69,7 @@ struct lsSignatureHelp { // In future version of the protocol this property might become // mandantory to better express the active parameter if the // active signature does have any. - optional activeParameter; + std::optional activeParameter; }; MAKE_REFLECT_STRUCT(lsSignatureHelp, signatures, diff --git a/src/messages/workspace_did_change_watched_files.cc b/src/messages/workspace_did_change_watched_files.cc index d44081e7..ac2a1bd1 100644 --- a/src/messages/workspace_did_change_watched_files.cc +++ b/src/messages/workspace_did_change_watched_files.cc @@ -50,7 +50,7 @@ struct Handler_WorkspaceDidChangeWatchedFiles switch (event.type) { case lsFileChangeType::Created: case lsFileChangeType::Changed: { - optional content = ReadContent(path); + std::optional content = ReadContent(path); if (!content) LOG_S(ERROR) << "Unable to read file content after saving " << path; else { diff --git a/src/messages/workspace_execute_command.cc b/src/messages/workspace_execute_command.cc index e8f66f25..a96360f3 100644 --- a/src/messages/workspace_execute_command.cc +++ b/src/messages/workspace_execute_command.cc @@ -35,10 +35,10 @@ struct Handler_WorkspaceExecuteCommand const auto& params = request->params; Out_WorkspaceExecuteCommand out; out.id = request->id; - if (params.command == "cquery._applyFixIt") { - } else if (params.command == "cquery._autoImplement") { - } else if (params.command == "cquery._insertInclude") { - } else if (params.command == "cquery.showReferences") { + if (params.command == "ccls._applyFixIt") { + } else if (params.command == "ccls._autoImplement") { + } else if (params.command == "ccls._insertInclude") { + } else if (params.command == "ccls.showReferences") { out.result = params.arguments.locations; } diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index b069ec84..4294bd05 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -19,7 +19,7 @@ bool InsertSymbolIntoResult(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx symbol, std::vector* result) { - optional info = + std::optional info = GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/); if (!info) return false; @@ -35,7 +35,7 @@ bool InsertSymbolIntoResult(QueryDatabase* db, loc = decls[0]; } - optional ls_location = GetLsLocation(db, working_files, loc); + std::optional ls_location = GetLsLocation(db, working_files, loc); if (!ls_location) return false; info->location = *ls_location; diff --git a/src/method.cc b/src/method.cc index cd24524d..f1e38590 100644 --- a/src/method.cc +++ b/src/method.cc @@ -3,8 +3,8 @@ MethodType kMethodType_Unknown = "$unknown"; MethodType kMethodType_Exit = "exit"; MethodType kMethodType_TextDocumentPublishDiagnostics = "textDocument/publishDiagnostics"; -MethodType kMethodType_CqueryPublishInactiveRegions = "$cquery/publishInactiveRegions"; -MethodType kMethodType_CqueryPublishSemanticHighlighting = "$cquery/publishSemanticHighlighting"; +MethodType kMethodType_CclsPublishInactiveRegions = "$ccls/publishInactiveRegions"; +MethodType kMethodType_CclsPublishSemanticHighlighting = "$ccls/publishSemanticHighlighting"; InMessage::~InMessage() = default; diff --git a/src/method.h b/src/method.h index 77d92616..7931673e 100644 --- a/src/method.h +++ b/src/method.h @@ -9,8 +9,8 @@ using MethodType = const char*; extern MethodType kMethodType_Unknown; extern MethodType kMethodType_Exit; extern MethodType kMethodType_TextDocumentPublishDiagnostics; -extern MethodType kMethodType_CqueryPublishInactiveRegions; -extern MethodType kMethodType_CqueryPublishSemanticHighlighting; +extern MethodType kMethodType_CclsPublishInactiveRegions; +extern MethodType kMethodType_CclsPublishSemanticHighlighting; using lsRequestId = std::variant; diff --git a/src/nt_string.h b/src/nt_string.h index 4083535e..0bc1e2c6 100644 --- a/src/nt_string.h +++ b/src/nt_string.h @@ -1,10 +1,9 @@ #pragma once -#include - #include #include #include +#include #include // Nullable null-terminated string, which is null if default constructed, diff --git a/src/platform.h b/src/platform.h index cbefb30e..106b8902 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include #include #include @@ -34,7 +34,7 @@ bool TryMakeDirectory(const std::string& absolute_path); void SetCurrentThreadName(const std::string& thread_name); -optional GetLastModificationTime(const std::string& absolute_path); +std::optional GetLastModificationTime(const std::string& absolute_path); void MoveFileTo(const std::string& destination, const std::string& source); void CopyFileTo(const std::string& destination, const std::string& source); diff --git a/src/platform_posix.cc b/src/platform_posix.cc index 12cb4a37..e3e34b29 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -49,14 +49,14 @@ namespace { // Returns the canonicalized absolute pathname, without expanding symbolic // links. This is a variant of realpath(2), C++ rewrite of // https://github.com/freebsd/freebsd/blob/master/lib/libc/stdlib/realpath.c -optional RealPathNotExpandSymlink(std::string path) { +std::optional RealPathNotExpandSymlink(std::string path) { if (path.empty()) { errno = EINVAL; - return nullopt; + return std::nullopt; } if (path[0] == '\0') { errno = ENOENT; - return nullopt; + return std::nullopt; } // Do not use PATH_MAX because it is tricky on Linux. @@ -70,7 +70,7 @@ optional RealPathNotExpandSymlink(std::string path) { i = 1; } else { if (!getcwd(tmp, sizeof tmp)) - return nullopt; + return std::nullopt; resolved = tmp; } @@ -96,10 +96,10 @@ optional RealPathNotExpandSymlink(std::string path) { // lstat(2) because we do not want to resolve symlinks. resolved += next_token; if (stat(resolved.c_str(), &sb) != 0) - return nullopt; + return std::nullopt; if (!S_ISDIR(sb.st_mode) && j < path.size()) { errno = ENOTDIR; - return nullopt; + return std::nullopt; } } @@ -160,7 +160,7 @@ std::string GetWorkingDirectory() { } std::string NormalizePath(const std::string& path) { - optional resolved = RealPathNotExpandSymlink(path); + std::optional resolved = RealPathNotExpandSymlink(path); return resolved ? *resolved : path; } @@ -184,22 +184,22 @@ void SetCurrentThreadName(const std::string& thread_name) { #endif } -optional GetLastModificationTime(const std::string& absolute_path) { +std::optional GetLastModificationTime(const std::string& absolute_path) { struct stat buf; if (stat(absolute_path.c_str(), &buf) != 0) { switch (errno) { case ENOENT: // std::cerr << "GetLastModificationTime: unable to find file " << // absolute_path << std::endl; - return nullopt; + return std::nullopt; case EINVAL: // std::cerr << "GetLastModificationTime: invalid param to _stat for // file file " << absolute_path << std::endl; - return nullopt; + return std::nullopt; default: // std::cerr << "GetLastModificationTime: unhandled for " << // absolute_path << std::endl; exit(1); - return nullopt; + return std::nullopt; } } @@ -279,7 +279,7 @@ bool RunObjectiveCIndexTests() { void TraceMe() { // If the environment variable is defined, wait for a debugger. - // In gdb, you need to invoke `signal SIGCONT` if you want cquery to continue + // In gdb, you need to invoke `signal SIGCONT` if you want ccls to continue // after detaching. if (getenv("CQUERY_TRACEME")) raise(SIGTSTP); diff --git a/src/platform_win.cc b/src/platform_win.cc index 027b6150..2b7f8126 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -95,22 +95,22 @@ void SetCurrentThreadName(const std::string& thread_name) { } } -optional GetLastModificationTime(const std::string& absolute_path) { +std::optional GetLastModificationTime(const std::string& absolute_path) { struct _stat buf; if (_stat(absolute_path.c_str(), &buf) != 0) { switch (errno) { case ENOENT: // std::cerr << "GetLastModificationTime: unable to find file " << // absolute_path << std::endl; - return nullopt; + return std::nullopt; case EINVAL: // std::cerr << "GetLastModificationTime: invalid param to _stat for // file file " << absolute_path << std::endl; - return nullopt; + return std::nullopt; default: // std::cerr << "GetLastModificationTime: unhandled for " << // absolute_path << std::endl; exit(1); - return nullopt; + return std::nullopt; } } @@ -140,7 +140,7 @@ std::vector GetPlatformClangArguments() { // // These options are only needed if clang is targeting the msvc triple, // which depends on how clang was build for windows. clang downloaded from - // releases.llvm.org defaults to msvc, so cquery does as well. + // releases.llvm.org defaults to msvc, so ccls does as well. // // https://github.com/cquery-project/cquery/issues/509 has more context. // diff --git a/src/port.cc b/src/port.cc index 7f5d5be2..adb4cde6 100644 --- a/src/port.cc +++ b/src/port.cc @@ -3,7 +3,7 @@ #include #include -void cquery_unreachable_internal(const char* msg, const char* file, int line) { +void ccls_unreachable_internal(const char* msg, const char* file, int line) { fprintf(stderr, "unreachable %s:%d %s\n", file, line, msg); CQUERY_BUILTIN_UNREACHABLE; abort(); diff --git a/src/port.h b/src/port.h index 6b5a4e3d..5680bfa9 100644 --- a/src/port.h +++ b/src/port.h @@ -19,10 +19,10 @@ #define CQUERY_BUILTIN_UNREACHABLE #endif -void cquery_unreachable_internal(const char* msg, const char* file, int line); +void ccls_unreachable_internal(const char* msg, const char* file, int line); #ifndef NDEBUG #define CQUERY_UNREACHABLE(msg) \ - cquery_unreachable_internal(msg, __FILE__, __LINE__) + ccls_unreachable_internal(msg, __FILE__, __LINE__) #else #define CQUERY_UNREACHABLE(msg) #endif diff --git a/src/project.cc b/src/project.cc index bf3f4968..387fe3a0 100644 --- a/src/project.cc +++ b/src/project.cc @@ -62,7 +62,7 @@ bool IsWindowsAbsolutePath(const std::string& path) { (path[2] == '/' || path[2] == '\\') && is_drive_letter(path[0]); } -enum class ProjectMode { CompileCommandsJson, DotCquery, ExternalCommand }; +enum class ProjectMode { CompileCommandsJson, DotCcls, ExternalCommand }; struct ProjectConfig { std::unordered_set quote_dirs; @@ -130,7 +130,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( const CompileCommandsEntry& entry) { auto cleanup_maybe_relative_path = [&](const std::string& path) { // TODO/FIXME: Normalization will fail for paths that do not exist. Should - // it return an optional? + // it return an std::optional? assert(!path.empty()); if (entry.directory.empty() || IsUnixAbsolutePath(path) || IsWindowsAbsolutePath(path)) { @@ -181,33 +181,8 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( break; } } - size_t i = 1; - - // If |compilationDatabaseCommand| is specified, the external command provides - // us the JSON compilation database which should be strict. We should do very - // little processing on |args|. - if (config->mode != ProjectMode::ExternalCommand && !clang_cl) { - // Strip all arguments consisting the compiler command, - // as there may be non-compiler related commands beforehand, - // ie, compiler schedular such as goma. This allows correct parsing for - // command lines like "goma clang -c foo". - std::string::size_type dot; - while (i < args.size() && args[i][0] != '-' && - // Do not skip over main source filename - NormalizePathWithTestOptOut(args[i]) != result.filename && - // There may be other filenames (e.g. more than one source filenames) - // preceding main source filename. We use a heuristic here. `.` may - // occur in both command names and source filenames. If `.` occurs in - // the last 4 bytes of args[i] and not followed by a digit, e.g. - // .c .cpp, We take it as a source filename. Others (like ./a/b/goma - // clang-4.0) are seen as commands. - ((dot = args[i].rfind('.')) == std::string::npos || - dot + 4 < args[i].size() || isdigit(args[i][dot + 1]) || - !args[i].compare(dot + 1, 3, "exe"))) - ++i; - } // Compiler driver. - result.args.push_back(args[i - 1]); + result.args.push_back(args[0]); // Add -working-directory if not provided. if (!AnyStartsWith(args, "-working-directory")) @@ -226,6 +201,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( // Note that when processing paths, some arguments support multiple forms, ie, // {"-Ifoo"} or {"-I", "foo"}. Support both styles. + size_t i = 1; result.args.reserve(args.size() + config->extra_flags.size()); for (; i < args.size(); ++i) { std::string arg = args[i]; @@ -306,7 +282,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( result.args.push_back("-resource-dir=" + config->resource_dir); // There could be a clang version mismatch between what the project uses and - // what cquery uses. Make sure we do not emit warnings for mismatched options. + // what ccls uses. Make sure we do not emit warnings for mismatched options. if (!AnyStartsWith(result.args, "-Wno-unknown-warning-option")) result.args.push_back("-Wno-unknown-warning-option"); @@ -335,11 +311,11 @@ std::vector ReadCompilerArgumentsFromFile( std::vector LoadFromDirectoryListing(Config* init_opts, ProjectConfig* config) { std::vector result; - config->mode = ProjectMode::DotCquery; - LOG_IF_S(WARNING, !FileExists(config->project_dir + "/.cquery") && + config->mode = ProjectMode::DotCcls; + LOG_IF_S(WARNING, !FileExists(config->project_dir + "/.ccls") && config->extra_flags.empty()) - << "cquery has no clang arguments. Considering adding either a " - "compile_commands.json or .cquery file. See the cquery README for " + << "ccls has no clang arguments. Considering adding either a " + "compile_commands.json or .ccls file. See the ccls README for " "more information."; std::unordered_map> folder_args; @@ -350,8 +326,8 @@ std::vector LoadFromDirectoryListing(Config* init_opts, [&folder_args, &files](const std::string& path) { if (SourceFileLanguage(path) != LanguageId::Unknown) { files.push_back(path); - } else if (GetBaseName(path) == ".cquery") { - LOG_S(INFO) << "Using .cquery arguments from " << path; + } else if (GetBaseName(path) == ".ccls") { + LOG_S(INFO) << "Using .ccls arguments from " << path; folder_args.emplace(GetDirName(path), ReadCompilerArgumentsFromFile(path)); } @@ -359,7 +335,7 @@ std::vector LoadFromDirectoryListing(Config* init_opts, const auto& project_dir_args = folder_args[config->project_dir]; LOG_IF_S(INFO, !project_dir_args.empty()) - << "Using .cquery arguments " << StringJoin(project_dir_args); + << "Using .ccls arguments " << StringJoin(project_dir_args); auto GetCompilerArgumentForFile = [&config, &folder_args](const std::string& path) { @@ -396,8 +372,8 @@ std::vector LoadCompilationEntriesFromDirectory( Config* config, ProjectConfig* project, const std::string& opt_compilation_db_dir) { - // If there is a .cquery file always load using directory listing. - if (FileExists(project->project_dir + ".cquery")) + // If there is a .ccls file always load using directory listing. + if (FileExists(project->project_dir + ".ccls")) return LoadFromDirectoryListing(config, project); // If |compilationDatabaseCommand| is specified, execute it to get the compdb. @@ -412,7 +388,7 @@ std::vector LoadCompilationEntriesFromDirectory( #ifdef _WIN32 // TODO #else - char tmpdir[] = "/tmp/cquery-compdb-XXXXXX"; + char tmpdir[] = "/tmp/ccls-compdb-XXXXXX"; if (!mkdtemp(tmpdir)) return {}; comp_db_dir = tmpdir; @@ -654,7 +630,7 @@ void Project::Index(Config* config, WorkingFiles* wfiles, lsRequestId id) { ForAllFilteredFiles(config, [&](int i, const Project::Entry& entry) { - optional content = ReadContent(entry.filename); + std::optional content = ReadContent(entry.filename); if (!content) { LOG_S(ERROR) << "When loading project, canont read file " << entry.filename; @@ -1518,7 +1494,7 @@ TEST_SUITE("Project") { // Guess at same directory level, when there are parent directories. { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("/a/b/c/d/new.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg1"}); @@ -1526,7 +1502,7 @@ TEST_SUITE("Project") { // Guess at same directory level, when there are child directories. { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("/a/b/c/new.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg2"}); @@ -1534,7 +1510,7 @@ TEST_SUITE("Project") { // Guess at new directory (use the closest parent directory). { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("/a/b/c/new/new.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg2"}); @@ -1551,7 +1527,7 @@ TEST_SUITE("Project") { } { - optional entry = p.FindCompilationEntryForFile("ee.cc"); + std::optional entry = p.FindCompilationEntryForFile("ee.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"a", "b", "ee.cc", "d"}); } @@ -1569,7 +1545,7 @@ TEST_SUITE("Project") { REQUIRE(!IsWindowsAbsolutePath("C:/")); REQUIRE(!IsWindowsAbsolutePath("../abc/test")); REQUIRE(!IsWindowsAbsolutePath("5:/test")); - REQUIRE(!IsWindowsAbsolutePath("cquery/project/file.cc")); + REQUIRE(!IsWindowsAbsolutePath("ccls/project/file.cc")); REQUIRE(!IsWindowsAbsolutePath("")); REQUIRE(!IsWindowsAbsolutePath("/etc/linux/path")); } @@ -1597,25 +1573,25 @@ TEST_SUITE("Project") { // Prefer files with the same ending. { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("my_browsertest.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg1"}); } { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("my_unittest.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg2"}); } { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("common/my_browsertest.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg1"}); } { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("common/my_unittest.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg2"}); @@ -1623,7 +1599,7 @@ TEST_SUITE("Project") { // Prefer the same directory over matching file-ending. { - optional entry = + std::optional entry = p.FindCompilationEntryForFile("common/a/foo.cc"); REQUIRE(entry.has_value()); REQUIRE(entry->args == std::vector{"arg3"}); diff --git a/src/project.h b/src/project.h index 2e2a9253..18e7bbd8 100644 --- a/src/project.h +++ b/src/project.h @@ -3,9 +3,9 @@ #include "config.h" #include "method.h" -#include +#include #include -#include +#include #include #include @@ -33,11 +33,11 @@ struct Project { // Loads a project for the given |directory|. // - // If |config->compilationDatabaseDirectory| is not empty, look for .cquery or + // If |config->compilationDatabaseDirectory| is not empty, look for .ccls or // compile_commands.json in it, otherwise they are retrieved in // |root_directory|. - // For .cquery, recursive directory listing is used and files with known - // suffixes are indexed. .cquery files can exist in subdirectories and they + // For .ccls, recursive directory listing is used and files with known + // suffixes are indexed. .ccls files can exist in subdirectories and they // will affect flags in their subtrees (relative paths are relative to the // project root, not subdirectories). For compile_commands.json, its entries // are indexed. diff --git a/src/query.cc b/src/query.cc index bb0d897b..b1336b9e 100644 --- a/src/query.cc +++ b/src/query.cc @@ -5,7 +5,7 @@ #include "serializers/json.h" #include -#include +#include #include #include @@ -39,10 +39,10 @@ void RemoveRange(std::vector* dest, const std::vector& to_remove) { dest->end()); } -optional ToQuery(const IdMap& id_map, +std::optional ToQuery(const IdMap& id_map, const IndexType::Def& type) { if (type.detailed_name.empty()) - return nullopt; + return std::nullopt; QueryType::Def result; result.detailed_name = type.detailed_name; @@ -64,10 +64,10 @@ optional ToQuery(const IdMap& id_map, return result; } -optional ToQuery(const IdMap& id_map, +std::optional ToQuery(const IdMap& id_map, const IndexFunc::Def& func) { if (func.detailed_name.empty()) - return nullopt; + return std::nullopt; QueryFunc::Def result; result.detailed_name = func.detailed_name; @@ -89,9 +89,9 @@ optional ToQuery(const IdMap& id_map, return result; } -optional ToQuery(const IdMap& id_map, const IndexVar::Def& var) { +std::optional ToQuery(const IdMap& id_map, const IndexVar::Def& var) { if (var.detailed_name.empty()) - return nullopt; + return std::nullopt; QueryVar::Def result; result.detailed_name = var.detailed_name; @@ -549,7 +549,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, }, /*onAdded:*/ [this, ¤t_id_map](IndexType* type) { - optional def_update = + std::optional def_update = ToQuery(current_id_map, type->def); if (def_update) types_def_update.push_back( @@ -574,9 +574,9 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, /*onFound:*/ [this, &previous_id_map, ¤t_id_map](IndexType* previous, IndexType* current) { - optional previous_remapped_def = + std::optional previous_remapped_def = ToQuery(previous_id_map, previous->def); - optional current_remapped_def = + std::optional current_remapped_def = ToQuery(current_id_map, current->def); if (current_remapped_def && previous_remapped_def != current_remapped_def && @@ -614,7 +614,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, }, /*onAdded:*/ [this, ¤t_id_map](IndexFunc* func) { - optional def_update = + std::optional def_update = ToQuery(current_id_map, func->def); if (def_update) funcs_def_update.push_back( @@ -635,9 +635,9 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, /*onFound:*/ [this, &previous_id_map, ¤t_id_map](IndexFunc* previous, IndexFunc* current) { - optional previous_remapped_def = + std::optional previous_remapped_def = ToQuery(previous_id_map, previous->def); - optional current_remapped_def = + std::optional current_remapped_def = ToQuery(current_id_map, current->def); if (current_remapped_def && previous_remapped_def != current_remapped_def && @@ -669,7 +669,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, }, /*onAdded:*/ [this, ¤t_id_map](IndexVar* var) { - optional def_update = ToQuery(current_id_map, var->def); + std::optional def_update = ToQuery(current_id_map, var->def); if (def_update) vars_def_update.push_back( QueryVar::DefUpdate(var->usr, std::move(*def_update))); @@ -685,9 +685,9 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, /*onFound:*/ [this, &previous_id_map, ¤t_id_map](IndexVar* previous, IndexVar* current) { - optional previous_remapped_def = + std::optional previous_remapped_def = ToQuery(previous_id_map, previous->def); - optional current_remapped_def = + std::optional current_remapped_def = ToQuery(current_id_map, current->def); if (current_remapped_def && previous_remapped_def != current_remapped_def && @@ -768,7 +768,7 @@ void QueryDatabase::RemoveUsrs(SymbolKind usr_kind, // but it should be pretty minimal and is solved by simply restarting the // indexer and loading from cache, which is a fast operation. // - // TODO: Add "cquery: Reload Index" command which unloads all querydb state + // TODO: Add "ccls: Reload Index" command which unloads all querydb state // and fully reloads from cache. This will address the memory leak above. switch (usr_kind) { @@ -818,7 +818,7 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { // This function runs on the querydb thread. // Example types: -// storage_name => std::vector> +// storage_name => std::vector> // merge_update => QueryType::DerivedUpdate => // MergeableUpdate def => QueryType // def->def_var_name => std::vector @@ -831,7 +831,7 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { } for (const std::string& filename : update->files_removed) - files[usr_to_file[NormalizedPath(filename)].id].def = nullopt; + files[usr_to_file[NormalizedPath(filename)].id].def = std::nullopt; ImportOrUpdate(update->files_def_update); RemoveUsrs(SymbolKind::Type, update->types_removed); @@ -1111,7 +1111,7 @@ TEST_SUITE("query") { TEST_CASE("Remove variable with usage") { auto load_index_from_json = [](const char* json) { return Deserialize(SerializeFormat::Json, "foo.cc", json, "", - nullopt); + std::nullopt); }; auto previous = load_index_from_json(R"RAW( diff --git a/src/query.h b/src/query.h index 008d52a5..ac746aa6 100644 --- a/src/query.h +++ b/src/query.h @@ -110,13 +110,13 @@ struct QueryFile { std::vector all_symbols; // Parts of the file which are disabled. std::vector inactive_regions; - // Used by |$cquery/freshenIndex|. + // Used by |$ccls/freshenIndex|. std::vector dependencies; }; using DefUpdate = WithFileContent; - optional def; + std::optional def; Maybe> symbol_idx; explicit QueryFile(const std::string& path) { @@ -323,8 +323,8 @@ template <> struct IndexToQuery { using type = QueryVarId; }; template <> struct IndexToQuery { using type = Use; }; template <> struct IndexToQuery { using type = SymbolRef; }; template <> struct IndexToQuery { using type = Use; }; -template struct IndexToQuery> { - using type = optional::type>; +template struct IndexToQuery> { + using type = std::optional::type>; }; template struct IndexToQuery> { using type = std::vector::type>; @@ -349,7 +349,7 @@ struct IdMap { template Maybe::type> ToQuery(Maybe id) const { if (!id) - return nullopt; + return std::nullopt; return ToQuery(*id); } template diff --git a/src/query_utils.cc b/src/query_utils.cc index 81bab28f..72e756c1 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -82,7 +82,7 @@ Maybe GetDeclarationFileForSymbol(QueryDatabase* db, break; } } - return nullopt; + return std::nullopt; } std::vector GetDeclarations(QueryDatabase* db, @@ -155,31 +155,31 @@ std::vector GetUsesForAllDerived(QueryDatabase* db, QueryFunc& root) { return ret; } -optional GetLsPosition(WorkingFile* working_file, +std::optional GetLsPosition(WorkingFile* working_file, const Position& position) { if (!working_file) return lsPosition(position.line, position.column); int column = position.column; - if (optional start = + if (std::optional start = working_file->GetBufferPosFromIndexPos(position.line, &column, false)) return lsPosition(*start, column); - return nullopt; + return std::nullopt; } -optional GetLsRange(WorkingFile* working_file, const Range& location) { +std::optional GetLsRange(WorkingFile* working_file, const Range& location) { if (!working_file) { return lsRange(lsPosition(location.start.line, location.start.column), lsPosition(location.end.line, location.end.column)); } int start_column = location.start.column, end_column = location.end.column; - optional start = working_file->GetBufferPosFromIndexPos( + std::optional start = working_file->GetBufferPosFromIndexPos( location.start.line, &start_column, false); - optional end = working_file->GetBufferPosFromIndexPos(location.end.line, + std::optional end = working_file->GetBufferPosFromIndexPos(location.end.line, &end_column, true); if (!start || !end) - return nullopt; + return std::nullopt; // If remapping end fails (end can never be < start), just guess that the // final location didn't move. This only screws up the highlighted code @@ -218,25 +218,25 @@ lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id) { } } -optional GetLsLocation(QueryDatabase* db, +std::optional GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, Use use) { std::string path; lsDocumentUri uri = GetLsDocumentUri(db, use.file, &path); - optional range = + std::optional range = GetLsRange(working_files->GetFileByFilename(path), use.range); if (!range) - return nullopt; + return std::nullopt; return lsLocation(uri, *range); } -optional GetLsLocationEx(QueryDatabase* db, +std::optional GetLsLocationEx(QueryDatabase* db, WorkingFiles* working_files, Use use, bool container) { - optional ls_loc = GetLsLocation(db, working_files, use); + std::optional ls_loc = GetLsLocation(db, working_files, use); if (!ls_loc) - return nullopt; + return std::nullopt; lsLocationEx ret; ret.lsLocation::operator=(*ls_loc); if (container) { @@ -282,7 +282,7 @@ lsSymbolKind GetSymbolKind(QueryDatabase* db, SymbolIdx sym) { } // Returns a symbol. The symbol will have *NOT* have a location assigned. -optional GetSymbolInfo(QueryDatabase* db, +std::optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx sym, bool use_short_name) { @@ -314,7 +314,7 @@ optional GetSymbolInfo(QueryDatabase* db, } } - return nullopt; + return std::nullopt; } std::vector FindSymbolsAtLocation(WorkingFile* working_file, @@ -326,7 +326,7 @@ std::vector FindSymbolsAtLocation(WorkingFile* working_file, int target_line = position.line; int target_column = position.character; if (working_file) { - optional index_line = working_file->GetIndexPosFromBufferPos( + std::optional index_line = working_file->GetIndexPosFromBufferPos( target_line, &target_column, false); if (index_line) target_line = *index_line; diff --git a/src/query_utils.h b/src/query_utils.h index f7f43a57..a3bd30df 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -3,7 +3,7 @@ #include "query.h" #include "working_files.h" -#include +#include Maybe GetDefinitionSpell(QueryDatabase* db, SymbolIdx sym); Maybe GetDefinitionExtent(QueryDatabase* db, SymbolIdx sym); @@ -24,18 +24,18 @@ std::vector GetNonDefDeclarations(QueryDatabase* db, SymbolIdx sym); std::vector GetUsesForAllBases(QueryDatabase* db, QueryFunc& root); std::vector GetUsesForAllDerived(QueryDatabase* db, QueryFunc& root); -optional GetLsPosition(WorkingFile* working_file, +std::optional GetLsPosition(WorkingFile* working_file, const Position& position); -optional GetLsRange(WorkingFile* working_file, const Range& location); +std::optional GetLsRange(WorkingFile* working_file, const Range& location); lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id, std::string* path); lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id); -optional GetLsLocation(QueryDatabase* db, +std::optional GetLsLocation(QueryDatabase* db, WorkingFiles* working_files, Use use); -optional GetLsLocationEx(QueryDatabase* db, +std::optional GetLsLocationEx(QueryDatabase* db, WorkingFiles* working_files, Use use, bool container); @@ -45,7 +45,7 @@ std::vector GetLsLocationExs(QueryDatabase* db, bool container, int limit); // Returns a symbol. The symbol will have *NOT* have a location assigned. -optional GetSymbolInfo(QueryDatabase* db, +std::optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx sym, bool use_short_name); diff --git a/src/recorder.cc b/src/recorder.cc index 94a46ed0..f369d85f 100644 --- a/src/recorder.cc +++ b/src/recorder.cc @@ -12,7 +12,7 @@ std::ofstream* g_file_out = nullptr; void EnableRecording(std::string path) { if (path.empty()) - path = "cquery"; + path = "ccls"; // We can only call |EnableRecording| once. assert(!g_file_in && !g_file_out); diff --git a/src/recorder.h b/src/recorder.h index 772841d3..f3474ae6 100644 --- a/src/recorder.h +++ b/src/recorder.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/semantic_highlight_symbol_cache.cc b/src/semantic_highlight_symbol_cache.cc index 10f8ebc4..3fc045bc 100644 --- a/src/semantic_highlight_symbol_cache.cc +++ b/src/semantic_highlight_symbol_cache.cc @@ -5,7 +5,7 @@ SemanticHighlightSymbolCache::Entry::Entry( const std::string& path) : all_caches_(all_caches), path(path) {} -optional SemanticHighlightSymbolCache::Entry::TryGetStableId( +std::optional SemanticHighlightSymbolCache::Entry::TryGetStableId( SymbolKind kind, const std::string& detailed_name) { TNameToId* map = GetMapForSymbol_(kind); @@ -13,19 +13,19 @@ optional SemanticHighlightSymbolCache::Entry::TryGetStableId( if (it != map->end()) return it->second; - return nullopt; + return std::nullopt; } int SemanticHighlightSymbolCache::Entry::GetStableId( SymbolKind kind, const std::string& detailed_name) { - optional id = TryGetStableId(kind, detailed_name); + std::optional id = TryGetStableId(kind, detailed_name); if (id) return *id; // Create a new id. First try to find a key in another map. all_caches_->cache_.IterateValues([&](const std::shared_ptr& entry) { - optional other_id = entry->TryGetStableId(kind, detailed_name); + std::optional other_id = entry->TryGetStableId(kind, detailed_name); if (other_id) { id = other_id; return false; diff --git a/src/semantic_highlight_symbol_cache.h b/src/semantic_highlight_symbol_cache.h index f540ecb9..907be1e6 100644 --- a/src/semantic_highlight_symbol_cache.h +++ b/src/semantic_highlight_symbol_cache.h @@ -4,7 +4,7 @@ #include "match.h" #include "query.h" -#include +#include #include #include @@ -25,7 +25,7 @@ struct SemanticHighlightSymbolCache { Entry(SemanticHighlightSymbolCache* all_caches, const std::string& path); - optional TryGetStableId(SymbolKind kind, + std::optional TryGetStableId(SymbolKind kind, const std::string& detailed_name); int GetStableId(SymbolKind kind, const std::string& detailed_name); diff --git a/src/serializer.cc b/src/serializer.cc index 02f8fd3c..7cd1df72 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -360,7 +360,7 @@ std::unique_ptr Deserialize( const std::string& path, const std::string& serialized_index_content, const std::string& file_content, - optional expected_version) { + std::optional expected_version) { if (serialized_index_content.empty()) return nullptr; diff --git a/src/serializer.h b/src/serializer.h index dbee4243..b2b9b65c 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -5,14 +5,15 @@ #include "port.h" #include -#include -#include -#include #include +#include #include +#include #include +#include #include +#include #include enum class SerializeFormat { Json, MessagePack }; @@ -176,13 +177,13 @@ void Reflect(Writer& visitor, SerializeFormat& value); //// Type constructors -// ReflectMember optional is used to represent TypeScript optional properties +// ReflectMember std::optional is used to represent TypeScript std::optional properties // (in `key: value` context). -// Reflect optional is used for a different purpose, whether an object is +// Reflect std::optional is used for a different purpose, whether an object is // nullable (possibly in `value` context). For the nullable semantics, // std::variant is recommended. template -void Reflect(Reader& visitor, optional& value) { +void Reflect(Reader& visitor, std::optional& value) { if (visitor.IsNull()) { visitor.GetNull(); return; @@ -192,7 +193,7 @@ void Reflect(Reader& visitor, optional& value) { value = std::move(real_value); } template -void Reflect(Writer& visitor, optional& value) { +void Reflect(Writer& visitor, std::optional& value) { if (value) Reflect(visitor, *value); else @@ -219,8 +220,8 @@ void Reflect(Writer& visitor, Maybe& value) { } template -void ReflectMember(Writer& visitor, const char* name, optional& value) { - // For TypeScript optional property key?: value in the spec, +void ReflectMember(Writer& visitor, const char* name, std::optional& value) { + // For TypeScript std::optional property key?: value in the spec, // We omit both key and value if value is std::nullopt (null) for JsonWriter // to reduce output. But keep it for other serialization formats. if (value || visitor.Format() != SerializeFormat::Json) { @@ -238,22 +239,13 @@ void ReflectMember(Writer& visitor, const char* name, Maybe& value) { } } -// Backport C++17 std::disjunction -namespace { -template -struct disjunction - : std::conditional>::type {}; -template -struct disjunction : B0 {}; -} // namespace - // Helper struct to reflect std::variant template struct ReflectVariant { // If T appears in Ts..., we should set the value of std::variant to // what we get from Reader. template - typename std::enable_if...>::value, + typename std::enable_if...>::value, void>::type ReflectTag(Reader& visitor, std::variant& value) { T a; @@ -263,7 +255,7 @@ struct ReflectVariant { // This SFINAE overload is used to prevent compile error. value = a; is not // allowed if T does not appear in Ts... template - typename std::enable_if...>::value, + typename std::enable_if...>::value, void>::type ReflectTag(Reader&, std::variant&) {} @@ -273,7 +265,7 @@ struct ReflectVariant { ReflectTag(visitor, value); // It is possible that IsInt64() && IsInt(). We don't call ReflectTag // if int is not in Ts... - else if (disjunction...>::value && visitor.IsInt()) + else if (std::disjunction...>::value && visitor.IsInt()) ReflectTag(visitor, value); else if (visitor.IsInt64()) ReflectTag(visitor, value); @@ -363,6 +355,6 @@ std::unique_ptr Deserialize( const std::string& path, const std::string& serialized_index_content, const std::string& file_content, - optional expected_version); + std::optional expected_version); void SetTestOutputMode(); diff --git a/src/standard_includes.cc b/src/standard_includes.cc index 42cc35b3..43a67c30 100644 --- a/src/standard_includes.cc +++ b/src/standard_includes.cc @@ -95,7 +95,7 @@ const char* kStandardLibraryIncludes[177] = { "new", "nl_types.h", "numeric", - "optional", + "std::optional", "ostream", "poll.h", "pthread.h", diff --git a/src/symbol.h b/src/symbol.h index bcbc6c64..54a09272 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -75,7 +75,7 @@ struct lsDocumentHighlight { // The highlight kind, default is DocumentHighlightKind.Text. lsDocumentHighlightKind kind = lsDocumentHighlightKind::Text; - // cquery extension + // ccls extension Role role = Role::None; }; MAKE_REFLECT_STRUCT(lsDocumentHighlight, range, kind, role); diff --git a/src/task.cc b/src/task.cc index b26f7b60..7a545d71 100644 --- a/src/task.cc +++ b/src/task.cc @@ -23,14 +23,14 @@ void TaskManager::SetIdle(TaskThread thread, const TIdleTask& task) { queue->idle_task = task; } -bool TaskManager::RunTasks(TaskThread thread, optional> max_time) { +bool TaskManager::RunTasks(TaskThread thread, std::optional> max_time) { auto start = std::chrono::high_resolution_clock::now(); TaskQueue* queue = pending_tasks_[thread].get(); bool ran_task = false; while (true) { - optional task; + std::optional task; // Get a task. { @@ -79,7 +79,7 @@ TEST_CASE("tasks are run as soon as they are posted") { }); // Execute all tasks. - tm.RunTasks(TaskThread::QueryDb, nullopt); + tm.RunTasks(TaskThread::QueryDb, std::nullopt); // Tasks are executed in reverse order. REQUIRE(a == 3); @@ -106,7 +106,7 @@ TEST_CASE("post from inside task manager") { }); // Execute all tasks. - tm.RunTasks(TaskThread::QueryDb, nullopt); + tm.RunTasks(TaskThread::QueryDb, std::nullopt); // Tasks are executed in normal order because the next task is not posted // until the previous one is executed. @@ -125,7 +125,7 @@ TEST_CASE("idle task is run after nested tasks") { }); // No tasks posted - idle runs once. - REQUIRE(tm.RunTasks(TaskThread::QueryDb, nullopt)); + REQUIRE(tm.RunTasks(TaskThread::QueryDb, std::nullopt)); REQUIRE(count == 1); count = 0; @@ -134,7 +134,7 @@ TEST_CASE("idle task is run after nested tasks") { tm.Post(TaskThread::QueryDb, [&]() { did_run = true; }); - REQUIRE(tm.RunTasks(TaskThread::QueryDb, nullopt)); + REQUIRE(tm.RunTasks(TaskThread::QueryDb, std::nullopt)); REQUIRE(did_run); REQUIRE(count == 1); } @@ -142,10 +142,10 @@ TEST_CASE("idle task is run after nested tasks") { TEST_CASE("RunTasks returns false when idle task returns false and no other tasks were run") { TaskManager tm; - REQUIRE(tm.RunTasks(TaskThread::QueryDb, nullopt) == false); + REQUIRE(tm.RunTasks(TaskThread::QueryDb, std::nullopt) == false); tm.SetIdle(TaskThread::QueryDb, []() { return false; }); - REQUIRE(tm.RunTasks(TaskThread::QueryDb, nullopt) == false); + REQUIRE(tm.RunTasks(TaskThread::QueryDb, std::nullopt) == false); } TEST_SUITE_END(); diff --git a/src/task.h b/src/task.h index 04feeedb..5cdd4e0a 100644 --- a/src/task.h +++ b/src/task.h @@ -1,7 +1,7 @@ #if false #pragma once -#include +#include #include #include @@ -28,10 +28,10 @@ struct TaskManager { // Run pending tasks for |thread|. Stop running tasks after |max_time| has // elapsed. Returns true if tasks were run. - bool RunTasks(TaskThread thread, optional> max_time); + bool RunTasks(TaskThread thread, std::optional> max_time); struct TaskQueue { - optional idle_task; + std::optional idle_task; std::vector tasks; std::mutex tasks_mutex; }; diff --git a/src/test.cc b/src/test.cc index 925a82f4..22524ab7 100644 --- a/src/test.cc +++ b/src/test.cc @@ -200,8 +200,8 @@ void DiffDocuments(std::string path, << std::endl; #if _POSIX_C_SOURCE >= 200809L - char expected_file[] = "/tmp/cquery.expected.XXXXXX"; - char actual_file[] = "/tmp/cquery.actual.XXXXXX"; + char expected_file[] = "/tmp/ccls.expected.XXXXXX"; + char actual_file[] = "/tmp/ccls.actual.XXXXXX"; int expected_fd = mkstemp(expected_file); int actual_fd = mkstemp(actual_file); dprintf(expected_fd, "%s", joined_expected_output.c_str()); @@ -269,7 +269,7 @@ void VerifySerializeToFrom(IndexFile* file) { std::string serialized = Serialize(SerializeFormat::Json, *file); std::unique_ptr result = Deserialize(SerializeFormat::Json, "--.cc", serialized, "", - nullopt /*expected_version*/); + std::nullopt /*expected_version*/); std::string actual = result->ToString(); if (expected != actual) { std::cerr << "Serialization failure" << std::endl; @@ -310,7 +310,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) { if (GetClangVersion() != kRequiredClangVersion && GetClangVersion().find("trunk") == std::string::npos) { std::cerr << "Index tests must be run using clang version \"" - << kRequiredClangVersion << "\" (cquery is running with \"" + << kRequiredClangVersion << "\" (ccls is running with \"" << GetClangVersion() << "\")" << std::endl; return false; } @@ -378,7 +378,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) { std::string expected_output = text_replacer.Apply(entry.second); // FIXME: promote to utils, find and remove duplicates (ie, - // cquery_call_tree.cc, maybe something in project.cc). + // ccls_call_tree.cc, maybe something in project.cc). auto basename = [](const std::string& path) -> std::string { size_t last_index = path.find_last_of('/'); if (last_index == std::string::npos) diff --git a/src/threaded_queue.h b/src/threaded_queue.h index 5f9404e0..5b3608a8 100644 --- a/src/threaded_queue.h +++ b/src/threaded_queue.h @@ -2,7 +2,7 @@ #include "utils.h" -#include +#include #include #include @@ -172,7 +172,7 @@ struct ThreadedQueue : public BaseThreadQueue { // Get the first element from the queue without blocking. Returns a null // value if the queue is empty. - optional TryPopFrontHelper(int which) { + std::optional TryPopFrontHelper(int which) { std::lock_guard lock(mutex_); auto execute = [&](std::deque* q) { auto val = std::move(q->front()); @@ -184,12 +184,12 @@ struct ThreadedQueue : public BaseThreadQueue { return execute(&priority_); if (which & 1 && queue_.size()) return execute(&queue_); - return nullopt; + return std::nullopt; } - optional TryPopFront() { return TryPopFrontHelper(3); } + std::optional TryPopFront() { return TryPopFrontHelper(3); } - optional TryPopBack() { + std::optional TryPopBack() { std::lock_guard lock(mutex_); auto execute = [&](std::deque* q) { auto val = std::move(q->back()); @@ -202,12 +202,12 @@ struct ThreadedQueue : public BaseThreadQueue { return execute(&queue_); if (priority_.size()) return execute(&priority_); - return nullopt; + return std::nullopt; } - optional TryPopFrontLow() { return TryPopFrontHelper(1); } + std::optional TryPopFrontLow() { return TryPopFrontHelper(1); } - optional TryPopFrontHigh() { return TryPopFrontHelper(2); } + std::optional TryPopFrontHigh() { return TryPopFrontHelper(2); } mutable std::mutex mutex_; diff --git a/src/timer.cc b/src/timer.cc index c2b37c0b..94bc9cf5 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -46,7 +46,7 @@ void Timer::Pause() { .count(); elapsed_ += elapsed; - start_ = nullopt; + start_ = std::nullopt; } void Timer::Resume() { diff --git a/src/timer.h b/src/timer.h index bbe2a955..182da671 100644 --- a/src/timer.h +++ b/src/timer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -25,7 +25,7 @@ struct Timer { void Resume(); // Raw start time. - optional> start_; + std::optional> start_; // Elapsed time. long long elapsed_ = 0; }; diff --git a/src/timestamp_manager.cc b/src/timestamp_manager.cc index c9924147..77f69acc 100644 --- a/src/timestamp_manager.cc +++ b/src/timestamp_manager.cc @@ -3,7 +3,7 @@ #include "cache_manager.h" #include "indexer.h" -optional TimestampManager::GetLastCachedModificationTime( +std::optional TimestampManager::GetLastCachedModificationTime( ICacheManager* cache_manager, const std::string& path) { { @@ -14,7 +14,7 @@ optional TimestampManager::GetLastCachedModificationTime( } IndexFile* file = cache_manager->TryLoad(path); if (!file) - return nullopt; + return std::nullopt; UpdateCachedModificationTime(path, file->last_modification_time); return file->last_modification_time; diff --git a/src/timestamp_manager.h b/src/timestamp_manager.h index 5fbc0865..ac02b10f 100644 --- a/src/timestamp_manager.h +++ b/src/timestamp_manager.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -11,7 +11,7 @@ struct ICacheManager; // important for import perf, as during dependency checking the same files are // checked over and over again if they are common headers. struct TimestampManager { - optional GetLastCachedModificationTime(ICacheManager* cache_manager, + std::optional GetLastCachedModificationTime(ICacheManager* cache_manager, const std::string& path); void UpdateCachedModificationTime(const std::string& path, int64_t timestamp); diff --git a/src/utils.cc b/src/utils.cc index 38080abf..f20e3c02 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -215,14 +215,14 @@ static void GetFilesInFolderHelper( goto bail; } - // Skip all dot files except .cquery. + // Skip all dot files except .ccls. // // The nested ifs are intentional, branching order is subtle here. // // Note that in the future if we do support dot directories/files, we must // always ignore the '.' and '..' directories otherwise this will loop // infinitely. - if (file.name[0] != '.' || strcmp(file.name, ".cquery") == 0) { + if (file.name[0] != '.' || strcmp(file.name, ".ccls") == 0) { if (file.is_dir) { if (recursive) { std::string child_dir = q.front().second + file.name + "/"; @@ -315,7 +315,7 @@ bool FileExists(const std::string& filename) { return cache.is_open(); } -optional ReadContent(const std::string& filename) { +std::optional ReadContent(const std::string& filename) { LOG_S(INFO) << "Reading " << filename; std::ifstream cache; cache.open(filename); @@ -324,7 +324,7 @@ optional ReadContent(const std::string& filename) { return std::string(std::istreambuf_iterator(cache), std::istreambuf_iterator()); } catch (std::ios_base::failure&) { - return nullopt; + return std::nullopt; } } diff --git a/src/utils.h b/src/utils.h index da54e338..860a8fa2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include #include #include @@ -94,7 +94,7 @@ std::string EscapeFileName(std::string path); // FIXME: Move ReadContent into ICacheManager? bool FileExists(const std::string& filename); -optional ReadContent(const std::string& filename); +std::optional ReadContent(const std::string& filename); std::vector ReadLinesWithEnding(std::string filename); std::vector ToLines(const std::string& content, bool trim_whitespace); diff --git a/src/working_files.cc b/src/working_files.cc index 64c091c3..1e173eec 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -146,7 +146,7 @@ int AlignColumn(const std::string& a, int column, std::string b, bool is_end) { // Find matching buffer line of index_lines[line]. // By symmetry, this can also be used to find matching index line of a buffer // line. -optional FindMatchingLine(const std::vector& index_lines, +std::optional FindMatchingLine(const std::vector& index_lines, const std::vector& index_to_buffer, int line, int* column, @@ -171,7 +171,7 @@ optional FindMatchingLine(const std::vector& index_lines, down = down >= int(index_to_buffer.size()) ? int(buffer_lines.size()) - 1 : index_to_buffer[down]; if (up > down) - return nullopt; + return std::nullopt; // Search for lines [up,down] and use Myers's diff algorithm to find the best // match (least edit distance). @@ -313,7 +313,7 @@ void WorkingFile::ComputeLineMapping() { buffer_to_index[index_to_buffer[i]] = i; } -optional WorkingFile::GetBufferPosFromIndexPos(int line, +std::optional WorkingFile::GetBufferPosFromIndexPos(int line, int* column, bool is_end) { // The implementation is simple but works pretty well for most cases. We @@ -333,7 +333,7 @@ optional WorkingFile::GetBufferPosFromIndexPos(int line, LOG_S(WARNING) << "Bad index_line (got " << line << ", expected [0, " << index_lines.size() << ")) in " << filename << stack.c_str(); - return nullopt; + return std::nullopt; } if (index_to_buffer.empty()) @@ -342,12 +342,12 @@ optional WorkingFile::GetBufferPosFromIndexPos(int line, buffer_lines, is_end); } -optional WorkingFile::GetIndexPosFromBufferPos(int line, +std::optional WorkingFile::GetIndexPosFromBufferPos(int line, int* column, bool is_end) { // See GetBufferLineFromIndexLine for additional comments. if (line < 0 || line >= (int)buffer_lines.size()) - return nullopt; + return std::nullopt; if (buffer_to_index.empty()) ComputeLineMapping(); diff --git a/src/working_files.h b/src/working_files.h index 60ce3375..c48c57d8 100644 --- a/src/working_files.h +++ b/src/working_files.h @@ -4,7 +4,7 @@ #include "utils.h" #include -#include +#include #include #include @@ -42,10 +42,10 @@ struct WorkingFile { // Also resolves |column| if not NULL. // When resolving a range, use is_end = false for begin() and is_end = // true for end() to get a better alignment of |column|. - optional GetBufferPosFromIndexPos(int line, int* column, bool is_end); + std::optional GetBufferPosFromIndexPos(int line, int* column, bool is_end); // Finds the index line number which maps to buffer line number |line|. // Also resolves |column| if not NULL. - optional GetIndexPosFromBufferPos(int line, int* column, bool is_end); + std::optional GetIndexPosFromBufferPos(int line, int* column, bool is_end); // TODO: Move FindClosestCallNameInBuffer and FindStableCompletionSource into // lex_utils.h/cc diff --git a/third_party/string_view.h b/third_party/string_view.h deleted file mode 100644 index 3c858d73..00000000 --- a/third_party/string_view.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#define STX_NAMESPACE_NAME std -#include "string_view.hpp"