From 21240d9af9de65d39d4e38d0dffab6912f9a7e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 15 Jan 2023 16:37:16 -0300 Subject: [PATCH] Added Sys::which. ecode: Added support for more LSP servers: Kotlin, Nim, Ruby, YAML. Added "Format Document" option in editor's context menu (when available). --- README.md | 2 +- bin/assets/plugins/lspclient.json | 31 ++++++- include/eepp/system/sys.hpp | 5 + projects/linux/ee.creator.user | 2 +- src/eepp/system/sys.cpp | 91 ++++++++++++++++--- src/examples/empty_window/empty_window.cpp | 2 +- src/modules/maps/include/eepp/maps/base.hpp | 2 + .../physics/include/eepp/physics/base.hpp | 2 + .../plugins/formatter/formatterplugin.cpp | 24 +++++ .../plugins/formatter/formatterplugin.hpp | 3 + 10 files changed, 149 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7ae2a02ee..d12f72efa 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,7 @@ Note: Please use a modern browser with good WebGL and WASM support (Chrome/ium 7 * **[Fonts example](https://cdn.ensoft.dev/eepp-demos/demo-fs.html?run=eepp-fonts.js)** -* **[Physics module demo](https://cdn.ensoft.dev/eepp-demos/demo-fs.html?run=eepp-physics.js)** +* **[Physics module demo](https://cdn.ensoft.dev/eepp-demos/demo-fs.html?run=eepp-physics-demo.js)** * **[Sprites example](https://cdn.ensoft.dev/eepp-demos/demo-fs.html?run=eepp-sprites.js)** diff --git a/bin/assets/plugins/lspclient.json b/bin/assets/plugins/lspclient.json index fea4f66ee..cb82e1436 100644 --- a/bin/assets/plugins/lspclient.json +++ b/bin/assets/plugins/lspclient.json @@ -7,7 +7,7 @@ "name": "typescript-language-server", "url": "https://github.com/theia-ide/typescript-language-server", "command": "typescript-language-server --stdio", - "file_patterns": ["%.ts$"], + "file_patterns": ["%.ts$", "%.tsx$"], "rootIndicationFileNames": ["package.json", "package-lock.json"], "initializationOptions": { "preferences": { @@ -97,6 +97,35 @@ "url": "https://github.com/sumneko/lua-language-server", "command": "lua-language-server", "file_patterns": ["%.lua"] + }, + { + "language": "kotlin", + "name": "kotlin-language-server", + "url": "https://github.com/fwcd/kotlin-language-server", + "command": "kotlin-language-server", + "file_patterns": ["%.kt"] + }, + { + "language": "nim", + "name": "nimlsp", + "url": "https://github.com/PMunch/nimlsp", + "command": "nimlsp", + "file_patterns": ["%.nim"] + }, + { + "language": "ruby", + "name": "solargraph", + "url": "https://solargraph.org", + "command": "solargraph stdio", + "rootIndicationFileNames": ["Gemfile", "Gemfile.lock", "gems.rb", "gems.lock", "Rakefile"], + "file_patterns": ["%.rb"] + }, + { + "language": "yaml", + "name": "yaml-language-server", + "url": "https://github.com/redhat-developer/yaml-language-server", + "command": "yaml-language-server --stdio", + "file_patterns": ["%.yaml", "%.yml"] } ] } diff --git a/include/eepp/system/sys.hpp b/include/eepp/system/sys.hpp index 5a03e9a3b..41ca22131 100644 --- a/include/eepp/system/sys.hpp +++ b/include/eepp/system/sys.hpp @@ -78,6 +78,11 @@ class EE_API Sys { /** @return The OS logical drives */ static std::vector getLogicalDrives(); + + /** Finds the location of a binary / executable file. + * @return The executable file path, or an empty string if not found. */ + static std::string which( const std::string& exeName, + const std::vector& customSearchPaths = {} ); }; }} // namespace EE::System diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 7d97d83d6..0cf237108 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp index cad142981..dafc2dd0f 100644 --- a/src/eepp/system/sys.cpp +++ b/src/eepp/system/sys.cpp @@ -24,6 +24,7 @@ #ifndef NOMINMAX #define NOMINMAX #endif +#include #include #undef GetDiskFreeSpace #undef GetTempPath @@ -32,13 +33,13 @@ #include #include #elif EE_PLATFORM == EE_PLATFORM_HAIKU -#include -#include #include #include #include #include #include +#include +#include #include #elif EE_PLATFORM == EE_PLATFORM_SOLARIS #include @@ -980,23 +981,23 @@ std::vector Sys::getLogicalDrives() { BVolumeRoster mounts; BVolume vol; mounts.Rewind(); - while (mounts.GetNextVolume(&vol) == B_NO_ERROR) { + while ( mounts.GetNextVolume( &vol ) == B_NO_ERROR ) { fs_info fsinfo; - fs_stat_dev(vol.Device(), &fsinfo); + fs_stat_dev( vol.Device(), &fsinfo ); BDirectory directory; BEntry entry; BPath path; status_t rc; - rc = vol.GetRootDirectory(&directory); - if (rc < B_OK) + rc = vol.GetRootDirectory( &directory ); + if ( rc < B_OK ) continue; - rc = directory.GetEntry(&entry); - if (rc < B_OK) + rc = directory.GetEntry( &entry ); + if ( rc < B_OK ) continue; - rc = entry.GetPath(&path); - if (rc < B_OK) + rc = entry.GetPath( &path ); + if ( rc < B_OK ) continue; - const char *str = path.Path(); + const char* str = path.Path(); ret.emplace_back( str ); } return ret; @@ -1005,4 +1006,72 @@ std::vector Sys::getLogicalDrives() { #endif } +static std::string getenv( const std::string& name ) { +#if EE_PLATFORM == EE_PLATFORM_WIN && defined( EE_COMPILER_MSVC ) + wchar_t* envbuf; + size_t envsize; + _wdupenv_s( &envbuf, &envsize, String( name ).toWideString().c_str() ); + std::string env; + if ( NULL != envbuf ) + env = String::fromWide( envbuf ).toUtf8(); + free( envbuf ); + return env; +#else + char* env = ::getenv( name.c_str() ); + return NULL == env ? std::string() : std::string( env ); +#endif +} + +#if EE_PLATFORM == EE_PLATFORM_WIN +#define PATH_SEP_CHAR ';' +#else +#define PATH_SEP_CHAR ':' +#endif +std::string Sys::which( const std::string& exeName, + const std::vector& customSearchPaths ) { + std::string PATH = getenv( "PATH" ); + std::vector PATHS = String::split( PATH, PATH_SEP_CHAR ); +#if EE_PLATFORM == EE_PLATFORM_WIN + static std::vector PATHEXTS = String::split( getenv( "PATHEXT" ), PATH_SEP_CHAR ); + std::string exePath; +#endif + + if ( !customSearchPaths.empty() ) { + for ( const auto& searchPath : customSearchPaths ) + PATHS.emplace_back( searchPath ); + } + +#if EE_PLATFORM == EE_PLATFORM_WIN + bool hasExtension = false; + for ( const auto& pathExt : PATHEXTS ) { + if ( String::endsWith( exeName, pathExt ) ) { + hasExtension = true; + break; + } + } +#endif + + for ( const auto& path : PATHS ) { + std::string fpath( path ); + FileSystem::dirAddSlashAtEnd( fpath ); + fpath += exeName; +#if EE_PLATFORM == EE_PLATFORM_WIN + if ( hasExtension ) { + if ( FileSystem::fileExists( fpath ) ) + return fpath; + } else { + for ( const auto& pathext : PATHEXTS ) { + exePath = fpath + pathext; + if ( FileSystem::fileExists( exePath ) ) + return exePath; + } + } +#else + if ( FileSystem::fileExists( fpath ) ) + return fpath; +#endif + } + return ""; +} + }} // namespace EE::System diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index fe140b963..d3899737b 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -29,7 +29,7 @@ void mainLoop() { } // EE_MAIN_FUNC is needed by some platforms to be able to find the real application main -EE_MAIN_FUNC int main( int argc, char* argv[] ) { +EE_MAIN_FUNC int main( int, char*[] ) { // Create a new window with vsync enabled win = Engine::instance()->createWindow( WindowSettings( 960, 640, "eepp - Empty Window" ), ContextSettings( true ) ); diff --git a/src/modules/maps/include/eepp/maps/base.hpp b/src/modules/maps/include/eepp/maps/base.hpp index c8df1fe20..29b6dcaac 100644 --- a/src/modules/maps/include/eepp/maps/base.hpp +++ b/src/modules/maps/include/eepp/maps/base.hpp @@ -21,6 +21,7 @@ using namespace EE::System; #ifndef EE_MAPS_STATIC #if EE_PLATFORM == EE_PLATFORM_WIN // Windows platforms +#ifndef EE_MAPS_API #ifdef EE_MAPS_EXPORTS // From DLL side, we must export #define EE_MAPS_API __declspec( dllexport ) @@ -28,6 +29,7 @@ using namespace EE::System; // From client application side, we must import #define EE_MAPS_API __declspec( dllimport ) #endif +#endif #else #if ( __GNUC__ >= 4 ) && !defined( EE_MAPS_API ) #define EE_MAPS_API __attribute__( ( visibility( "default" ) ) ) diff --git a/src/modules/physics/include/eepp/physics/base.hpp b/src/modules/physics/include/eepp/physics/base.hpp index 6ed29930b..22f265721 100644 --- a/src/modules/physics/include/eepp/physics/base.hpp +++ b/src/modules/physics/include/eepp/physics/base.hpp @@ -24,6 +24,7 @@ using namespace EE::System; #ifndef EE_PHYSICS_STATIC #if EE_PLATFORM == EE_PLATFORM_WIN // Windows platforms +#ifndef EE_PHYSICS_API #ifdef EE_PHYSICS_EXPORTS // From DLL side, we must export #define EE_PHYSICS_API __declspec( dllexport ) @@ -31,6 +32,7 @@ using namespace EE::System; // From client application side, we must import #define EE_PHYSICS_API __declspec( dllimport ) #endif +#endif #else #if ( __GNUC__ >= 4 ) && !defined( EE_PHYSICS_API ) #define EE_PHYSICS_API __attribute__( ( visibility( "default" ) ) ) diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index d7c5d66f4..1e8964163 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #define PUGIXML_HEADER_ONLY @@ -219,6 +220,29 @@ std::string FormatterPlugin::getFileConfigPath() { return mConfigPath; } +bool FormatterPlugin::onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, const Vector2i&, + const Uint32& ) { + const auto& patterns = editor->getDocument().getSyntaxDefinition().getFiles(); + bool found = false; + for ( const auto& formatter : mFormatters ) { + for ( const auto& pattern : patterns ) { + if ( std::find( formatter.files.begin(), formatter.files.end(), pattern ) != + formatter.files.end() ) { + found = true; + break; + } + } + } + if ( !found ) + return false; + + menu->add( editor->getUISceneNode()->i18n( "formatter-format-document", "Format Document" ), + nullptr, KeyBindings::keybindFormat( mKeyBindings["format-doc"] ) ) + ->setId( "format-doc" ); + + return false; +} + void FormatterPlugin::formatDoc( UICodeEditor* editor ) { ScopedOp op( [&]() { diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.hpp b/src/tools/ecode/plugins/formatter/formatterplugin.hpp index 5cf79c908..efeb02239 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.hpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.hpp @@ -59,6 +59,9 @@ class FormatterPlugin : public UICodeEditorPlugin { std::string getFileConfigPath(); + virtual bool onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, + const Vector2i& position, const Uint32& flags ); + protected: enum class FormatterType { Inplace, Output, Native };