Skip to content

Commit

Permalink
Merge pull request #65 from abgox/module
Browse files Browse the repository at this point in the history
fix(module): 更新版本 5.3.2
  • Loading branch information
abgox authored Jan 10, 2025
2 parents 4beb3be + d0cf056 commit 8452381
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 108 deletions.
7 changes: 7 additions & 0 deletions module/CHANGELOG-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<a href="./CHANGELOG-CN.md">简体中文</a>
</p>

## 5.3.2 (2025/1/10)

- 优化了补全过滤。
-`$PSCompletions` 中添加了部分属性供 `hooks` 使用,以提升解析速度。
- 修复了后台作业可能导致补全报错的问题。
- 其他修复与优化。

## 5.3.1 (2025/1/5)

- 修复了当选项补全已使用,在下次补全时没有被过滤掉的问题。
Expand Down
19 changes: 19 additions & 0 deletions module/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[
{
"version": "5.3.2",
"info": {
"zh-CN": [
"更新(2025/1/10)\n",
"- 优化了补全过滤。\n",
"- 在 $PSCompletions 中添加了部分属性供 hooks 使用,以提升解析速度。\n",
"- 修复了后台作业可能导致补全报错的问题。\n",
"- 其他修复与优化。\n"
],
"en-US": [
"Update(2025/1/10)\n",
"- Optimize completion filtering.\n",
"- Add some properties in $PSCompletions for hooks to use to improve parsing speed.\n",
"- Fix an issue where background jobs could cause completion errors.\n",
"- Other fixes and optimizations.\n"
]
}
},
{
"version": "5.3.1",
"info": {
Expand Down
9 changes: 8 additions & 1 deletion module/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<p align="center">
<a href="./CHANGELOG-CN.md">简体中文</a>|
<a href="./CHANGELOG-CN.md">简体中文</a> |
<a href="./CHANGELOG.md">English</a>
</p>

## 5.3.2 (2025/1/10)

- Optimize completion filtering.
- Add some properties in `$PSCompletions` for `hooks` to use to improve parsing speed.
- Fix an issue where background jobs could cause completion errors.
- Other fixes and optimizations.

## 5.3.1 (2025/1/5)

- Fix an issue where when option completion had been used, it wasn't filtered out on the next completion.
Expand Down
2 changes: 1 addition & 1 deletion module/PSCompletions/PSCompletions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@{
RootModule = 'PSCompletions.psm1'

ModuleVersion = '5.3.1'
ModuleVersion = '5.3.2'

GUID = '00929632-527d-4dab-a5b3-21197faccd05'

Expand Down
2 changes: 1 addition & 1 deletion module/PSCompletions/core/completion/unix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod generate_complet
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod handle_completion {
foreach ($_ in $PSCompletions.data.aliasMap.keys) {
Register-ArgumentCompleter -CommandName $_ -ScriptBlock {
Register-ArgumentCompleter -Native -CommandName $_ -ScriptBlock {
param($word_to_complete, $command_ast, $cursor_position)

$space_tab = if (!$word_to_complete.length) { 1 }else { 0 }
Expand Down
2 changes: 1 addition & 1 deletion module/PSCompletions/core/completion/win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod generate_complet
else {
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod handle_completion {
foreach ($_ in $PSCompletions.data.aliasMap.keys) {
Register-ArgumentCompleter -CommandName $_ -ScriptBlock {
Register-ArgumentCompleter -Native -CommandName $_ -ScriptBlock {
param($word_to_complete, $command_ast, $cursor_position)

$space_tab = if (!$word_to_complete.length) { 1 }else { 0 }
Expand Down
118 changes: 67 additions & 51 deletions module/PSCompletions/core/init.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using namespace System.Management.Automation
$_ = Split-Path $PSScriptRoot -Parent
New-Variable -Name PSCompletions -Value @{
version = '5.3.1'
version = '5.3.2'
path = @{
root = $_
completions = Join-Path $_ 'completions'
Expand All @@ -22,7 +22,12 @@ New-Variable -Name PSCompletions -Value @{
separator = [System.IO.Path]::DirectorySeparatorChar
wc = New-Object System.Net.WebClient
menu = @{
const = @{
# 在 hooks 中,将其设置为 $true 即可。
# 用于那些大量动态生成的补全,忽略不必要的 tip,加快解析速度
ignore_tip = $false
# 存放临时数据,仅当使用 Esc 退出补全菜单时清除
temp = @{}
const = @{
symbol_item = @('SpaceTab', 'WriteSpaceTab', 'OptionTab')
line_item = @('horizontal', 'vertical', 'top_left', 'bottom_left', 'top_right', 'bottom_right')
color_item = @('item_text', 'item_back', 'selected_text', 'selected_back', 'filter_text', 'filter_back', 'border_text', 'border_back', 'status_text', 'status_back', 'tip_text', 'tip_back')
Expand Down Expand Up @@ -436,14 +441,61 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod get_completion {
}
$completions = $PSCompletions.completions_data.$root
$filter_list = [array](filterCompletions)
$filter_list = [array](handleCompletions $filter_list)
$_filter_list = [array](handleCompletions $filter_list)

$filter_list = [System.Collections.Generic.List[object]]@()
if ($space_tab -or $PSCompletions.input_arr[-1] -like '-*=') {
$filter_list = $filter_list.Where({ $_.CompletionText -notlike "-*" -or $_.CompletionText -notin $input_arr })
foreach ($item in $_filter_list) {
if ($item.CompletionText -notlike "-*" -or $item.CompletionText -notin $input_arr) {
$isContinue = $false
if ($item.alias) {
foreach ($a in $item.alias) {
if ($a -in $input_arr) {
$isContinue = $true
break
}
}
}
if ($isContinue) {
continue
}
$padSymbols = foreach ($c in $item.symbols) { $PSCompletions.config.$c }
$padSymbols = if ($padSymbols) { "$($PSCompletions.config.between_item_and_symbol)$($padSymbols -join '')" }else { '' }
$filter_list.Add(@{
ListItemText = $item.ListItemText + $padSymbols
CompletionText = $item.CompletionText
ToolTip = $item.ToolTip
})
}
}
}
else {
$filter_list = $filter_list.Where({ $_.CompletionText -like "$([WildcardPattern]::Escape($input_arr[-1]))*" })
$_input_arr = [System.Collections.Generic.List[string]]$PSCompletions.input_arr.Clone()
$_input_arr.RemoveAt(($_input_arr.Count - 1))
foreach ($item in $_filter_list) {
if ($item.CompletionText -like "$([WildcardPattern]::Escape($input_arr[-1]))*") {
$isContinue = $false
if ($item.alias) {
foreach ($a in $item.alias) {
if ($a -in $_input_arr) {
$isContinue = $true
break
}
}
}
if ($isContinue) {
continue
}
$padSymbols = foreach ($c in $item.symbols) { $PSCompletions.config.$c }
$padSymbols = if ($padSymbols) { "$($PSCompletions.config.between_item_and_symbol)$($padSymbols -join '')" }else { '' }
$filter_list.Add(@{
ListItemText = $item.ListItemText + $padSymbols
CompletionText = $item.CompletionText
ToolTip = $item.ToolTip
})
}
}
}

if ($PSCompletions.config.enable_completions_sort -eq 1) {
$path_order = "$($PSCompletions.path.order)/$root.json"
if ($PSCompletions.order."$($root)_job") {
Expand Down Expand Up @@ -478,45 +530,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod get_completion {
}
$PSCompletions.order_job((Get-PSReadLineOption).HistorySavePath, $root, $path_order)
}

$filter_list = [array]$filter_list

if ($space_tab) {
$_input_arr = $PSCompletions.input_arr
}
else {
$_input_arr = [System.Collections.Generic.List[string]]$PSCompletions.input_arr.Clone()
$_input_arr.RemoveAt(($_input_arr.Count - 1))
}
$return = @()

foreach ($item in $filter_list) {
if ($item -ne $null) {
if ($item.CompletionText -in $_input_arr) {
continue
}
$isContinue = $false
if ($item.alias) {
foreach ($a in $item.alias) {
if ($a -in $_input_arr) {
$isContinue = $true
break
}
}
}
if ($isContinue) {
continue
}
$padSymbols = foreach ($c in $item.symbols) { $PSCompletions.config.$c }
$padSymbols = if ($padSymbols) { "$($PSCompletions.config.between_item_and_symbol)$($padSymbols -join '')" }else { '' }
$return += @{
ListItemText = $item.ListItemText + $padSymbols
CompletionText = $item.CompletionText
ToolTip = $item.ToolTip
}
}
}
return $return
return $filter_list
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod handle_data_by_runspace {
param(
Expand Down Expand Up @@ -1111,7 +1125,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_powers
$PSCompletions.menu.is_show_tip = $PSCompletions.config.enable_tip -eq 1
}

if ($PSCompletions.menu.is_show_tip) {
if ($PSCompletions.menu.is_show_tip -and !$PSCompletions.menu.ignore_tip) {
foreach ($_ in $filter_list) {
if ($_.ToolTip -ne $null) {
$tip = $PSCompletions.replace_content($_.ToolTip)
Expand Down Expand Up @@ -1142,6 +1156,8 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_powers
}
}
}
$PSCompletions.menu.ignore_tip = $false
$PSCompletions.menu.temp = @{}
}
Add-Member -InputObject $PSCompletions -MemberType ScriptMethod argc_completions {
param(
Expand All @@ -1150,7 +1166,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod argc_completions
foreach ($_ in $completions) {
Register-ArgumentCompleter -Native -CommandName $_ -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$words = @($commandAst.CommandElements | Where { $_.Extent.StartOffset -lt $cursorPosition } | ForEach-Object {
$words = @($commandAst.CommandElements.Where({ $_.Extent.StartOffset -lt $cursorPosition }) | ForEach-Object {
$word = $_.ToString()
if ($word.Length -gt 2) {
if (($word.StartsWith('"') -and $word.EndsWith('"')) -or ($word.StartsWith("'") -and $word.EndsWith("'"))) {
Expand All @@ -1170,15 +1186,15 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod argc_completions
if ($commandAst.CommandElements[$lastElemIndex].Extent.EndOffset -lt $cursorPosition) {
$words += $emptyS
}
@((argc --argc-compgen powershell $emptyS $words) -split "`n") | ForEach-Object {
$parts = ($_ -split "`t")

foreach ($_ in @((argc --argc-compgen powershell $emptyS $words) -split "`n")) {
$parts = ($_ -split "`t")
if ($PSCompletions.config.enable_tip_when_enhance) {
$tip = if ($parts[3] -eq '') { ' ' }else { $parts[3] }
[CompletionResult]::new($parts[0], $parts[0], [CompletionResultType]::ParameterValue, $tip)
[CompletionResult]::new($parts[0], $parts[0], 'ParameterValue', $tip)
}
else {
[CompletionResult]::new($parts[0], $parts[0], [CompletionResultType]::ParameterValue, ' ')
[CompletionResult]::new($parts[0], $parts[0], 'ParameterValue', ' ')
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions module/PSCompletions/core/menu/win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,10 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod reset {
else {
$enable_tip = $PSCompletions.config.comp_config.$($PSCompletions.root_cmd).enable_tip
if ($enable_tip -ne $null) {
$PSCompletions.menu.is_show_tip = $enable_tip -eq 1
$PSCompletions.menu.is_show_tip = $enable_tip -eq 1 -and !$PSCompletions.menu.ignore_tip
}
else {
$PSCompletions.menu.is_show_tip = $PSCompletions.config.enable_tip -eq 1
$PSCompletions.menu.is_show_tip = $PSCompletions.config.enable_tip -eq 1 -and !$PSCompletions.menu.ignore_tip
}
}
}
Expand Down Expand Up @@ -926,6 +926,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module
27 {
# 27: ESC
$PSCompletions.menu.reset()
$PSCompletions.menu.temp = @{}
''
break loop
}
Expand Down Expand Up @@ -1040,4 +1041,5 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module
}
}
[console]::OutputEncoding = $current_encoding
$PSCompletions.menu.ignore_tip = $false
}
26 changes: 1 addition & 25 deletions module/PSCompletions/core/utils/Core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
param([string]$path)
if (!(Test-Path $path)) { New-Item -ItemType Directory $path > $null }
}
function ensure_psc {
ensure_dir "$($PSCompletions.path.completions)/psc"
ensure_dir "$($PSCompletions.path.completions)/psc/language"

$path_config = "$($PSCompletions.path.completions)/psc/config.json"
download_file "completions/psc/config.json" $path_config $PSCompletions.urls

$config = get_raw_content $path_config | ConvertFrom-Json

$file_list = @('guid.txt')
if ($config.hooks -ne $null) {
$file_list += 'hooks.ps1'
}
foreach ($lang in $config.language) {
$file_list += "language/$lang.json"
}
foreach ($path in $file_list) {
$path_file = "$($PSCompletions.path.completions)/psc/$path"
if (!(Test-Path $path_file)) {
download_file "completions/psc/$path" $path_file $PSCompletions.urls
}
}
}
function download_list {
ensure_dir $PSCompletions.path.temp
if (!(Test-Path $PSCompletions.path.completions_json)) {
Expand Down Expand Up @@ -110,8 +87,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
}

ensure_dir $PSCompletions.path.order

ensure_psc
ensure_dir "$($PSCompletions.path.completions)/psc"

$null = download_list

Expand Down
26 changes: 1 addition & 25 deletions module/PSCompletions/core/utils/Desktop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,6 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
param([string]$path)
if (!(Test-Path $path)) { New-Item -ItemType Directory $path > $null }
}
function ensure_psc {
ensure_dir "$($PSCompletions.path.completions)/psc"
ensure_dir "$($PSCompletions.path.completions)/psc/language"

$path_config = "$($PSCompletions.path.completions)/psc/config.json"
download_file "completions/psc/config.json" $path_config $PSCompletions.urls

$config = get_raw_content $path_config | ConvertFrom-Json

$file_list = @('guid.txt')
if ($config.hooks -ne $null) {
$file_list += 'hooks.ps1'
}
foreach ($lang in $config.language) {
$file_list += "language/$lang.json"
}
foreach ($path in $file_list) {
$path_file = "$($PSCompletions.path.completions)/psc/$path"
if (!(Test-Path $path_file)) {
download_file "completions/psc/$path" $path_file $PSCompletions.urls
}
}
}
function download_list {
ensure_dir $PSCompletions.path.temp
if (!(Test-Path $PSCompletions.path.completions_json)) {
Expand Down Expand Up @@ -175,8 +152,7 @@ Add-Member -InputObject $PSCompletions -MemberType ScriptMethod start_job {
}

ensure_dir $PSCompletions.path.order

ensure_psc
ensure_dir "$($PSCompletions.path.completions)/psc"

$null = download_list

Expand Down
2 changes: 1 addition & 1 deletion module/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.1
5.3.2

0 comments on commit 8452381

Please sign in to comment.