Skip to content

Commit d332a72

Browse files
committed
version1.3.1; 增加ICompletionSource的模糊匹配功能;
1 parent e18d167 commit d332a72

10 files changed

+597
-27
lines changed

src/ChinesePinyinIntelliSenseExtender.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="Intellisense\SyncCompletion\IdeographCompletionSourceProvider.cs" />
5858
<Compile Include="Intellisense\SyncCompletion\IdeographCompletionCommandHandler.cs" />
5959
<Compile Include="Intellisense\SyncCompletion\IdeographCompletionHandlerProvider.cs" />
60+
<Compile Include="Intellisense\SyncCompletion\InnerIdeographCompletionSet.cs" />
6061
<Compile Include="Internal\ArrayBaseEnumerator.cs" />
6162
<Compile Include="Options\DictionaryCombinationCreateForm.cs">
6263
<SubType>Form</SubType>
@@ -107,6 +108,8 @@
107108
<Compile Include="Ref\StringTrie\UnsafePooledIncrementalContainer.cs" />
108109
<Compile Include="Ref\StringTrie\ValueRef.cs" />
109110
<Compile Include="Usings.cs" />
111+
<Compile Include="Util\CompletionSetSelectBestMatchHelper.cs" />
112+
<Compile Include="Util\InputTextMatchHelper.cs" />
110113
<Compile Include="Util\StringPreMatchUtil.cs" />
111114
<Compile Include="Util\InputMethodDictionaryLoader.cs" />
112115
<Compile Include="Intellisense\AsyncCompletion\IdeographAsyncCompletionSource.cs" />

src/Intellisense/CompletionSourceProviderBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ static CompletionSourceProviderBase()
4646
{
4747
s_providerContentTypeCache.TryAdd(typeof(IdeographAsyncCompletionSourceProvider), Array.Empty<string>());
4848
s_providerContentTypeCache.TryAdd(typeof(IdeographCompletionSourceProvider), Array.Empty<string>());
49-
5049
}
5150

5251
#endregion Public 构造函数
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
namespace ChinesePinyinIntelliSenseExtender.Intellisense;
1+
#nullable enable
22

3+
namespace ChinesePinyinIntelliSenseExtender.Intellisense;
4+
5+
/// <summary>
6+
/// 表意文字完成
7+
/// </summary>
38
internal interface IIdeographCompletion
49
{
10+
#region Public 属性
11+
12+
/// <summary>
13+
/// 匹配文本
14+
/// </summary>
15+
string? MatchText { get; }
16+
17+
#endregion Public 属性
518
}
Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,98 @@
1-
using Microsoft.VisualStudio.Language.Intellisense;
1+
#nullable enable
2+
3+
using Microsoft.VisualStudio.Language.Intellisense;
24
using Microsoft.VisualStudio.Text;
35

46
namespace ChinesePinyinIntelliSenseExtender.Intellisense.SyncCompletion;
57

68
internal class IdeographCompletionSet : CompletionSet, IIdeographCompletionSet
79
{
10+
#region Private 字段
11+
12+
private readonly InnerIdeographCompletionSet _innerIdeographCompletionSet;
13+
14+
#endregion Private 字段
15+
16+
#region Public 属性
17+
18+
public override IList<Completion> CompletionBuilders => _innerIdeographCompletionSet.CompletionBuilders;
19+
20+
public override IList<Completion> Completions => _innerIdeographCompletionSet.Completions;
21+
22+
#endregion Public 属性
23+
824
#region Public 构造函数
925

10-
public IdeographCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<Completion> completions, IEnumerable<Completion> completionBuilders) : base(moniker, displayName, applicableTo, completions, completionBuilders)
26+
public IdeographCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<Completion> completions, IEnumerable<Completion> completionBuilders)
27+
: base(moniker, displayName, applicableTo, completions, completionBuilders)
1128
{
29+
_innerIdeographCompletionSet = new InnerIdeographCompletionSet(this, new(WritableCompletions), new(WritableCompletionBuilders));
1230
}
1331

1432
#endregion Public 构造函数
33+
34+
#region Public 方法
35+
36+
public override void Filter()
37+
{
38+
_innerIdeographCompletionSet.Filter();
39+
}
40+
41+
public override IReadOnlyList<Span> GetHighlightedSpansInDisplayText(string displayText)
42+
{
43+
return _innerIdeographCompletionSet.GetHighlightedSpansInDisplayText(displayText);
44+
}
45+
46+
public override void SelectBestMatch()
47+
{
48+
_innerIdeographCompletionSet.SelectBestMatch();
49+
}
50+
51+
#endregion Public 方法
1552
}
1653

