回答編集履歴

2

編集

2019/03/06 10:51

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  if ($lastBlock -match '(^[)(.*)') {
42
42
 
43
- $newTypes = [AppDomain]::CurrentDomain.GetAssemblies() | Foreach-Object {
43
+ [AppDomain]::CurrentDomain.GetAssemblies() | Foreach-Object {
44
44
 
45
45
  $_.GetTypes()
46
46
 
@@ -48,9 +48,7 @@
48
48
 
49
49
  ($_.Name -notlike '*_<staticHelpers>') -and ($_.FullName -ilike "*$($Matches[2])*")
50
50
 
51
- }
52
-
53
- $newTypes | ForEach-Object {
51
+ } | ForEach-Object {
54
52
 
55
53
  '[' + $_.FullName + ']'
56
54
 

1

追記

2019/03/06 10:51

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -9,3 +9,61 @@
9
9
 
10
10
 
11
11
  現在使用可能なクラスは `[AppDomain]::CurrentDomain.GetAssemblies()|%{$_.GetTypes()}` で得ることができますが、補完のたびにこれを呼び出すのもパフォーマンスが落ちるでしょう。例えば指定したキーワードがコマンドラインにあった場合に読み直すようにするのはどうでしょうか?
12
+
13
+
14
+
15
+ # 追記
16
+
17
+
18
+
19
+ 以下のスクリプトを実行することで、外部モジュールで作られたクラスが補完できることを確認しました。
20
+
21
+ なお、新クラスのアセンブリ名が `PowerShell Class Assembly` となるのは PowerShell Core の場合で、それ以前のバージョンの場合は `/powershell` のようでした。
22
+
23
+
24
+
25
+ ```
26
+
27
+ function TabExpansion
28
+
29
+ {
30
+
31
+ param($line, $lastWord)
32
+
33
+
34
+
35
+ $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
36
+
37
+ $matchBackup = $Matches
38
+
39
+ try {
40
+
41
+ if ($lastBlock -match '(^[)(.*)') {
42
+
43
+ $newTypes = [AppDomain]::CurrentDomain.GetAssemblies() | Foreach-Object {
44
+
45
+ $_.GetTypes()
46
+
47
+ } | Where-Object {
48
+
49
+ ($_.Name -notlike '*_<staticHelpers>') -and ($_.FullName -ilike "*$($Matches[2])*")
50
+
51
+ }
52
+
53
+ $newTypes | ForEach-Object {
54
+
55
+ '[' + $_.FullName + ']'
56
+
57
+ }
58
+
59
+ }
60
+
61
+ } finally {
62
+
63
+ $Matches = $matchBackup
64
+
65
+ }
66
+
67
+ }
68
+
69
+ ```