Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach CommandPalette to persist recent command lines #11030

Merged
7 commits merged into from
Aug 26, 2021

Conversation

Don-Vito
Copy link
Contributor

@Don-Vito Don-Vito commented Aug 24, 2021

Closes #11026

@ghost ghost added Area-CmdPal Command Palette issues and features Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Aug 24, 2021
@Rosefield
Copy link
Contributor

Going to hit some merge conflicts with #10972 but I suspect you'll win the race to be on main first.

@Don-Vito
Copy link
Contributor Author

Going to hit some merge conflicts with #10972 but I suspect you'll win the race to be on main first.

Not sure I will get there earlier, but if required would love to assist with the merge 😊

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

Let me know what you think about my comments.
Your PR looks excellent. 🙂

src/cascadia/TerminalApp/CommandPalette.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CommandPalette.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CommandPalette.cpp Outdated Show resolved Hide resolved
@Don-Vito
Copy link
Contributor Author

Let me know what you think about my comments.
Your PR looks excellent. 🙂

Thanks a lot for the comments! They are great as usual!

@Don-Vito Don-Vito requested a review from lhecker August 25, 2021 17:35
Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

I still disagree about the implementation of CommandPalette::_updateRecentCommands. It's rather long and complex whereas the previous solution was only 3 LOC and certainly faster.
But it's not incorrect code, so I'll let others chime in and approve it in the meantime.

@Don-Vito Don-Vito requested a review from lhecker August 25, 2021 18:30
@Rosefield
Copy link
Contributor

My approval doesn't mean anything but it looks good to me 👍

@Don-Vito
Copy link
Contributor Author

My approval doesn't mean anything but it looks good to me 👍

Thanks for helping with this one!

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Okay so on load, we'll load the recent commands from state.json. When a command is run, we'll update state.json with our list of recent commands. So

  • Window 1 loads ["foo", "bar"]
  • Window 1 runs "baz" (state is now ["foo", "bar", "baz"])
  • Window 2 loads ["foo", "bar", "baz"]
  • Window 1 runs "boo" (state is now ["foo", "bar", "baz", "boo"])
  • Window 2 runs "asdf" (state is now ["foo", "bar", "baz", "asdf"])
  • Window 1 runs "qwer" (state is now ["foo", "bar", "baz", "boo", "qwer"])

that seems right to me. Thanks for doing this! This is a cool feature to have land.

@@ -55,6 +55,48 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
return fmt::format("{}[]", ConversionTrait<GUID>{}.TypeDescription());
}
};

template<typename T>
struct ConversionTrait<winrt::Windows::Foundation::Collections::IVector<T>>
Copy link
Member

Choose a reason for hiding this comment

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

everybody's writing this exact same converter this week, aren't they 😝

@DHowett
Copy link
Member

DHowett commented Aug 26, 2021

You know, I think it's different still: state is part of the reload trigger, so Window 2 will pick up boo and add asdf, and then Window 1 will pick up asdf and add qwer

@zadjii-msft
Copy link
Member

state is part of the reload trigger,

AH okay, didn't know that

@Don-Vito
Copy link
Contributor Author

  • Window 1 loads ["foo", "bar"]
  • Window 1 runs "baz" (state is now ["foo", "bar", "baz"])
  • Window 2 loads ["foo", "bar", "baz"]
  • Window 1 runs "boo" (state is now ["foo", "bar", "baz", "boo"])
  • Window 2 runs "asdf" (state is now ["foo", "bar", "baz", "boo", "asdf"]) - hopefully due to reload, if the time is more than a second
  • Window 1 runs "qwer" (state is now ["foo", "bar", "baz", "boo", "asdf", "qwer"]) - same here

@Rosefield
Copy link
Contributor

state is part of the reload trigger

Does that mean all of settings is reloaded each time the command palette is opened/closed?

@Don-Vito
Copy link
Contributor Author

state is part of the reload trigger

Does that mean all of settings is reloaded each time the command palette is opened/closed?

From my understanding no. It is reloaded when the state file changes (with a throttling of 1 sec).

@Rosefield
Copy link
Contributor

That makes more sense. For a moment I was thinking that if state was changed, then settings was also refreshed. I knew about the throttling on loading the ApplicationState.

@@ -744,15 +739,14 @@ namespace winrt::TerminalApp::implementation
}
}

std::optional<winrt::TerminalApp::FilteredCommand> CommandPalette::_buildCommandLineCommand(std::wstring const& commandLine)
std::optional<TerminalApp::FilteredCommand> CommandPalette::_buildCommandLineCommand(const hstring& commandLine)
{
if (commandLine.empty())
{
return std::nullopt;
Copy link
Member

Choose a reason for hiding this comment

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

Huh, I just realized this. A FilteredCommand is already nullable, because it is a smart pointer type. Is there value that we get out of using nullopt (which would mean "not null, and also not populated" to provide a third state?

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Aug 26, 2021
@ghost
Copy link

ghost commented Aug 26, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 7112f4e into microsoft:main Aug 26, 2021
@lhecker
Copy link
Member

lhecker commented Aug 26, 2021

I wish there was a way to let other instances know that the state changed without actually writing the state file to disk. We currently write the state to disk up to once a second. It's fine compared to other applications, but I wish there was another way, like telling the OS "no you really don't need to flush this file to disk right away".

ghost pushed a commit that referenced this pull request Aug 31, 2021
The first time you open commandline mode, `recentCommands` doesn't exist yet. However, we immediately try to read the `Size()` in a couple places. This'll A/V and we'll crash 😨 

The fix is easy - don't try and read the size of the non-existent `recentCommands`

Found this while playing with #11069
Regressed in #11030 
Didn't bother filing an issue for it when I have the fix in hand
@ghost
Copy link

ghost commented Oct 20, 2021

🎉Windows Terminal Preview v1.12.2922.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CmdPal Command Palette issues and features AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: Command palette commandline mode should store history in ApplicationState
5 participants