1754
internal class IdeographCompletionSet2 : CompletionSet2, IIdeographCompletionSet
1855
{
56+
#region Private 字段
57+
58+
private readonly InnerIdeographCompletionSet _innerIdeographCompletionSet;
59+
60+
#endregion Private 字段
61+
62+
#region Public 属性
63+
64+
public override IList<Completion> CompletionBuilders => _innerIdeographCompletionSet.CompletionBuilders;
65+
66+
public override IList<Completion> Completions => _innerIdeographCompletionSet.Completions;
67+
68+
#endregion Public 属性
69+
1970
#region Public 构造函数
2071

21-
public IdeographCompletionSet2(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<Completion> completions, IEnumerable<Completion> completionBuilders, IReadOnlyList<IIntellisenseFilter> filters) : base(moniker, displayName, applicableTo, completions, completionBuilders, filters)
72+
public IdeographCompletionSet2(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<Completion> completions, IEnumerable<Completion> completionBuilders, IReadOnlyList<IIntellisenseFilter> filters)
73+
: base(moniker, displayName, applicableTo, completions, completionBuilders, filters)
2274
{
75+
_innerIdeographCompletionSet = new InnerIdeographCompletionSet(this, new(WritableCompletions), new(WritableCompletionBuilders));
2376
}
2477

2578
#endregion Public 构造函数
79+
80+
#region Public 方法
81+
82+
public override void Filter()
83+
{
84+
_innerIdeographCompletionSet.Filter();
85+
}
86+
87+
public override IReadOnlyList<Span> GetHighlightedSpansInDisplayText(string displayText)
88+
{
89+
return _innerIdeographCompletionSet.GetHighlightedSpansInDisplayText(displayText);
90+
}
91+
92+
public override void SelectBestMatch()
93+
{
94+
_innerIdeographCompletionSet.SelectBestMatch();
95+
}
96+
97+
#endregion Public 方法
2698
}

src/Intellisense/SyncCompletion/IdeographCompletionSource.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ private Completion CloneCompletion(Completion originCompletion)
9191
return originCompletion switch
9292
{
9393
Completion4 completion4 => completion4.Suffix?.Length > 0
94-
? new IdeographCompletion4(displayText: completion4.DisplayText, suffix: completion4.Suffix, origin: completion4)
95-
: new IdeographCompletion4(displayText: completion4.DisplayText, origin: completion4),
96-
Completion3 completion3 => new IdeographCompletion3(displayText: completion3.DisplayText, origin: completion3),
97-
Completion2 completion2 => new IdeographCompletion2(displayText: completion2.DisplayText, origin: completion2),
98-
_ => new IdeographCompletion(displayText: originCompletion.DisplayText, origin: originCompletion),
94+
? new IdeographCompletion4(displayText: completion4.DisplayText, suffix: completion4.Suffix, matchText: null, origin: completion4)
95+
: new IdeographCompletion4(displayText: completion4.DisplayText, matchText: null, origin: completion4),
96+
Completion3 completion3 => new IdeographCompletion3(displayText: completion3.DisplayText, matchText: null, origin: completion3),
97+
Completion2 completion2 => new IdeographCompletion2(displayText: completion2.DisplayText, matchText: null, origin: completion2),
98+
_ => new IdeographCompletion(displayText: originCompletion.DisplayText, matchText: null, origin: originCompletion),
9999
};
100100
}
101101

@@ -106,11 +106,11 @@ private Completion CreateCompletion(Completion originCompletion, string originIn
106106
return originCompletion switch
107107
{
108108
Completion4 completion4 => completion4.Suffix?.Length > 0
109-
? new IdeographCompletion4(displayText: displayText, suffix: completion4.Suffix, origin: completion4)
110-
: new IdeographCompletion4(displayText: displayText, origin: completion4),
111-
Completion3 completion3 => new IdeographCompletion3(displayText: displayText, origin: completion3),
112-
Completion2 completion2 => new IdeographCompletion2(displayText: displayText, origin: completion2),
113-
_ => new IdeographCompletion(displayText: displayText, origin: originCompletion),
109+
? new IdeographCompletion4(displayText: displayText, suffix: completion4.Suffix, matchText: spelling, origin: completion4)
110+
: new IdeographCompletion4(displayText: displayText, matchText: spelling, origin: completion4),
111+
Completion3 completion3 => new IdeographCompletion3(displayText: displayText, matchText: spelling, origin: completion3),
112+
Completion2 completion2 => new IdeographCompletion2(displayText: displayText, matchText: spelling, origin: completion2),
113+
_ => new IdeographCompletion(displayText: displayText, matchText: spelling, origin: originCompletion),
114114
};
115115
}
116116

