diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index 50eaf06c4..997e5c80e 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -442,7 +442,11 @@ void FormatterPlugin::runFormatter( UICodeEditor* editor, const Formatter& forma } std::string cmd( formatter.command ); - String::replaceAll( cmd, "$FILENAME", "\"" + path + "\"" ); + std::string pathstr( "\"" + path + "\"" ); + String::replaceAll( cmd, "$FILENAME", pathstr ); + String::replaceAll( cmd, "${file_path}", pathstr ); + String::replaceAll( cmd, "$PROJECTPATH", mPluginManager->getWorkspaceFolder() ); + String::replaceAll( cmd, "${project_root}", mPluginManager->getWorkspaceFolder() ); Process process; if ( process.create( cmd ) ) { std::string data; diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index e1bd848b5..7ececd0fe 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -1,5 +1,5 @@ -#include "linterplugin.hpp" -#include "../../stringhelper.hpp" +#include "../../stringhelper.hpp" +#include "linterplugin.hpp" #include #include #include @@ -827,7 +827,11 @@ void LinterPlugin::runLinter( std::shared_ptr doc, const Linter& l const std::string& path ) { Clock clock; std::string cmd( linter.command ); - String::replaceAll( cmd, "$FILENAME", "\"" + path + "\"" ); + std::string pathstr( "\"" + path + "\"" ); + String::replaceAll( cmd, "$FILENAME", pathstr ); + String::replaceAll( cmd, "${file_path}", pathstr ); + String::replaceAll( cmd, "$PROJECTPATH", mManager->getWorkspaceFolder() ); + String::replaceAll( cmd, "${project_root}", mManager->getWorkspaceFolder() ); if ( linter.isNative && mNativeLinters.find( cmd ) != mNativeLinters.end() ) { mNativeLinters[cmd]( doc, path ); return; diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 01e76bf79..c5f7f67cd 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -1,5 +1,5 @@ -#include "lspclientplugin.hpp" #include "../../version.hpp" +#include "lspclientplugin.hpp" #include #include #include @@ -184,8 +184,12 @@ static LSPURIAndServer getServerURIFromTextDocumentURI( LSPClientServerManager& return { uri, manager.getOneLSPClientServer( uri ) }; } -static void sanitizeCommand( std::string& cmd ) { - String::replaceAll( cmd, "$NPROC", String::toString( Sys::getCPUCount() ) ); +static void sanitizeCommand( std::string& cmd, const std::string& workspaceFolder ) { + std::string cpucount( String::toString( Sys::getCPUCount() ) ); + String::replaceAll( cmd, "$NPROC", cpucount ); + String::replaceAll( cmd, "${nproc}", cpucount ); + String::replaceAll( cmd, "$PROJECTPATH", workspaceFolder ); + String::replaceAll( cmd, "${project_root}", workspaceFolder ); } LSPPositionAndServer getLSPLocationFromJSON( LSPClientServerManager& manager, const json& data ) { @@ -836,7 +840,7 @@ void LSPClientPlugin::load( PluginManager* pluginManager ) { } } -static std::string parseCommand( nlohmann::json cmd ) { +static std::string parseCommand( nlohmann::json cmd, const std::string& workspaceFolder ) { std::string command; if ( cmd.is_string() ) { command = cmd.get(); @@ -852,7 +856,7 @@ static std::string parseCommand( nlohmann::json cmd ) { command = cmd[platform].get(); } } - sanitizeCommand( command ); + sanitizeCommand( command, workspaceFolder ); return command; } @@ -1023,14 +1027,15 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std lspR.shareProcessWithOtherDefinition = obj["share_process"].get(); } if ( obj.contains( "command" ) ) { - lspR.command = parseCommand( obj["command"] ); + lspR.command = + parseCommand( obj["command"], mManager->getWorkspaceFolder() ); } if ( !obj.value( "command_parameters", "" ).empty() ) { std::string cmdParam( obj.value( "command_parameters", "" ) ); if ( !cmdParam.empty() && cmdParam.front() != ' ' ) cmdParam = " " + cmdParam; lspR.commandParameters += cmdParam; - sanitizeCommand( lspR.commandParameters ); + sanitizeCommand( lspR.commandParameters, mManager->getWorkspaceFolder() ); } if ( obj.contains( "host" ) ) { lspR.host = obj.value( "host", "" ); @@ -1062,7 +1067,7 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std if ( tlsp.name == use ) { lsp.language = obj["language"]; foundTlsp = true; - lsp.command = parseCommand( tlsp.command ); + lsp.command = parseCommand( tlsp.command, mManager->getWorkspaceFolder() ); lsp.name = tlsp.name; lsp.rootIndicationFileNames = tlsp.rootIndicationFileNames; lsp.url = tlsp.url; @@ -1083,7 +1088,7 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std } } else { lsp.language = obj["language"]; - lsp.command = parseCommand( obj["command"] ); + lsp.command = parseCommand( obj["command"], mManager->getWorkspaceFolder() ); lsp.name = obj["name"]; lsp.url = obj.value( "url", "" ); lsp.host = obj.value( "host", "" ); @@ -1114,8 +1119,8 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std lsp.rootIndicationFileNames.push_back( fn ); } - sanitizeCommand( lsp.command ); - sanitizeCommand( lsp.commandParameters ); + sanitizeCommand( lsp.command, mManager->getWorkspaceFolder() ); + sanitizeCommand( lsp.commandParameters, mManager->getWorkspaceFolder() ); tryAddEnv( obj, lsp );