Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7168,7 +7168,7 @@ internal static List<CompletionResult> CompleteHashtableKey(CompletionContext co
switch (binding.CommandName)
{
case "Get-WinEvent":
return GetSpecialHashTableKeyMembers(excludedKeys, wordToComplete, "LogName", "ProviderName", "Path", "Keywords", "ID", "Level",
return GetSpecialHashTableKeyMembers(excludedKeys, wordToComplete, "LogName", "ProviderName", "Path", "Keywords", "ID", "Level",
"StartTime", "EndTime", "UserID", "Data", "SuppressHashFilter");
}
}
Expand Down Expand Up @@ -7298,32 +7298,40 @@ internal static bool IsPathSafelyExpandable(ExpandableStringExpressionAst expand
internal static string CombineVariableWithPartialPath(VariableExpressionAst variableAst, string extraText, ExecutionContext executionContext)
{
var varPath = variableAst.VariablePath;
if (varPath.IsVariable || varPath.DriveName.Equals("env", StringComparison.OrdinalIgnoreCase))
if (!varPath.IsVariable && !varPath.DriveName.Equals("env", StringComparison.OrdinalIgnoreCase))
{
try
{
// We check the strict mode inside GetVariableValue
object value = VariableOps.GetVariableValue(varPath, executionContext, variableAst);
var strValue = (value == null) ? string.Empty : value as string;
return null;
}

if (strValue == null)
{
object baseObj = PSObject.Base(value);
if (baseObj is string || baseObj.GetType().IsPrimitive)
{
strValue = LanguagePrimitives.ConvertTo<string>(value);
}
}
if (varPath.UnqualifiedPath.Equals(SpecialVariables.PSScriptRoot, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrEmpty(variableAst.Extent.File))
{
return Path.GetDirectoryName(variableAst.Extent.File) + extraText;
}

if (strValue != null)
try
{
// We check the strict mode inside GetVariableValue
object value = VariableOps.GetVariableValue(varPath, executionContext, variableAst);
var strValue = (value == null) ? string.Empty : value as string;

if (strValue == null)
{
object baseObj = PSObject.Base(value);
if (baseObj is string || baseObj?.GetType()?.IsPrimitive is true)
{
return strValue + extraText;
strValue = LanguagePrimitives.ConvertTo<string>(value);
}
}
catch (Exception)

if (strValue != null)
{
return strValue + extraText;
}
}
catch (Exception)
{
}

return null;
}
Expand Down
20 changes: 20 additions & 0 deletions 20 test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,26 @@ switch ($x)
$expected = ($expected | Sort-Object -CaseSensitive | ForEach-Object { "./$_" }) -join ":"

}

It "PSScriptRoot path completion when AST extent has file identity" {
$scriptText = '"$PSScriptRoot\BugFix.Tests"'
$tokens = $null
$scriptAst = [System.Management.Automation.Language.Parser]::ParseInput(
$scriptText,
$PSCommandPath,
[ref] $tokens,
[ref] $null)

$cursorPosition = $scriptAst.Extent.StartScriptPosition.
GetType().
GetMethod('CloneWithNewOffset', [System.Reflection.BindingFlags]'NonPublic, Instance').
Invoke($scriptAst.Extent.StartScriptPosition, @($scriptText.Length - 1))

$res = TabExpansion2 -ast $scriptAst -tokens $tokens -positionOfCursor $cursorPosition
$res.CompletionMatches | Should -HaveCount 1
$expectedPath = Join-Path $PSScriptRoot -ChildPath BugFix.Tests.ps1
$res.CompletionMatches[0].CompletionText | Should -Be "`"$expectedPath`""
}
}

Context "Cmdlet name completion" {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.