src/Intellisense/SyncCompletion/IdeographCompletions.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using System.Windows.Media;
1+
#nullable enable
2+
3+
using System.Diagnostics;
4+
using System.Windows.Media;
25
using Microsoft.VisualStudio.Imaging.Interop;
36
using Microsoft.VisualStudio.Language.Intellisense;
47
using Microsoft.VisualStudio.Utilities;
58

69
namespace ChinesePinyinIntelliSenseExtender.Intellisense.SyncCompletion;
710

11+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
812
internal class IdeographCompletion : Completion, IIdeographCompletion
913
{
1014
#region Private 字段
@@ -23,21 +27,25 @@ internal class IdeographCompletion : Completion, IIdeographCompletion
2327

2428
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
2529

30+
public string? MatchText { get; }
31+
2632
public override PropertyCollection Properties => _origin.Properties;
2733

2834
#endregion Public 属性
2935

3036
#region Public 构造函数
3137

32-
public IdeographCompletion(string displayText, Completion origin)
38+
public IdeographCompletion(string displayText, string? matchText, Completion origin)
3339
{
34-
_origin = origin;
3540
DisplayText = displayText;
41+
MatchText = matchText;
42+
_origin = origin;
3643
}
3744

3845
#endregion Public 构造函数
3946
}
4047

48+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
4149
internal class IdeographCompletion2 : Completion2, IIdeographCompletion
4250
{
4351
#region Private 字段
@@ -58,21 +66,25 @@ internal class IdeographCompletion2 : Completion2, IIdeographCompletion
5866

5967
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
6068

69+
public string? MatchText { get; }
70+
6171
public override PropertyCollection Properties => _origin.Properties;
6272

6373
#endregion Public 属性
6474

6575
#region Public 构造函数
6676

67-
public IdeographCompletion2(string displayText, Completion2 origin)
77+
public IdeographCompletion2(string displayText, string? matchText, Completion2 origin)
6878
{
69-
_origin = origin;
7079
DisplayText = displayText;
80+
MatchText = matchText;
81+
_origin = origin;
7182
}
7283

7384
#endregion Public 构造函数
7485
}
7586

87+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
7688
internal class IdeographCompletion3 : Completion3, IIdeographCompletion
7789
{
7890
#region Private 字段
@@ -95,21 +107,25 @@ internal class IdeographCompletion3 : Completion3, IIdeographCompletion
95107

96108
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
97109

110+
public string? MatchText { get; }
111+
98112
public override PropertyCollection Properties => _origin.Properties;
99113

100114
#endregion Public 属性
101115

102116
#region Public 构造函数
103117

104-
public IdeographCompletion3(string displayText, Completion3 origin)
118+
public IdeographCompletion3(string displayText, string? matchText, Completion3 origin)
105119
{
106-
_origin = origin;
107120
DisplayText = displayText;
121+
MatchText = matchText;
122+
_origin = origin;
108123
}
109124

110125
#endregion Public 构造函数
111126
}
112127

128+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
113129
internal class IdeographCompletion4 : Completion4, IIdeographCompletion
114130
{
115131
#region Private 字段
@@ -132,22 +148,27 @@ internal class IdeographCompletion4 : Completion4, IIdeographCompletion
132148

133149
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
134150

151+
public string? MatchText { get; }
152+
135153
public override PropertyCollection Properties => _origin.Properties;
136154

137155
#endregion Public 属性
138156

139157
#region Public 构造函数
140158

141-
public IdeographCompletion4(string displayText, string suffix, Completion4 origin) : base(displayText: null, insertionText: null, description: null, iconMoniker: default, suffix: suffix)
159+
public IdeographCompletion4(string displayText, string suffix, string? matchText, Completion4 origin)
160+
: base(displayText: null, insertionText: null, description: null, iconMoniker: default, suffix: suffix)
142161
{
143-
_origin = origin;
144162
DisplayText = displayText;
163+
MatchText = matchText;
164+
_origin = origin;
145165
}
146166

147-
public IdeographCompletion4(string displayText, Completion4 origin)
167+
public IdeographCompletion4(string displayText, string? matchText, Completion4 origin)
148168
{
149-
_origin = origin;
150169
DisplayText = displayText;
170+
MatchText = matchText;
171+
_origin = origin;
151172
}
152173

153174
#endregion Public 构造函数

0 commit comments

Comments
 (0)