-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Conversation
@@ -0,0 +1,72 @@ | |||
Describe TabCompletion -Tags CI { |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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 -' { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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' | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra line.
There was a problem hiding this comment.
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" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
@powercode Please add description in the PR. This can be useful for documentation. |
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) |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
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" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra line.
There was a problem hiding this comment.
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" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
from tokenAtCursor.Text.
Addressing review comments by iSazonov
d88a7d5
to
2727ca9
Compare
Rebased master and fixed conflicting test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 |
There was a problem hiding this 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.
Sometimes mantainers aren't predictable - I just asked what I was getting myself. |
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. |
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. |
Note that CoreFX says this:
See here. |
Yes, they were more clearly writing the workflow. We have to do the same. |
|
|
||
Context NativeCommand { | ||
BeforeAll { | ||
$nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name |
There was a problem hiding this comment.
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.
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 '--'.