Skip to content

Commit

Permalink
smaller refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 2, 2024
1 parent bba8aac commit 5a029f0
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 35 deletions.
24 changes: 1 addition & 23 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ namespace winrt::TerminalApp::implementation
// their settings file. Ask the ActionMap for those.
if (WI_IsFlagSet(source, SuggestionsSource::Tasks))
{
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSnippets(currentCommandline, currentWorkingDirectory);
const auto tasks = co_await _settings.GlobalSettings().ActionMap().FilterToSnippets(currentCommandline, currentWorkingDirectory);
for (const auto& t : tasks)
{
commandsCollection.push_back(t);
Expand All @@ -1391,28 +1391,6 @@ namespace winrt::TerminalApp::implementation
}
}

// if (WI_IsFlagSet(source, SuggestionsSource::Local) &&
// context != nullptr)
// {
// // TODO! this is wack. CurrentWorkingDirectory should be it's own
// // property, or a property of ControlCore.DirectoryHistory() or
// // something. I only have 5 minutes to pch tho so garbage will do
// auto cwd = context.CurrentWorkingDirectory();// strongControl.CommandHistory().CurrentWorkingDirectory();
// if (!cwd.empty())
// {
// co_await winrt::resume_background();
// auto localTasksFileContents = CascadiaSettings::ReadFile(cwd + L"\\.wt.json");
// if (!localTasksFileContents.empty())
// {
// const auto localCommands = Command::ParseLocalCommands(localTasksFileContents);
// for (const auto& t : localCommands)
// {
// commandsCollection.push_back(t);
// }
// }
// }
// }

co_await wil::resume_foreground(Dispatcher());

// Open the palette with all these commands in it.
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ namespace Microsoft.Terminal.Settings.Model
Tasks = 0x1,
CommandHistory = 0x2,
DirectoryHistory = 0x4,
Local = 0x8,
All = 0xffffffff,
};

Expand Down
12 changes: 6 additions & 6 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
winrt::hstring currentCommandline,
winrt::hstring currentWorkingDirectory)
{
auto results = winrt::single_threaded_vector<Model::Command>();
std::vector<Model::Command> results{};

const auto numBackspaces = currentCommandline.size();
// Helper to clone a sendInput command into a new Command, with the
Expand Down Expand Up @@ -860,7 +860,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
command.ActionAndArgs().Action() == ShortcutAction::SendInput)
{
// copy it into the results.
results.Append(createInputAction(command));
results.push_back(createInputAction(command));
}
// If this is nested...
else if (command.HasNestedCommands())
Expand All @@ -879,15 +879,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto copy = cmdImpl->Copy();
copy->NestedCommands(innerResults.GetView());

results.Append(*copy);
results.push_back(*copy);
}
}
}

return results;
return winrt::single_threaded_vector<Model::Command>(std::move(results));
}

IVector<Model::Command> ActionMap::FilterToSnippets(
winrt::Windows::Foundation::IAsyncOperation<IVector<Model::Command>> ActionMap::FilterToSnippets(
winrt::hstring currentCommandline,
winrt::hstring currentWorkingDirectory)
{
Expand Down Expand Up @@ -944,6 +944,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}

return results;
co_return results;
}
}
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/ActionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void ExpandCommands(const Windows::Foundation::Collections::IVectorView<Model::Profile>& profiles,
const Windows::Foundation::Collections::IMapView<winrt::hstring, Model::ColorScheme>& schemes);

winrt::Windows::Foundation::Collections::IVector<Model::Command> FilterToSnippets(winrt::hstring currentCommandline, winrt::hstring currentWorkingDirectory);
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Foundation::Collections::IVector<Model::Command>> FilterToSnippets(winrt::hstring currentCommandline, winrt::hstring currentWorkingDirectory);

private:
Model::Command _GetActionByID(const winrt::hstring actionID) const;
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/ActionMap.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Terminal.Settings.Model

IVector<Command> ExpandedCommands { get; };

IVector<Command> FilterToSnippets(String CurrentCommandline, String CurrentWorkingDirectory);
Windows.Foundation.IAsyncOperation<IVector<Command> > FilterToSnippets(String CurrentCommandline, String CurrentWorkingDirectory);
};

[default_interface] runtimeclass ActionMap : IActionMapView
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsModel/Command.idl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ namespace Microsoft.Terminal.Settings.Model

static IVector<Command> ParsePowerShellMenuComplete(String json, Int32 replaceLength);
static IVector<Command> HistoryToCommands(IVector<String> commandHistory, String commandline, Boolean directories);
static IVector<Command> ParseLocalCommands(String localTasksFileContents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,12 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FindMatchDirecti

JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SuggestionsSource)
{
static constexpr std::array<pair_type, 7> mappings = {
static constexpr std::array<pair_type, 6> mappings = {
pair_type{ "none", AllClear },
pair_type{ "tasks", ValueType::Tasks },
pair_type{ "snippets", ValueType::Tasks },
pair_type{ "commandHistory", ValueType::CommandHistory },
pair_type{ "directoryHistory", ValueType::DirectoryHistory },
pair_type{ "local", ValueType::Local },
pair_type{ "all", AllSet },
};
};
Expand Down

0 comments on commit 5a029f0

Please sign in to comment.