Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
33a47a6b
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,发现更多精彩内容 >>
未验证
提交
33a47a6b
编写于
3月 02, 2020
作者:
S
Sam Harwell
提交者:
GitHub
3月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #41803 from sharwell/analyzer-config
Apply options via .editorconfig for analyzer testing
上级
ebf15ea3
22bc3f0f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
87 addition
and
3 deletion
+87
-3
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
...TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
+11
-1
src/EditorFeatures/TestUtilities/CodeActions/CodeFixVerifierHelper.cs
...atures/TestUtilities/CodeActions/CodeFixVerifierHelper.cs
+62
-0
src/EditorFeatures/TestUtilities/CodeActions/OptionsCollection.cs
...orFeatures/TestUtilities/CodeActions/OptionsCollection.cs
+3
-1
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
...tilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
+11
-1
未找到文件。
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
浏览文件 @
33a47a6b
...
...
@@ -45,8 +45,18 @@ public Test()
solution
=
solution
.
WithProjectCompilationOptions
(
projectId
,
compilationOptions
);
#if !CODE_STYLE // TODO: Add support for Options based tests in CodeStyle layer
var
(
analyzerConfigSource
,
remainingOptions
)
=
CodeFixVerifierHelper
.
ConvertOptionsToAnalyzerConfig
(
DefaultFileExt
,
Options
);
if
(
analyzerConfigSource
is
object
)
{
foreach
(
var
id
in
solution
.
ProjectIds
)
{
var
documentId
=
DocumentId
.
CreateNewId
(
id
,
".editorconfig"
);
solution
=
solution
.
AddAnalyzerConfigDocument
(
documentId
,
".editorconfig"
,
analyzerConfigSource
,
filePath
:
"/.editorconfig"
);
}
}
var
options
=
solution
.
Options
;
foreach
(
var
(
key
,
value
)
in
Options
)
foreach
(
var
(
key
,
value
)
in
remaining
Options
)
{
options
=
options
.
WithChangedOption
(
key
,
value
);
}
...
...
src/EditorFeatures/TestUtilities/CodeActions/CodeFixVerifierHelper.cs
浏览文件 @
33a47a6b
...
...
@@ -5,8 +5,13 @@
#
nullable
enable
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
...
...
@@ -75,5 +80,62 @@ private static void VerifyMessageHelpLinkUri(DiagnosticAnalyzer analyzer)
Assert
.
NotEqual
(
""
,
descriptor
.
HelpLinkUri
??
""
);
}
}
#if !CODE_STYLE
public
static
(
SourceText
?
analyzerConfig
,
IEnumerable
<
KeyValuePair
<
OptionKey
,
object
?>>
options
)
ConvertOptionsToAnalyzerConfig
(
string
defaultFileExtension
,
OptionsCollection
options
)
{
if
(
options
.
Count
==
0
)
{
return
(
null
,
options
);
}
var
optionSet
=
new
OptionSetWrapper
(
options
.
ToDictionary
<
KeyValuePair
<
OptionKey
,
object
?>,
OptionKey
,
object
?>(
option
=>
option
.
Key
,
option
=>
option
.
Value
));
var
remainingOptions
=
new
List
<
KeyValuePair
<
OptionKey
,
object
?>>();
var
analyzerConfig
=
new
StringBuilder
();
analyzerConfig
.
AppendLine
(
"root = true"
);
analyzerConfig
.
AppendLine
();
analyzerConfig
.
AppendLine
(
$"[*.
{
defaultFileExtension
}
]"
);
foreach
(
var
(
key
,
value
)
in
options
)
{
var
editorConfigStorageLocation
=
key
.
Option
.
StorageLocations
.
OfType
<
IEditorConfigStorageLocation2
>().
FirstOrDefault
();
if
(
editorConfigStorageLocation
is
null
)
{
remainingOptions
.
Add
(
KeyValuePairUtil
.
Create
<
OptionKey
,
object
?>(
key
,
value
));
continue
;
}
analyzerConfig
.
AppendLine
(
editorConfigStorageLocation
.
GetEditorConfigString
(
value
,
optionSet
));
}
return
(
SourceText
.
From
(
analyzerConfig
.
ToString
(),
Encoding
.
UTF8
),
remainingOptions
);
}
private
sealed
class
OptionSetWrapper
:
OptionSet
{
private
readonly
Dictionary
<
OptionKey
,
object
?>
_options
;
public
OptionSetWrapper
(
Dictionary
<
OptionKey
,
object
?>
options
)
{
_options
=
options
;
}
public
override
object
?
GetOption
(
OptionKey
optionKey
)
{
if
(!
_options
.
TryGetValue
(
optionKey
,
out
var
value
))
{
value
=
optionKey
.
Option
.
DefaultValue
;
}
return
value
;
}
public
override
OptionSet
WithChangedOption
(
OptionKey
optionAndLanguage
,
object
?
value
)
=>
throw
new
NotSupportedException
();
internal
override
IEnumerable
<
OptionKey
>
GetChangedOptions
(
OptionSet
optionSet
)
=>
SpecializedCollections
.
EmptyEnumerable
<
OptionKey
>();
}
#endif
}
}
src/EditorFeatures/TestUtilities/CodeActions/OptionsCollection.cs
浏览文件 @
33a47a6b
...
...
@@ -9,7 +9,7 @@
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
sealed
class
OptionsCollection
:
I
Enumerable
<
KeyValuePair
<
OptionKey
,
object
>>
public
sealed
class
OptionsCollection
:
I
ReadOnlyCollection
<
KeyValuePair
<
OptionKey
,
object
>>
{
private
readonly
Dictionary
<
OptionKey
,
object
>
_options
=
new
Dictionary
<
OptionKey
,
object
>();
private
readonly
string
_languageName
;
...
...
@@ -19,6 +19,8 @@ public OptionsCollection(string languageName)
_languageName
=
languageName
;
}
public
int
Count
=>
_options
.
Count
;
public
void
Add
<
T
>(
Option
<
T
>
option
,
T
value
)
=>
_options
.
Add
(
new
OptionKey
(
option
),
value
);
...
...
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
浏览文件 @
33a47a6b
...
...
@@ -32,8 +32,18 @@ public Test()
solution
=
solution
.
WithProjectParseOptions
(
projectId
,
parseOptions
.
WithLanguageVersion
(
LanguageVersion
));
#if !CODE_STYLE // TODO: Add support for Options based tests in CodeStyle layer
var
(
analyzerConfigSource
,
remainingOptions
)
=
CodeFixVerifierHelper
.
ConvertOptionsToAnalyzerConfig
(
DefaultFileExt
,
Options
);
if
(
analyzerConfigSource
is
object
)
{
foreach
(
var
id
in
solution
.
ProjectIds
)
{
var
documentId
=
DocumentId
.
CreateNewId
(
id
,
".editorconfig"
);
solution
=
solution
.
AddAnalyzerConfigDocument
(
documentId
,
".editorconfig"
,
analyzerConfigSource
,
filePath
:
"/.editorconfig"
);
}
}
var
options
=
solution
.
Options
;
foreach
(
var
(
key
,
value
)
in
Options
)
foreach
(
var
(
key
,
value
)
in
remaining
Options
)
{
options
=
options
.
WithChangedOption
(
key
,
value
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录