Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
ac850257
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac850257
编写于
3月 21, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Event hookup should follow user naming styles
上级
4f4ccc41
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
16 deletion
+68
-16
src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs
...sTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs
+12
-1
src/VisualStudio/CSharp/Impl/EventHookup/EventHookupSessionManager_EventHookupSession.cs
...entHookup/EventHookupSessionManager_EventHookupSession.cs
+25
-9
src/VisualStudio/CSharp/Test/EventHookup/EventHookupCommandHandlerTests.cs
...CSharp/Test/EventHookup/EventHookupCommandHandlerTests.cs
+25
-0
src/VisualStudio/CSharp/Test/EventHookup/EventHookupTestState.cs
...ualStudio/CSharp/Test/EventHookup/EventHookupTestState.cs
+5
-6
src/VisualStudio/CSharp/Test/Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests.csproj
...oft.VisualStudio.LanguageServices.CSharp.UnitTests.csproj
+1
-0
未找到文件。
src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs
浏览文件 @
ac850257
...
...
@@ -29,6 +29,8 @@ public NamingStylesTestOptionSets(string languageName)
_optionKey
=
NamingStyleOptions
.
GetNamingPreferencesOptionKey
(
languageName
);
}
public
OptionKey
OptionKey
=>
_optionKey
;
public
IDictionary
<
OptionKey
,
object
>
MergeStyles
(
IDictionary
<
OptionKey
,
object
>
first
,
IDictionary
<
OptionKey
,
object
>
second
,
string
languageName
)
{
var
firstPreferences
=
(
NamingStylePreferences
)
first
.
First
().
Value
;
...
...
@@ -57,6 +59,9 @@ public NamingStylesTestOptionSets(string languageName)
public
IDictionary
<
OptionKey
,
object
>
MethodNamesArePascalCase
=>
Options
(
_optionKey
,
MethodNamesArePascalCaseOption
());
public
IDictionary
<
OptionKey
,
object
>
MethodNamesAreCamelCase
=>
Options
(
_optionKey
,
MethodNamesAreCamelCaseOption
());
public
IDictionary
<
OptionKey
,
object
>
ParameterNamesAreCamelCase
=>
Options
(
_optionKey
,
ParameterNamesAreCamelCaseOption
());
...
...
@@ -290,6 +295,12 @@ private NamingStylePreferences FieldNamesAreCamelCaseWithFieldUnderscorePrefixAn
}
private
static
NamingStylePreferences
MethodNamesArePascalCaseOption
()
=>
MethodNamesAreCasedOption
(
Capitalization
.
PascalCase
);
internal
static
NamingStylePreferences
MethodNamesAreCamelCaseOption
()
=>
MethodNamesAreCasedOption
(
Capitalization
.
CamelCase
);
private
static
NamingStylePreferences
MethodNamesAreCasedOption
(
Capitalization
capitalization
)
{
var
symbolSpecification
=
new
SymbolSpecification
(
null
,
...
...
@@ -300,7 +311,7 @@ private static NamingStylePreferences MethodNamesArePascalCaseOption()
var
namingStyle
=
new
NamingStyle
(
Guid
.
NewGuid
(),
capitalizationScheme
:
Capitalization
.
PascalCase
,
capitalizationScheme
:
capitalization
,
name
:
"Name"
,
prefix
:
""
,
suffix
:
""
,
...
...
src/VisualStudio/CSharp/Impl/EventHookup/EventHookupSessionManager_EventHookupSession.cs
浏览文件 @
ac850257
...
...
@@ -3,11 +3,15 @@
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Editor.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Internal.Log
;
...
...
@@ -19,6 +23,7 @@
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor
;
using
Roslyn.Utilities
;
using
static
Microsoft
.
CodeAnalysis
.
Diagnostics
.
Analyzers
.
NamingStyles
.
SymbolSpecification
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.EventHookup
{
...
...
@@ -96,6 +101,7 @@ public void Cancel()
{
AssertIsForeground
();
_cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationToken
=
_cancellationTokenSource
.
Token
;
_textView
=
textView
;
_subjectBuffer
=
subjectBuffer
;
this
.
TESTSessionHookupMutex
=
testSessionHookupMutex
;
...
...
@@ -110,22 +116,22 @@ public void Cancel()
var
asyncToken
=
asyncListener
.
BeginAsyncOperation
(
GetType
().
Name
+
".Start"
);
this
.
GetEventNameTask
=
Task
.
Factory
.
SafeStartNewFromAsync
(
()
=>
DetermineIfEventHookupAndGetHandlerNameAsync
(
document
,
position
,
_cancellationTokenSource
.
Token
),
_cancellationTokenSource
.
Token
,
()
=>
DetermineIfEventHookupAndGetHandlerNameAsync
(
document
,
position
,
cancellation
Token
),
cancellation
Token
,
TaskScheduler
.
Default
);
var
continuedTask
=
this
.
GetEventNameTask
.
SafeContinueWithFromAsync
(
async
t
=>
{
await
ThreadingContext
.
JoinableTaskFactory
.
SwitchToMainThreadAsync
(
alwaysYield
:
true
,
_cancellationTokenSource
.
Token
);
_cancellationTokenSource
.
Token
.
ThrowIfCancellationRequested
();
await
ThreadingContext
.
JoinableTaskFactory
.
SwitchToMainThreadAsync
(
alwaysYield
:
true
,
cancellation
Token
);
cancellation
Token
.
ThrowIfCancellationRequested
();
if
(
t
.
Result
!=
null
)
{
commandHandler
.
EventHookupSessionManager
.
EventHookupFoundInSession
(
this
);
}
},
_cancellationTokenSource
.
Token
,
cancellation
Token
,
TaskContinuationOptions
.
OnlyOnRanToCompletion
|
TaskContinuationOptions
.
ExecuteSynchronously
,
TaskScheduler
.
Default
);
...
...
@@ -167,7 +173,14 @@ private async Task<string> DetermineIfEventHookupAndGetHandlerNameAsync(Document
return
null
;
}
return
GetEventHandlerName
(
eventSymbol
,
plusEqualsToken
.
Value
,
semanticModel
,
document
.
GetLanguageService
<
ISyntaxFactsService
>());
var
namingRule
=
await
document
.
GetApplicableNamingRuleAsync
(
new
SymbolKindOrTypeKind
(
MethodKind
.
Ordinary
),
new
DeclarationModifiers
(
isStatic
:
plusEqualsToken
.
Value
.
Parent
.
IsInStaticContext
()),
Accessibility
.
Private
,
cancellationToken
).
ConfigureAwait
(
false
);
return
GetEventHandlerName
(
eventSymbol
,
plusEqualsToken
.
Value
,
semanticModel
,
document
.
GetLanguageService
<
ISyntaxFactsService
>(),
namingRule
);
}
}
...
...
@@ -207,11 +220,14 @@ private IEventSymbol GetEventSymbol(SemanticModel semanticModel, SyntaxToken plu
return
symbol
as
IEventSymbol
;
}
private
string
GetEventHandlerName
(
IEventSymbol
eventSymbol
,
SyntaxToken
plusEqualsToken
,
SemanticModel
semanticModel
,
ISyntaxFactsService
syntaxFactsService
)
private
string
GetEventHandlerName
(
IEventSymbol
eventSymbol
,
SyntaxToken
plusEqualsToken
,
SemanticModel
semanticModel
,
ISyntaxFactsService
syntaxFactsService
,
NamingRule
namingRule
)
{
AssertIsBackground
();
var
basename
=
string
.
Format
(
"{0}_{1}"
,
GetNameObjectPart
(
eventSymbol
,
plusEqualsToken
,
semanticModel
,
syntaxFactsService
),
eventSymbol
.
Name
);
basename
=
basename
.
ToPascalCase
(
trimLeadingTypePrefix
:
false
);
var
objectPart
=
GetNameObjectPart
(
eventSymbol
,
plusEqualsToken
,
semanticModel
,
syntaxFactsService
);
var
basename
=
namingRule
.
NamingStyle
.
CreateName
(
ImmutableArray
.
Create
(
string
.
Format
(
"{0}_{1}"
,
objectPart
,
eventSymbol
.
Name
)));
var
reservedNames
=
semanticModel
.
LookupSymbols
(
plusEqualsToken
.
SpanStart
).
Select
(
m
=>
m
.
Name
);
...
...
src/VisualStudio/CSharp/Test/EventHookup/EventHookupCommandHandlerTests.cs
浏览文件 @
ac850257
...
...
@@ -3,9 +3,11 @@
// See the LICENSE file in the project root for more information.
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Xml.Linq
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
...
...
@@ -16,6 +18,8 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.EventHookup
[
UseExportProvider
]
public
class
EventHookupCommandHandlerTests
{
private
readonly
NamingStylesTestOptionSets
_namingOptions
=
new
NamingStylesTestOptionSets
(
LanguageNames
.
CSharp
);
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
EventHookup
)]
public
async
Task
HandlerName_EventInThisClass
()
{
...
...
@@ -34,6 +38,27 @@ void M()
testState
.
AssertShowing
(
"C_MyEvent"
);
}
[
WorkItem
(
20999
,
"https://github.com/dotnet/roslyn/issues/20999"
)]
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
EventHookup
)]
public
async
Task
HandlerName_EventInThisClass_CamelCaseRule
()
{
var
markup
=
@"
class C
{
event System.Action MyEvent;
void M()
{
MyEvent +$$
}
}"
;
using
var
testState
=
new
EventHookupTestState
(
EventHookupTestState
.
GetWorkspaceXml
(
markup
),
_namingOptions
.
MethodNamesAreCamelCase
);
testState
.
SendTypeChar
(
'='
);
await
testState
.
WaitForAsynchronousOperationsAsync
();
testState
.
AssertShowing
(
"c_MyEvent"
);
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
EventHookup
)]
public
async
Task
HandlerName_EventOnLocal
()
{
...
...
src/VisualStudio/CSharp/Test/EventHookup/EventHookupTestState.cs
浏览文件 @
ac850257
...
...
@@ -44,16 +44,15 @@ private static ComposableCatalog GetExtraParts()
}
public
static
EventHookupTestState
CreateTestState
(
string
markup
,
IDictionary
<
OptionKey
,
object
>
options
=
null
)
{
var
workspaceXml
=
string
.
Format
(
@"
=>
new
EventHookupTestState
(
GetWorkspaceXml
(
markup
),
options
);
public
static
XElement
GetWorkspaceXml
(
string
markup
)
=>
XElement
.
Parse
(
string
.
Format
(
@"
<Workspace>
<Project Language=""C#"" CommonReferences=""true"">
<Document>{0}</Document>
</Project>
</Workspace>"
,
markup
);
return
new
EventHookupTestState
(
XElement
.
Parse
(
workspaceXml
),
options
);
}
</Workspace>"
,
markup
));
internal
void
AssertShowing
(
string
expectedText
)
{
...
...
src/VisualStudio/CSharp/Test/Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests.csproj
浏览文件 @
ac850257
...
...
@@ -13,6 +13,7 @@
<ProjectReference
Include=
"..\..\..\Compilers\Test\Utilities\CSharp\Microsoft.CodeAnalysis.CSharp.Test.Utilities.csproj"
/>
<ProjectReference
Include=
"..\..\..\Compilers\Test\Utilities\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.Test.Utilities.vbproj"
/>
<ProjectReference
Include=
"..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj"
/>
<ProjectReference
Include=
"..\..\..\EditorFeatures\DiagnosticsTestUtilities\Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities.csproj"
/>
<ProjectReference
Include=
"..\..\..\EditorFeatures\TestUtilities2\Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities.vbproj"
/>
<ProjectReference
Include=
"..\..\..\EditorFeatures\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.vbproj"
/>
<ProjectReference
Include=
"..\..\..\Features\LanguageServer\Protocol\Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录