8000 Fixing bug where native.exe --<tab> would not call native completer by powercode · Pull Request #3633 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fixing bug where native.exe --<tab> would not call native completer #3633

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 8 commits into from
Jun 7, 2017

Conversation

powercode
Copy link
Collaborator
@powercode powercode commented Apr 24, 2017

A case was missing when parsing the processing the current token. The result was that the registered argument completer for a native command was not called if the wordToComplete was '--'.

@@ -0,0 +1,72 @@
Describe TabCompletion -Tags CI {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use our common template:
Describe "TabCompletion"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

BeforeAll {
$nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name
}
It 'Completes native commands with -' {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the template more readable:
It "Completes native commands with '-'" {

Below too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

$nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name
}
It 'Completes native commands with -' {
Register-ArgumentCompleter -Native -CommandName $nativeCommand -ScriptBlock {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we don't clean up completers after each test we should move all Register-ArgumentCompleter in BeforeAll block.

else {
return 'unexpected wordtocomplete'
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove extra line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

$res.CompletionMatches.CompletionText | Should be "-option"
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add Newline at EOF.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

@@ -114,7 +114,7 @@ internal CompletionContext CreateCompletionContext(ExecutionContext executionCon
else
{
var stringExpandableToken = tokenAtCursor as StringExpandableToken;
if (stringExpandableToken != null && stringExpandableToken.NestedTokens != null)
if (stringExpandableToken?.NestedTokens != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use C# 7.0 pattern here too. It is better use common pattern in whole file.

@@ -156,7 +156,7 @@ private static bool CompleteAgainstSwitchFile(Ast lastAst, Token tokenBeforeCurs
Tuple<Token, Ast> fileConditionTuple;

var errorStatement = lastAst as ErrorStatementAst;
if (errorStatement != null && errorStatement.Flags != null && errorStatement.Kind != null && tokenBeforeCursor != null &&
if (errorStatement?.Flags != null && errorStatement.Kind != null && tokenBeforeCursor != null &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same about c# 7.0 pattern.

@@ -173,7 +173,7 @@ private static bool CompleteAgainstSwitchFile(Ast lastAst, Token tokenBeforeCurs
}

errorStatement = pipeline.Parent as ErrorStatementAst;
if (errorStatement == null || errorStatement.Kind == null || errorStatement.Flags == null)
if (errorStatement?.Kind == null || errorStatement.Flags == null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same about c# 7.0 pattern.

@@ -206,15 +206,13 @@ private static bool CompleteAgainstStatementFlags(Ast scriptAst, Ast lastAst, To

// Handle "switch -f<tab>"
var errorStatement = lastAst as ErrorStatementAst;
if (errorStatement != null && errorStatement.Kind != null)
if (errorStatement?.Kind != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same about c# 7.0 pattern.

@@ -882,7 +871,7 @@ internal static TypeName FindTypeNameToComplete(ITypeName type, IScriptPosition
var arrayTypeName = type as ArrayTypeName;
if (arrayTypeName != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same about c# 7.0 pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

@iSazonov
Copy link
Collaborator

@powercode Please add description in the PR. This can be useful for documentation.

@powercode
Copy link
Collaborator Author

@iSazonov Thanks for the review.
I've addressed your comments, except for the one about the registration of TabCompleters.
These are stored in private variables in the ExecutionContext, and as far as I know, there is no way to Unregister-ArgumentCompleter. @lzybkr ?

@iSazonov
Copy link
Collaborator

I think it's even better for tests to register several TabCompleters in BeforeAll and not remove them.

var stringExpandableToken = tokenAtCursor as StringExpandableToken;
if (stringExpandableToken != null && stringExpandableToken.NestedTokens != null)
if (tokenAtCursor is StringExpandableToken stringExpandableToken &&
stringExpandableToken.NestedTokens != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks gorgeous! 👍

I'd like to see the same everywhere below. Now there are too many use cases for "as" and "?"

var errorStatement = lastAst as ErrorStatementAst;
if (errorStatement != null && errorStatement.Flags != null && errorStatement.Kind != null && tokenBeforeCursor != null &&
errorStatement.Kind.Kind.Equals(TokenKind.Switch) && errorStatement.Flags.TryGetValue("file", out fileConditionTuple))
if (errorStatement?.Flags != null && errorStatement.Kind != null && tokenBeforeCursor != null &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

For information only. Personally I do not like to use "?" in if(). Expanded condition looks much clearer.

else {
return "unexpected wordtocomplete"
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove extra line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

else {
return "unexpected wordtocomplete"
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove extra line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Closed.

F438
Staffan Gustafsson added 6 commits April 25, 2017 08:30
@powercode
Copy link
Collaborator Author

Rebased master and fixed conflicting test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1

Copy link
Contributor
@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

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

Would it be unreasonable to ask for logic code changes only?

The C# 7 language usage is nice, but I'd rather see those sorts of changes in a distinct PR.

@iSazonov
Copy link
Collaborator

Sometimes mantainers aren't predictable - I just asked what I was getting myself.

10000

@lzybkr
Copy link
Contributor
lzybkr commented May 23, 2017

Sometimes people aren't predictable.

PowerShell is no longer my full time job - so when I ask for something like this, it's to make things easier for me. It's already somewhat hard to keep up as a maintainer with an unrelated full time job and non-computer related responsibilities and hobbies.

If you could see our pre-GitHub history, you would certainly see that I've been guilty of changes like this, but I blame not having a good enough VCS to make it easier. So I have plenty of personal experience with the difficulties of looking at changes that mix style and logical changes - and I do think a cleaner and easier to understand history is valuable in the long run, even if it wasn't painful to review something like this in the short term.

@iSazonov
Copy link
Collaborator

I meant that often we contribute and discuss before the appointment of mantainer and before his posts - so we can not predict a review style and facilitate the mantainer's work.
I believe our workflow process could be improved, I guess we could take more from the CoreCLR/CoreFX workflows.
/cc @joeyaiello

@lzybkr
Copy link
Contributor
lzybkr commented May 24, 2017

Note that CoreFX says this:

DO NOT send PRs for upgrading code to use newer language features, though it's ok to use newer language features as part of new code that's written.

See here.

@iSazonov
Copy link
Collaborator

Yes, they were more clearly writing the workflow. We have to do the same.

@lzybkr
Copy link
Contributor
lzybkr commented Jun 7, 2017

:shipit:


Context NativeCommand {
BeforeAll {
$nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be wiser to create an external command on testdrive and change the path, but that's a tiny bit annoying to make it portable, so I'll merge as is.

@lzybkr lzybkr merged commit 3125764 into PowerShell:master Jun 7, 2017
@powercode powercode deleted the native-arg-hyphen branch January 26, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0