Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 2, 2024
1 parent 091797c commit 3aa5b4b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 39 deletions.
24 changes: 12 additions & 12 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ namespace winrt::TerminalApp::implementation
if (const auto& realArgs = args.ActionArgs().try_as<SuggestionsArgs>())
{
_doHandleSuggestions(realArgs);

args.Handled(true);
}
}
Expand All @@ -1349,20 +1349,21 @@ namespace winrt::TerminalApp::implementation
// OR they wanted command history (or some other source that
// requires context from the control)
// then get that here.
// const bool shouldGetContext = realArgs.UseCommandline() ||
// WI_IsAnyFlagSet(source, SuggestionsSource::CommandHistory | SuggestionsSource::Local);
// if (shouldGetContext)
// {
if (const auto& control{ _GetActiveControl() })
const bool shouldGetContext = realArgs.UseCommandline() ||
WI_IsAnyFlagSet(source, SuggestionsSource::CommandHistory);
if (const auto& control{ _GetActiveControl() })
{
currentWorkingDirectory = control.CurrentWorkingDirectory();

if (shouldGetContext)
{
context = control.CommandHistory();
if (context)
{
currentCommandline = context.CurrentCommandline();
currentWorkingDirectory = context.CurrentWorkingDirectory();
}
}
// }
}

// Aggregate all the commands from the different sources that
// the user selected.
Expand Down Expand Up @@ -1395,10 +1396,9 @@ namespace winrt::TerminalApp::implementation

// Open the palette with all these commands in it.
_OpenSuggestions(_GetActiveControl(),
winrt::single_threaded_vector<Command>(std::move(commandsCollection)),
SuggestionsMode::Palette,
currentCommandline);

winrt::single_threaded_vector<Command>(std::move(commandsCollection)),
SuggestionsMode::Palette,
currentCommandline);
}

void TerminalPage::_HandleColorSelection(const IInspectable& /*sender*/,
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,11 +2269,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto context = winrt::make_self<CommandHistoryContext>(std::move(commands));
context->CurrentCommandline(trimmedCurrentCommand);

context->CurrentWorkingDirectory(winrt::hstring{ _terminal->GetWorkingDirectory() });

return *context;
}

winrt::hstring ControlCore::CurrentWorkingDirectory() const
{
return winrt::hstring{ _terminal->GetWorkingDirectory() };
}

Core::Scheme ControlCore::ColorScheme() const noexcept
{
Core::Scheme s;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void ContextMenuSelectCommand();
void ContextMenuSelectOutput();

winrt::hstring CurrentWorkingDirectory() const;
#pragma endregion

#pragma region ITerminalInput
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace Microsoft.Terminal.Control
{
IVector<String> History { get; };
String CurrentCommandline { get; };
String CurrentWorkingDirectory { get; };
};

[default_interface] runtimeclass ControlCore : ICoreState
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ICoreState.idl
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ namespace Microsoft.Terminal.Control
void SelectOutput(Boolean goUp);
IVector<ScrollMark> ScrollMarks { get; };

String CurrentWorkingDirectory { get; };

};
}
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3548,6 +3548,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _core.CommandHistory();
}
winrt::hstring TermControl::CurrentWorkingDirectory() const
{
return _core.CurrentWorkingDirectory();
}

Core::Scheme TermControl::ColorScheme() const noexcept
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void SelectCommand(const bool goUp);
void SelectOutput(const bool goUp);

winrt::hstring CurrentWorkingDirectory() const;
#pragma endregion

void ScrollViewport(int viewTop);
Expand Down
42 changes: 21 additions & 21 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

#pragma region Snippets
std::vector<Model::Command> _filterToSnippets(IMapView<hstring, Model::Command> nameMap,
winrt::hstring currentCommandline,
const std::vector<Model::Command>& localCommands)
winrt::hstring currentCommandline,
const std::vector<Model::Command>& localCommands)
{
std::vector<Model::Command> results{};

Expand All @@ -853,10 +853,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return *copy;
};

// Helper to copy this command into a snippet-styled command, and any
// Helper to copy this command into a snippet-styled command, and any
// nested commands
const auto addCommand = [&](auto& command)
{
const auto addCommand = [&](auto& command) {
// If this is not a nested command, and it's a sendInput command...
if (!command.HasNestedCommands() &&
command.ActionAndArgs().Action() == ShortcutAction::SendInput)
Expand Down Expand Up @@ -893,7 +892,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
addCommand(command);
}
// ... and all the local commands passed in here
for (const auto& command : localCommands) {
for (const auto& command : localCommands)
{
addCommand(command);
}

Expand All @@ -902,14 +902,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

// 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
// then take all the sendInput actions in it and store them in our
// _cwdLocalSnippetsCache
winrt::Windows::Foundation::IAsyncAction ActionMap::_updateLocalSnippetCache(winrt::hstring currentWorkingDirectory)
{
// Don't do I/O on the main thread, duh
co_await winrt::resume_background();

// This returns an empty string if we fail to load the file.
// This returns an empty string if we fail to load the file.
auto localTasksFileContents = CascadiaSettings::ReadFile(currentWorkingDirectory + L"\\.wt.json");
if (!localTasksFileContents.empty())
{
Expand All @@ -922,11 +922,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// 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 agressive for something that we don't
// really own. Instead, just bail out.
// That seems overly agressive 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")] })
{
Expand All @@ -939,27 +939,27 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
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.
// 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
// dir's .wt.json
// 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
// dir's .wt.json
auto cachedCwdCommands = _cwdLocalSnippetsCache.find(currentWorkingDirectory);
if (cachedCwdCommands == _cwdLocalSnippetsCache.end())
{
Expand All @@ -968,9 +968,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
cachedCwdCommands = _cwdLocalSnippetsCache.find(currentWorkingDirectory);
}

auto cachedCommands = cachedCwdCommands != _cwdLocalSnippetsCache.end() ?
cachedCwdCommands->second :
std::vector<Model::Command>{};
auto cachedCommands = cachedCwdCommands != _cwdLocalSnippetsCache.end() ?
cachedCwdCommands->second :
std::vector<Model::Command>{};

co_return winrt::single_threaded_vector<Model::Command>(_filterToSnippets(NameMap(), currentCommandline, cachedCommands));
}
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsModel/ActionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

void _TryUpdateActionMap(const Model::Command& cmd);
void _TryUpdateKeyChord(const Model::Command& cmd, const Control::KeyChord& keys);
winrt::Windows::Foundation::IAsyncAction _updateLocalSnippetCache(winrt::hstring currentWorkingDirectory);

winrt::Windows::Foundation::IAsyncAction _updateLocalSnippetCache(winrt::hstring currentWorkingDirectory);

Windows::Foundation::Collections::IMap<hstring, Model::ActionAndArgs> _AvailableActionsCache{ nullptr };
Windows::Foundation::Collections::IMap<hstring, Model::Command> _NameMapCache{ nullptr };
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
throw winrt::hresult_error(WEB_E_INVALID_JSON_STRING, winrt::to_hstring(errs));
}

auto result = std::vector<Model::Command>();
if (auto actions{ root[JsonKey("actions")] })
{
Expand Down

1 comment on commit 3aa5b4b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (5)

agressive
apikey
duh
projectttttttttttttttttt
Unregistering

Previously acknowledged words that are now absent CRLFs Redir unregistering wcsicmp 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/migrie/f/local-snippets-cleaner branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https:/microsoft/terminal/actions/runs/9335035141/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2207) from .github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt
.github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (5)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (1)

See the 📜action log or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 3

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.