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).
This commit is contained in:
Martín Lucas Golini
2023-01-15 16:37:16 -03:00
parent 1c755196da
commit 21240d9af9
10 changed files with 149 additions and 15 deletions
+1 -1
View File
@@ -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)**
+30 -1
View File
@@ -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"]
}
]
}
+5
View File
@@ -78,6 +78,11 @@ class EE_API Sys {
/** @return The OS logical drives */
static std::vector<std::string> 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<std::string>& customSearchPaths = {} );
};
}} // namespace EE::System
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 8.0.2, 2023-01-15T02:15:07. -->
<!-- Written by QtCreator 8.0.2, 2023-01-15T04:19:38. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
+80 -11
View File
@@ -24,6 +24,7 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <stdlib.h>
#include <windows.h>
#undef GetDiskFreeSpace
#undef GetTempPath
@@ -32,13 +33,13 @@
#include <mntent.h>
#include <unistd.h>
#elif EE_PLATFORM == EE_PLATFORM_HAIKU
#include <kernel/OS.h>
#include <kernel/image.h>
#include <Directory.h>
#include <Path.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <fs_info.h>
#include <kernel/OS.h>
#include <kernel/image.h>
#include <sys/statvfs.h>
#elif EE_PLATFORM == EE_PLATFORM_SOLARIS
#include <stdlib.h>
@@ -980,23 +981,23 @@ std::vector<std::string> 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<std::string> 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<std::string>& customSearchPaths ) {
std::string PATH = getenv( "PATH" );
std::vector<std::string> PATHS = String::split( PATH, PATH_SEP_CHAR );
#if EE_PLATFORM == EE_PLATFORM_WIN
static std::vector<std::string> 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
+1 -1
View File
@@ -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 ) );
@@ -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" ) ) )
@@ -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" ) ) )
@@ -7,6 +7,7 @@
#include <eepp/system/process.hpp>
#include <eepp/ui/css/stylesheet.hpp>
#include <eepp/ui/css/stylesheetparser.hpp>
#include <eepp/ui/uipopupmenu.hpp>
#include <nlohmann/json.hpp>
#include <random>
#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(
[&]() {
@@ -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 };