Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/ActionMap.cpp (C++)

Code before:

        // This returns an empty string if we fail to load the file.
        auto localTasksFileContents = CascadiaSettings::ReadFile(currentWorkingDirectory + L"\\.wt.json");
        if (!localTasksFileContents.empty())
        {
            auto data = winrt::to_string(localTasksFileContents);
            std::string errs;
            static std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder::CharReaderBuilder().newCharReader() };
            Json::Value root;
            if (!reader->parse(data.data(), data.data() + data.size(), &root, &errs))
            {
                // In the real settings parser, we'd throw here:
                // throw winrt::hresult_error(WEB_E_INVALID_JSON_STRING, winrt::to_hstring(errs));
                //
                // That seems overly aggressive for something that we don't
                // really own. Instead, just bail out.
                co_return;
            }

            auto result = std::vector<Model::Command>();
            if (auto actions{ root[JsonKey("actions")] })
            {
                std::vector<SettingsLoadWarnings> warnings;
                for (const auto& json : actions)
                {
                    auto parsed = Command::FromJson(json, warnings, OriginTag::Generated);
                    // Skip over things that aren't snippets
                    if (parsed->ActionAndArgs().Action() != ShortcutAction::SendInput)
                    {
                        continue;
                    }

                    result.push_back(*parsed);
                }
            }

            _cwdLocalSnippetsCache.insert_or_assign(currentWorkingDirectory, result);
        }

        // Now at the bottom, we've either found a file successfully parsed it,
        // and updated the _cwdLocalSnippetsCache. Or we failed at some point,
        // and then it doesn't really matter.
        co_return;
    }

    winrt::Windows::Foundation::IAsyncOperation<IVector<Model::Command>> ActionMap::FilterToSnippets(
        winrt::hstring currentCommandline,
        winrt::hstring currentWorkingDirectory)
    {
        // Check if there are any cached commands in this directory.
        // If there aren't, then we'll try to look for any commands in this

Review comment (suggestion):
```suggestion
                    const auto parsed = Command::FromJson(json, warnings, OriginTag::Generated);
```

Code after:
        newAction.Args(sendInputArgs);
        auto cmd{ make_self<Command>() };
        if (!name.empty())
        {
            cmd->Name(name);
        }
        cmd->ActionAndArgs(newAction);
        cmd->GenerateID();
        AddAction(*cmd, keys);
    }

    // Update ActionMap's cache of actions for this directory. We'll look for a
    // .wt.json in this directory. If it exists, we'll read it, parse it's JSON,
    // then take all the sendInput actions in it and store them in our
    // _cwdLocalSnippetsCache
    std::vector<Model::Command> ActionMap::_updateLocalSnippetCache(winrt::hstring currentWorkingDirectory)
    {
        // This returns an empty string if we fail to load the file.
        std::filesystem::path localSnippetsPath{ std::wstring_view{ currentWorkingDirectory + L"\\.wt.json" } };
        const auto localTasksFileContents = til::io::read_file_as_utf8_string_if_exists(localSnippetsPath);
        if (!localTasksFileContents.has_value() || localTasksFileContents->empty())
        {
            return {};
        }

        const auto& data = *localTasksFileContents;
        Json::Value root;
        std::string errs;
        const std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder{}.newCharReader() };
        if (!reader->parse(data.data(), data.data() + data.size(), &root, &errs))
        {
            // In the real settings parser, we'd throw here:
            // throw winrt::hresult_error(WEB_E_INVALID_JSON_STRING, winrt::to_hstring(errs));
            //
            // That seems overly aggressive for something that we don't
            // really own. Instead, just bail out.
            return {};
        }

        auto result = std::vector<Model::Command>();
        if (auto actions{ root[JsonKey("snippets")] })
        {
            for (const auto& json : actions)
            {
                result.push_back(*Command::FromSnippetJson(json));
            }
        }
        return result;
    }

    winrt::Windows::Foundation::IAsyncOperation<IVector<Model::Command>> ActionMap::FilterToSnippets(