diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c0674..ce09596 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## Changed + + - Reorganization of all "sub applications" in sub-cmake files + +## Fixed + + - Removed definition of hash for slang::SourceRange introduced by Slang 7.0 (#14) + +## Dependencies + + - Slang from 6.0 to 7.0 + - uri from `master` to a fixed hash + remove shallow clone (#13) + + +# 0.2.0 + ## Added - Add support for `include` folders in config files. diff --git a/CMakeLists.txt b/CMakeLists.txt index 8100f68..69d02a4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ endif() message(STATUS "Software version: " ${VERSION_STRING}) + # Use sockpp as a static lib option(SOCKPP_BUILD_SHARED "" OFF) option(SOCKPP_BUILD_STATIC "" ON) @@ -44,128 +45,36 @@ option(SPDLOG_FMT_EXTERNAL "" ON) # As workaround option(SLANG_USE_MIMALLOC "" ON) -# Add all third parties -include(third-party.cmake) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -set(LSP_METAMODEL_PATH ${CMAKE_CURRENT_BINARY_DIR}/metaModel.json) -set(LSP_DATASTRUCT_ROOT ${CMAKE_SOURCE_DIR}/lsp-server/include/types) -set(LSP_DATASTRUCT_CMAKE ${LSP_DATASTRUCT_ROOT}/generated_headers.cmake) -if(NOT EXISTS ${LSP_DATASTRUCT_CMAKE} OR NOT EXISTS ${LSP_METAMODEL_PATH}) - - message(STATUS "Regenerating LSP data structures using " ${LSP_METAMODEL_PATH}) - file( - DOWNLOAD https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/metaModel/metaModel.json - ${LSP_METAMODEL_PATH} - ) +# Add all third parties +include(cmake/third-party.cmake) +include(cmake/create-component.cmake) +include(cmake/lsp-datastructures.cmake) - execute_process(COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/LSPGen/main.py -fo ${LSP_DATASTRUCT_ROOT} ${LSP_METAMODEL_PATH}) - message(STATUS "Regeneration done. ") -endif() -include(${LSP_DATASTRUCT_CMAKE}) -list(TRANSFORM SVLS_GEN_HEADERS PREPEND ${LSP_DATASTRUCT_ROOT}/) - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) # add_subdirectory(lib-diplomat-index) ########################################################### # SV-FORMATTER ########################################################### -message(STATUS "Setup SV-Formatter library and executable ") -add_library(sv-formatter-lib STATIC - formatter/format_DataDeclaration.cpp - formatter/spacing_manager.cpp -) - -target_link_libraries(sv-formatter-lib PRIVATE slang::slang) -target_include_directories(sv-formatter-lib INTERFACE formatter/) - -add_executable(sv-formatter-exe - -utils/ast-printer/ast_print.cpp - -formatter/main_formatter.cpp -) - -target_link_libraries(sv-formatter-exe -PRIVATE argparse::argparse -PRIVATE fmt::fmt -PRIVATE spdlog::spdlog - -PRIVATE slang::slang -PRIVATE sv-formatter-lib -) - - -target_include_directories(sv-formatter-exe -PRIVATE $ -PRIVATE utils/ast-printer) - -set_property(TARGET sv-formatter-exe PROPERTY OUTPUT_NAME sv-formatter) -set_property(TARGET sv-formatter-lib PROPERTY OUTPUT_NAME sv-formatter) - -message(STATUS "Setup SV-Explorer library and executable ") +include(cmake/sv-formatter.cmake) +include(cmake/sv-explorer.cmake) +# include(cmake/sv-indexer.cmake) -add_library(sv-explorer-lib STATIC -explorer/hier_visitor.cpp -) - -target_link_libraries(sv-explorer-lib -PRIVATE slang::slang -PRIVATE nlohmann_json::nlohmann_json) -target_include_directories(sv-explorer-lib INTERFACE explorer/) - - -add_executable(sv-explorer-exe -explorer/main.cpp -explorer/explorer_visitor.cpp -) - -target_link_libraries(sv-explorer-exe -PRIVATE nlohmann_json::nlohmann_json -PRIVATE slang::slang -PRIVATE sv-explorer-lib -) - - -target_include_directories(sv-explorer-exe -PRIVATE $ -PRIVATE utils/ast_print) - -set_property(TARGET sv-explorer-exe PROPERTY OUTPUT_NAME sv-explorer) -set_property(TARGET sv-explorer-lib PROPERTY OUTPUT_NAME sv-explorer) - ###################################################################### ###################################################################### ###################################################################### -# target_link_libraries(sv-explorer -# PRIVATE nlohmann_json::nlohmann_json -# PRIVATE slang::slang) - -# target_include_directories(sv-explorer -# PRIVATE explorer/) - -###################################################################### -###################################################################### -###################################################################### - message(STATUS "Setup SV-LSP executable and other stuff") -# add_library(diplomat-system-lib STATIC -# system/src/process_handler_lnx.cpp -# ) - -# target_include_directories(diplomat-system-lib PRIVATE system/include) - - add_executable(sv-blackbox main_blackbox.cpp documenter_visitor.h documenter_visitor.cpp) @@ -194,7 +103,6 @@ lsp-server/diplomat/src/visitor_module_bb.cpp lsp-server/diplomat/src/visitor_index.cpp lsp-server/diplomat/src/diagnostic_client.cpp lsp-server/diplomat/src/diplomat_index.cpp - ) target_compile_definitions(slang-lsp PUBLIC DIPLOMAT_VERSION_STRING=\"${VERSION_STRING}\") @@ -214,6 +122,7 @@ PRIVATE spdlog::spdlog PRIVATE nlohmann_json::nlohmann_json PRIVATE sv-formatter-lib PRIVATE sv-explorer-lib +# PRIVATE sv-indexer-lib PUBLIC slang::slang ) @@ -238,8 +147,12 @@ utils/ast-printer/ast_print.cpp utils/ast-printer/ast_print_main.cpp ) +target_include_directories(sv-tree +PRIVATE utils/ast-printer +) + target_link_libraries(sv-tree -PRIVATE slang::slang +PUBLIC slang::slang PRIVATE argparse::argparse) # target_include_directories(sv-explorer diff --git a/cmake/create-component.cmake b/cmake/create-component.cmake new file mode 100644 index 0000000..ff0df86 --- /dev/null +++ b/cmake/create-component.cmake @@ -0,0 +1,62 @@ +function(create_component NAME) + set(options NOLIB) + set(multiValueArgs + LIB_SRC + LIB_INC + LIB_LINK + EXE_SRC + EXE_INC + EXE_LINK + ) + cmake_parse_arguments(PARSE_ARGV 1 COMP "${options}" "${oneValueArgs}" "${multiValueArgs}") + + if(NOT ${COMP_NOLIB}) + add_library(${NAME}-lib STATIC) + if(DEFINED COMP_LIB_SRC) + target_sources(${NAME}-lib ${COMP_LIB_SRC}) + endif() + + if(DEFINED COMP_LIB_LINK) + target_link_libraries(${NAME}-lib ${COMP_LIB_LINK}) + endif() + + if(DEFINED COMP_LIB_INC) + target_include_directories(${NAME}-lib ${COMP_LIB_INC}) + endif() + + if(NOT DEFINED COMP_EXE_LINK) + set(COMP_EXE_LINK "") + endif() + + if(NOT DEFINED COMP_EXE_INC) + set(COMP_EXE_LINK "") + endif() + + list(PREPEND COMP_EXE_LINK PRIVATE ${NAME}-lib) + list(PREPEND COMP_EXE_INC PRIVATE $) + # message(STATUS " EXE INC : ${COMP_EXE_INC}") + # Override the output name to avoid libNAME-lib.so + # The lib prefix is automatically added. + set_property(TARGET ${NAME}-lib PROPERTY OUTPUT_NAME ${NAME}) + else() + message(STATUS "No library for target component ${NAME}") + endif() + + add_executable(${NAME}-exe) + if(DEFINED COMP_EXE_SRC) + target_sources(${NAME}-exe ${COMP_EXE_SRC}) + else() + message(ERROR "Component ${NAME} have no source specified for its executable (EXE_SRC)") + endif() + + + target_link_libraries(${NAME}-exe ${COMP_EXE_LINK}) + target_include_directories(${NAME}-exe ${COMP_EXE_INC}) + + # Override the output name of the executable to have a clean NAME + # instead of NAME-exe. + set_property(TARGET ${NAME}-exe PROPERTY OUTPUT_NAME ${NAME}) + + message(STATUS "Created targets for component ${NAME}.") + +endfunction(create_component) diff --git a/cmake/lsp-datastructures.cmake b/cmake/lsp-datastructures.cmake new file mode 100644 index 0000000..a67e4c1 --- /dev/null +++ b/cmake/lsp-datastructures.cmake @@ -0,0 +1,19 @@ +set(LSP_METAMODEL_PATH ${CMAKE_CURRENT_BINARY_DIR}/metaModel.json) +set(LSP_DATASTRUCT_ROOT ${CMAKE_SOURCE_DIR}/lsp-server/include/types) +set(LSP_DATASTRUCT_CMAKE ${LSP_DATASTRUCT_ROOT}/generated_headers.cmake) + +if(NOT EXISTS ${LSP_DATASTRUCT_CMAKE} OR NOT EXISTS ${LSP_METAMODEL_PATH}) + + message(STATUS "Regenerating LSP data structures using " ${LSP_METAMODEL_PATH}) + file( + DOWNLOAD https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/metaModel/metaModel.json + ${LSP_METAMODEL_PATH} + ) + + execute_process(COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/LSPGen/main.py -fo ${LSP_DATASTRUCT_ROOT} ${LSP_METAMODEL_PATH}) + message(STATUS "Regeneration done. ") + +endif() + +include(${LSP_DATASTRUCT_CMAKE}) +list(TRANSFORM SVLS_GEN_HEADERS PREPEND ${LSP_DATASTRUCT_ROOT}/) \ No newline at end of file diff --git a/cmake/sv-explorer.cmake b/cmake/sv-explorer.cmake new file mode 100644 index 0000000..a4cb7d3 --- /dev/null +++ b/cmake/sv-explorer.cmake @@ -0,0 +1,18 @@ + +create_component(sv-explorer +LIB_SRC + PRIVATE explorer/hier_visitor.cpp +LIB_INC + INTERFACE explorer/ +LIB_LINK + PUBLIC slang::slang + PUBLIC nlohmann_json::nlohmann_json +EXE_SRC + PRIVATE explorer/main.cpp + PRIVATE explorer/explorer_visitor.cpp +EXE_INC + PRIVATE utils/ast-printer +EXE_LINK + PRIVATE slang::slang + PRIVATE nlohmann_json::nlohmann_json + ) \ No newline at end of file diff --git a/cmake/sv-formatter.cmake b/cmake/sv-formatter.cmake new file mode 100644 index 0000000..507524a --- /dev/null +++ b/cmake/sv-formatter.cmake @@ -0,0 +1,20 @@ +create_component(sv-formatter +LIB_SRC + PRIVATE formatter/format_DataDeclaration.cpp + PRIVATE formatter/spacing_manager.cpp +LIB_INC + INTERFACE formatter/ +LIB_LINK + PUBLIC slang::slang +EXE_SRC + PRIVATE utils/ast-printer/ast_print.cpp + PRIVATE formatter/main_formatter.cpp +EXE_INC + PRIVATE utils/ast-printer +EXE_LINK + PRIVATE argparse::argparse + PRIVATE fmt::fmt + PRIVATE spdlog::spdlog + PRIVATE slang::slang + PRIVATE sv-formatter-lib + ) \ No newline at end of file diff --git a/cmake/sv-indexer.cmake b/cmake/sv-indexer.cmake new file mode 100644 index 0000000..9a3d2db --- /dev/null +++ b/cmake/sv-indexer.cmake @@ -0,0 +1,14 @@ +create_component(sv-indexer +LIB_SRC + PRIVATE indexer/index_elements.cpp + PRIVATE indexer/diplomat_index.cpp + PRIVATE indexer/visitor_index.cpp +LIB_INC + PUBLIC indexer/include +LIB_LINK + PUBLIC slang::slang + PUBLIC nlohmann_json::nlohmann_json + spdlog::spdlog +EXE_SRC + PRIVATE indexer/main_indexer.cpp + ) \ No newline at end of file diff --git a/cmake/third-party.cmake b/cmake/third-party.cmake new file mode 100755 index 0000000..e0f4838 --- /dev/null +++ b/cmake/third-party.cmake @@ -0,0 +1,57 @@ +include(FetchContent) + +# Base library, might be used as dependencies for others + + +FetchContent_Declare(fmt +GIT_REPOSITORY https://github.com/fmtlib/fmt.git +#GIT_TAG 10.2.1 # For correct management with slang +GIT_TAG 11.0.2 +GIT_SHALLOW ON) + +FetchContent_Declare(network +GIT_REPOSITORY https://github.com/fpagliughi/sockpp.git +GIT_TAG v1.0.0 +GIT_SHALLOW ON) + +FetchContent_Declare(spdlog +GIT_REPOSITORY https://github.com/gabime/spdlog.git +GIT_TAG v1.14.1 +GIT_SHALLOW ON) + +FetchContent_Declare(json +GIT_REPOSITORY https://github.com/nlohmann/json.git +GIT_TAG v3.11.3 +GIT_SHALLOW ON) + +FetchContent_Declare(uri +GIT_REPOSITORY https://github.com/ben-zen/uri-library.git +GIT_TAG 6b1b15a +GIT_SHALLOW OFF) + +FetchContent_Declare(uuid +GIT_REPOSITORY https://github.com/mariusbancila/stduuid.git +GIT_TAG v1.2.3 +GIT_SHALLOW ON) + +# Core feature providers +FetchContent_Declare( slang + GIT_REPOSITORY https://github.com/MikePopoloski/slang.git + GIT_TAG v7.0 + GIT_SHALLOW ON) + + +FetchContent_Declare(argparse + GIT_REPOSITORY https://github.com/p-ranav/argparse.git + GIT_TAG v3.1 + GIT_SHALLOW ON) + +FetchContent_MakeAvailable(uri) + +# FetchContent_MakeAvailable(pgm-index) + +FetchContent_MakeAvailable(fmt network uuid) +FetchContent_MakeAvailable(json spdlog) +FetchContent_MakeAvailable(argparse slang) + +include_directories($) diff --git a/lsp-server/diplomat/include/diplomat_index.hpp b/lsp-server/diplomat/include/diplomat_index.hpp index 92c0812..edb9510 100755 --- a/lsp-server/diplomat/include/diplomat_index.hpp +++ b/lsp-server/diplomat/include/diplomat_index.hpp @@ -5,18 +5,6 @@ #include "slang/text/SourceLocation.h" #include "slang/parsing/Token.h" -template<> -struct std::hash -{ - std::size_t operator()(const slang::SourceRange& l) const noexcept - { - std::size_t h1 = std::hash{}(l.start()); - std::size_t h2 = std::hash{}(l.end()); - return h1 ^ (h2 << 1); // or use boost::hash_combine - } -}; - - template<> struct std::hash {