Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Remove duplicate modules from completion results#25538

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iSazonov merged 3 commits intoPowerShell:masterfromMartinGC94:SkipDuplicateModules2
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -499,11 +499,16 @@ internal static List<CompletionResult> CompleteModuleName(CompletionContext cont
nestedModulesToFilterOut = new(currentModule.NestedModules);
}

var completedModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (PSObject item in psObjects)
{
var moduleInfo = (PSModuleInfo)item.BaseObject;
var completionText = moduleInfo.Name;
var listItemText = completionText;
if (!completedModules.Add(completionText))
{
continue;
}

if (shortNameSearch
&& completionText.Contains('.')
&& !shortNamePattern.IsMatch(completionText.Substring(completionText.LastIndexOf('.') + 1))
Expand All@@ -524,6 +529,7 @@ internal static List<CompletionResult> CompleteModuleName(CompletionContext cont
+ moduleInfo.ModuleType.ToString() + "\r\nPath: "
+ moduleInfo.Path;

string listItemText = completionText;
completionText = CompletionHelpers.QuoteCompletionText(completionText, quote);

result.Add(new CompletionResult(completionText, listItemText, CompletionResultType.ParameterValue, toolTip));
Expand Down
39 changes: 34 additions & 5 deletionstest/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,13 +36,13 @@ Describe "TabCompletion" -Tags CI {
It 'Should not include duplicate command results' {
$OldModulePath = $env:PSModulePath
$tempDir = Join-Path -Path $TestDrive -ChildPath "TempPsModuleDir"
$ModuleDirs = @(
Join-Path $tempDir "TestModule1\1.0"
Join-Path $tempDir "TestModule1\1.1"
Join-Path $tempDir "TestModule2\1.0"
)
try
{
$ModuleDirs = @(
Join-Path $tempDir "TestModule1\1.0"
Join-Path $tempDir "TestModule1\1.1"
Join-Path $tempDir "TestModule2\1.0"
)
foreach ($Dir in $ModuleDirs)
{
$NewDir = New-Item -Path $Dir -ItemType Directory -Force
Expand All@@ -61,9 +61,38 @@ Describe "TabCompletion" -Tags CI {
finally
{
$env:PSModulePath = $OldModulePath
Remove-Item -LiteralPath $ModuleDirs -Recurse -Force
}
}

It 'Should not include duplicate module results' {
$OldModulePath = $env:PSModulePath
$tempDir = Join-Path -Path $TestDrive -ChildPath "TempPsModuleDir"
try
{
$ModuleDirs = @(
Join-Path $tempDir "TestModule1\1.0"
Join-Path $tempDir "TestModule1\1.1"
)
foreach ($Dir in $ModuleDirs)
{
$NewDir = New-Item -Path $Dir -ItemType Directory -Force
$ModuleName = $NewDir.Parent.Name
Set-Content -Value 'MyTestFunction{}' -LiteralPath "$($NewDir.FullName)\$ModuleName.psm1"
New-ModuleManifest -Path "$($NewDir.FullName)\$ModuleName.psd1" -RootModule "$ModuleName.psm1" -FunctionsToExport "MyTestFunction" -ModuleVersion $NewDir.Name
}

$env:PSModulePath += [System.IO.Path]::PathSeparator + $tempDir
$Res = TabExpansion2 -inputScript 'Import-Module -Name TestModule'
$Res.CompletionMatches.Count | Should -Be 1
$Res.CompletionMatches[0].CompletionText | Should -Be TestModule1
}
finally
{
$env:PSModulePath = $OldModulePath
Remove-Item -LiteralPath $ModuleDirs -Recurse -Force
}

It 'Should complete dotnet method' {
$res = TabExpansion2 -inputScript '(1).ToSt' -cursorColumn '(1).ToSt'.Length
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'ToString('
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp