MCPcopy Create free account
hub / github.com/SpartanJ/eepp / processMessage

Method processMessage

src/tools/ecode/projectdirectorytree.cpp:619–676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619PluginRequestHandle ProjectDirectoryTree::processMessage( const PluginMessage& msg ) {
620 if ( msg.type != PluginMessageType::FindAndOpenClosestURI || !msg.isRequest() || !msg.isJSON() )
621 return {};
622
623 const nlohmann::json& json = msg.asJSON();
624 if ( !json.contains( "uri" ) )
625 return {};
626
627 nlohmann::json juris = json.at( "uri" );
628 std::vector<std::string> expectedNames;
629 std::vector<std::string> tentativePaths;
630 for ( const auto& turi : juris ) {
631 std::string path( URI( turi.get<std::string>() ).getFSPath() );
632 tentativePaths.emplace_back( path );
633 expectedNames.emplace_back( FileSystem::fileNameFromPath( path ) );
634 }
635
636 auto model = fuzzyMatchTree( expectedNames, 10 );
637
638 size_t rowCount = model->rowCount( {} );
639 if ( rowCount == 0 )
640 return {};
641
642 std::map<int, std::string, std::greater<int>> matchesMap;
643
644 for ( size_t i = 0; i < rowCount; ++i ) {
645 Variant dataName = model->data( model->index( i, 0 ) );
646 Variant dataPath = model->data( model->index( i, 1 ) );
647 if ( dataName.isString() && dataPath.isString() ) {
648 std::string fileName( dataName.toString() );
649 std::string filePath( dataPath.toString() );
650 if ( std::find( expectedNames.begin(), expectedNames.end(), fileName ) !=
651 expectedNames.end() ) {
652 std::string closestDataPath;
653 int max{ std::numeric_limits<int>::min() };
654 for ( const auto& paths : tentativePaths ) {
655 int res = String::fuzzyMatch( filePath.c_str(), paths.c_str() );
656 if ( res > max ) {
657 closestDataPath = filePath;
658 max = res;
659 }
660 }
661 if ( !closestDataPath.empty() )
662 matchesMap[max] = closestDataPath;
663 }
664 }
665 }
666
667 if ( !matchesMap.empty() ) {
668 if ( mPluginManager && mLoadFileFromPathOrFocusFn ) {
669 std::string filePath( matchesMap.begin()->second );
670 mPluginManager->getUISceneNode()->runOnMainThread(
671 [this, filePath]() { mLoadFileFromPathOrFocusFn( filePath ); } );
672 }
673 }
674
675 return PluginRequestHandle::broadcast();
676}

Callers

nothing calls this directly

Calls 15

findFunction · 0.85
isRequestMethod · 0.80
isJSONMethod · 0.80
atMethod · 0.80
getFSPathMethod · 0.80
isStringMethod · 0.80
c_strMethod · 0.80
runOnMainThreadMethod · 0.80
containsMethod · 0.45
rowCountMethod · 0.45
dataMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected