-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[cmdpal] Port v1 calculator extension #38629
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d01957b
init
cadd264
update
a24051e
Remove duplicated cp command
1e03e32
Change the long desc
2fe9da8
Update notice.md
c9c5d8b
Use the same icon for fallback item
70b042e
Add Rappl to expect list
f1ca6de
update notice.md
6a68f44
Merge branch 'main' into yuleng/cmdpal/portV1cal
ccd997f
Move the original order back.
b08eda9
Make Radians become default choice
9ff5713
Fix empty result
2a6ffa1
Remove unused settings.
4b7a942
fix typo
b705457
Merge branch 'main' into yuleng/cmdpal/portV1cal
c1706ef
merge main
718d2cd
CmdPal: minor calc updates (#38914)
zadjii-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1295,6 +1295,7 @@ QUNS | |
| QXZ | ||
| RAII | ||
| RAlt | ||
| Rappl | ||
| randi | ||
| Rasterization | ||
| Rasterize | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/BracketHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright (c) Microsoft Corporation | ||
| // The Microsoft Corporation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.CmdPal.Ext.Calc.Helper; | ||
|
|
||
| public static class BracketHelper | ||
| { | ||
| public static bool IsBracketComplete(string query) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(query)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| var valueTuples = query | ||
| .Select(BracketTrail) | ||
| .Where(r => r != default); | ||
|
|
||
| var trailTest = new Stack<TrailType>(); | ||
|
|
||
| foreach (var (direction, type) in valueTuples) | ||
| { | ||
| switch (direction) | ||
| { | ||
| case TrailDirection.Open: | ||
| trailTest.Push(type); | ||
| break; | ||
| case TrailDirection.Close: | ||
| // Try to get item out of stack | ||
| if (!trailTest.TryPop(out var popped)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (type != popped) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| continue; | ||
| default: | ||
| { | ||
| throw new ArgumentOutOfRangeException($"Can't process value (Parameter direction: {direction})"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return trailTest.Count == 0; | ||
| } | ||
|
|
||
| private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char) | ||
| { | ||
| switch (@char) | ||
| { | ||
| case '(': | ||
| return (TrailDirection.Open, TrailType.Round); | ||
| case ')': | ||
| return (TrailDirection.Close, TrailType.Round); | ||
| case '[': | ||
| return (TrailDirection.Open, TrailType.Bracket); | ||
| case ']': | ||
| return (TrailDirection.Close, TrailType.Bracket); | ||
| default: | ||
| return default; | ||
| } | ||
| } | ||
|
|
||
| private enum TrailDirection | ||
| { | ||
| None, | ||
| Open, | ||
| Close, | ||
| } | ||
|
|
||
| private enum TrailType | ||
| { | ||
| None, | ||
| Bracket, | ||
| Round, | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.