LCOV - code coverage report
Current view: top level - muse/framework/extensions - extensionscommands.h Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 20 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2026 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #pragma once
      23              : 
      24              : #include "rcommand/commandtypes.h"
      25              : #include "extensionstypes.h"
      26              : 
      27              : namespace muse::extensions {
      28              : inline static const muse::rcommand::Command OPEN_APIDUMP_COMMAND("command://extensions/open-apidump");
      29              : 
      30            0 : inline rcommand::Command makeCommand(const ExtensionUri& extensionUri, const ExtensionActionCode& action)
      31              : {
      32              :     // extension://some/uri + action -> command://extension/some/uri/action
      33            0 :     rcommand::Command c;
      34            0 :     c.setScheme(std::string(rcommand::COMMAND_SCHEME));
      35            0 :     c.addPath(std::string(EXTENSION_SCHEME)); // scheme as first segment of path
      36            0 :     c.addPath(extensionUri.path());
      37            0 :     c.addPath(action);
      38            0 :     return c;
      39            0 : }
      40              : 
      41            0 : inline ExtensionUri extensionUriByCommand(const rcommand::Command& c)
      42              : {
      43              :     // command://extension/some/uri/action -> extension://some/uri
      44              : 
      45            0 :     std::vector<std::string> segments = c.pathSegments();
      46            0 :     IF_ASSERT_FAILED(segments.size() >= 3) {
      47            0 :         return ExtensionUri();
      48              :     }
      49            0 :     IF_ASSERT_FAILED(segments.at(0) == std::string(EXTENSION_SCHEME)) {
      50            0 :         return ExtensionUri();
      51              :     }
      52              : 
      53            0 :     ExtensionUri uri;
      54            0 :     uri.setScheme(std::string(EXTENSION_SCHEME));
      55            0 :     for (size_t i = 1 /* skip extension */; i < (segments.size() - 1 /* skip action */); ++i) {
      56            0 :         uri.addPath(segments.at(i));
      57              :     }
      58            0 :     return uri;
      59            0 : }
      60              : 
      61              : inline ExtensionActionCode actionByCommand(const rcommand::Command& c)
      62              : {
      63              :     // command://extension/some/uri/action -> action
      64              :     std::vector<std::string> segments = c.pathSegments();
      65              :     IF_ASSERT_FAILED(segments.size() >= 3) {
      66              :         return {};
      67              :     }
      68              :     return segments.at(segments.size() - 1);
      69              : }
      70              : }
        

Generated by: LCOV version 2.0-1