Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
170f1295
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,发现更多精彩内容 >>
提交
170f1295
编写于
5月 19, 2015
作者:
T
Tomáš Matoušek
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2882 from tmat/AnalyzerErrorReporting
Fix analyzer type load error reporting, API
上级
7971a1e4
97ce8c09
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
81 addition
and
34 deletion
+81
-34
src/Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
...Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
+10
-1
src/Compilers/Core/Portable/CodeAnalysisResources.resx
src/Compilers/Core/Portable/CodeAnalysisResources.resx
+3
-0
src/Compilers/Core/Portable/CommandLine/CommonCommandLineArguments.cs
...s/Core/Portable/CommandLine/CommonCommandLineArguments.cs
+2
-2
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs
...Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs
+23
-17
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerLoadFailureEventArgs.cs
...rtable/DiagnosticAnalyzer/AnalyzerLoadFailureEventArgs.cs
+36
-8
src/Compilers/Core/Portable/PublicAPI.txt
src/Compilers/Core/Portable/PublicAPI.txt
+5
-4
src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioAnalyzer.cs
.../Def/Implementation/ProjectSystem/VisualStudioAnalyzer.cs
+2
-2
未找到文件。
src/Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
浏览文件 @
170f1295
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.
4200
0
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
...
...
@@ -728,6 +728,15 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to No analyzers found.
/// </summary>
internal
static
string
NoAnalyzersFound
{
get
{
return
ResourceManager
.
GetString
(
"NoAnalyzersFound"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot deserialize type '{0}', no binder supplied..
/// </summary>
...
...
src/Compilers/Core/Portable/CodeAnalysisResources.resx
浏览文件 @
170f1295
...
...
@@ -469,4 +469,7 @@
<data
name=
"AnalyzerNameColumnHeader"
xml:space=
"preserve"
>
<value>
Analyzer
</value>
</data>
<data
name=
"NoAnalyzersFound"
xml:space=
"preserve"
>
<value>
No analyzers found
</value>
</data>
</root>
\ No newline at end of file
src/Compilers/Core/Portable/CommandLine/CommonCommandLineArguments.cs
浏览文件 @
170f1295
...
...
@@ -349,10 +349,10 @@ internal ImmutableArray<DiagnosticAnalyzer> ResolveAnalyzersFromArguments(string
switch
(
e
.
ErrorCode
)
{
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
:
diagnostic
=
new
DiagnosticInfo
(
messageProvider
,
messageProvider
.
WRN_UnableToLoadAnalyzer
,
analyzerReference
.
FullPath
,
e
.
Exception
.
Message
);
diagnostic
=
new
DiagnosticInfo
(
messageProvider
,
messageProvider
.
WRN_UnableToLoadAnalyzer
,
analyzerReference
.
FullPath
,
e
.
Message
);
break
;
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToCreateAnalyzer
:
diagnostic
=
new
DiagnosticInfo
(
messageProvider
,
messageProvider
.
WRN_AnalyzerCannotBeCreated
,
e
.
TypeName
,
analyzerReference
.
FullPath
,
e
.
Exception
.
Message
);
diagnostic
=
new
DiagnosticInfo
(
messageProvider
,
messageProvider
.
WRN_AnalyzerCannotBeCreated
,
e
.
TypeName
,
analyzerReference
.
FullPath
,
e
.
Message
);
break
;
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
:
diagnostic
=
new
DiagnosticInfo
(
messageProvider
,
messageProvider
.
WRN_NoAnalyzerInAssembly
,
analyzerReference
.
FullPath
);
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs
浏览文件 @
170f1295
...
...
@@ -4,6 +4,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
...
...
@@ -160,7 +161,7 @@ internal void AddAnalyzers(ImmutableDictionary<string, ImmutableArray<Diagnostic
}
catch
(
Exception
e
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
,
e
,
null
));
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
,
e
.
Message
,
e
));
return
;
}
...
...
@@ -183,7 +184,7 @@ internal void AddAnalyzers(ImmutableDictionary<string, ImmutableArray<Diagnostic
// If we've reported errors already while trying to instantiate types, don't complain that there are no analyzers.
if
(
builder
.
Count
==
initialCount
&&
!
reportedError
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
,
null
,
null
));
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
,
CodeAnalysisResources
.
NoAnalyzersFound
));
}
}
...
...
@@ -209,7 +210,7 @@ internal void AddAnalyzers(ImmutableArray<DiagnosticAnalyzer>.Builder builder, s
}
catch
(
Exception
e
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
,
e
,
null
));
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
,
e
.
Message
));
return
;
}
...
...
@@ -224,7 +225,7 @@ internal void AddAnalyzers(ImmutableArray<DiagnosticAnalyzer>.Builder builder, s
// If we've reported errors already while trying to instantiate types, don't complain that there are no analyzers.
if
(
builder
.
Count
==
initialCount
&&
!
reportedError
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
,
null
,
null
));
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
,
CodeAnalysisResources
.
NoAnalyzersFound
));
}
}
...
...
@@ -252,20 +253,30 @@ private IEnumerable<DiagnosticAnalyzer> GetAnalyzersForTypeNames(Assembly analyz
// Given the type names, get the actual System.Type and try to create an instance of the type through reflection.
foreach
(
var
typeName
in
analyzerTypeNames
)
{
DiagnosticAnalyzer
analyzer
=
null
;
Type
type
;
try
{
var
type
=
analyzerAssembly
.
GetType
(
typeName
);
if
(
DerivesFromDiagnosticAnalyzer
(
type
))
{
analyzer
=
(
DiagnosticAnalyzer
)
Activator
.
CreateInstance
(
type
);
}
type
=
Type
.
GetType
(
typeName
+
", "
+
analyzerAssembly
.
FullName
,
throwOnError
:
true
);
}
catch
(
Exception
e
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToCreateAnalyzer
,
e
.
Message
,
e
,
typeName
));
reportedError
=
true
;
continue
;
}
Debug
.
Assert
(
type
!=
null
);
DiagnosticAnalyzer
analyzer
;
try
{
analyzer
=
Activator
.
CreateInstance
(
type
)
as
DiagnosticAnalyzer
;
}
catch
(
Exception
e
)
{
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToCreateAnalyzer
,
e
,
typeName
));
analyzer
=
null
;
this
.
AnalyzerLoadFailed
?.
Invoke
(
this
,
new
AnalyzerLoadFailureEventArgs
(
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToCreateAnalyzer
,
e
.
Message
,
e
,
typeName
));
reportedError
=
true
;
continue
;
}
if
(
analyzer
!=
null
)
...
...
@@ -381,11 +392,6 @@ private static string GetFullyQualifiedTypeName(TypeDefinition typeDef, PEModule
}
}
private
static
bool
DerivesFromDiagnosticAnalyzer
(
Type
type
)
{
return
type
.
GetTypeInfo
().
IsSubclassOf
(
typeof
(
DiagnosticAnalyzer
));
}
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
AnalyzerFileReference
);
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerLoadFailureEventArgs.cs
浏览文件 @
170f1295
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Diagnostics
;
namespace
Microsoft.CodeAnalysis.Diagnostics
{
public
class
AnalyzerLoadFailureEventArgs
:
EventArgs
public
sealed
class
AnalyzerLoadFailureEventArgs
:
EventArgs
{
public
enum
FailureErrorCode
{
...
...
@@ -14,15 +15,42 @@ public enum FailureErrorCode
NoAnalyzers
=
3
}
public
readonly
string
TypeName
;
public
readonly
Exception
Exception
;
public
readonly
FailureErrorCode
ErrorCode
;
/// <summary>
/// If a specific analyzer failed to load the namespace-qualified name of its type, null otherwise.
/// </summary>
public
string
TypeName
{
get
;
}
public
AnalyzerLoadFailureEventArgs
(
FailureErrorCode
errorCode
,
Exception
ex
,
string
typeName
)
/// <summary>
/// Error message.
/// </summary>
public
string
Message
{
get
;
}
/// <summary>
/// Error code.
/// </summary>
public
FailureErrorCode
ErrorCode
{
get
;
}
/// <summary>
/// Exception that was thrown while loading the analyzer. May be null.
/// </summary>
public
Exception
Exception
{
get
;
}
public
AnalyzerLoadFailureEventArgs
(
FailureErrorCode
errorCode
,
string
message
,
Exception
exceptionOpt
=
null
,
string
typeNameOpt
=
null
)
{
this
.
TypeName
=
typeName
;
this
.
ErrorCode
=
errorCode
;
this
.
Exception
=
ex
;
if
(
errorCode
<=
FailureErrorCode
.
None
||
errorCode
>
FailureErrorCode
.
NoAnalyzers
)
{
throw
new
ArgumentOutOfRangeException
(
nameof
(
errorCode
));
}
if
(
message
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
message
));
}
ErrorCode
=
errorCode
;
Message
=
message
;
TypeName
=
typeNameOpt
;
Exception
=
exceptionOpt
;
}
}
}
src/Compilers/Core/Portable/PublicAPI.txt
浏览文件 @
170f1295
...
...
@@ -294,12 +294,16 @@ Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.GetAssembly() -> System
Microsoft.CodeAnalysis.Diagnostics.AnalyzerImageReference
Microsoft.CodeAnalysis.Diagnostics.AnalyzerImageReference.AnalyzerImageReference(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> analyzers, string fullPath = null, string display = null) -> void
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.AnalyzerLoadFailureEventArgs(Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode errorCode, System.Exception ex, string typeName) -> void
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.AnalyzerLoadFailureEventArgs(Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode errorCode, string message, System.Exception exceptionOpt = null, string typeNameOpt = null) -> void
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.ErrorCode.get -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.Exception.get -> System.Exception
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers = 3 -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode.None = 0 -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer = 2 -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToLoadAnalyzer = 1 -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.Message.get -> string
Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.TypeName.get -> string
Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions
Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions.AdditionalFiles.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.AdditionalText>
Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions.AnalyzerOptions(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.AdditionalText> additionalFiles) -> void
...
...
@@ -1988,9 +1992,6 @@ override sealed Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer.ToString()
override sealed Microsoft.CodeAnalysis.LocalizableString.Equals(object other) -> bool
override sealed Microsoft.CodeAnalysis.LocalizableString.GetHashCode() -> int
override sealed Microsoft.CodeAnalysis.LocalizableString.ToString() -> string
readonly Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.ErrorCode -> Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.FailureErrorCode
readonly Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.Exception -> System.Exception
readonly Microsoft.CodeAnalysis.Diagnostics.AnalyzerLoadFailureEventArgs.TypeName -> string
static Microsoft.CodeAnalysis.AnnotationExtensions.WithAdditionalAnnotations<TNode>(this TNode node, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxAnnotation> annotations) -> TNode
static Microsoft.CodeAnalysis.AnnotationExtensions.WithAdditionalAnnotations<TNode>(this TNode node, params Microsoft.CodeAnalysis.SyntaxAnnotation[] annotations) -> TNode
static Microsoft.CodeAnalysis.AnnotationExtensions.WithoutAnnotations<TNode>(this TNode node, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxAnnotation> annotations) -> TNode
...
...
src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioAnalyzer.cs
浏览文件 @
170f1295
...
...
@@ -85,12 +85,12 @@ private void OnAnalyzerLoadError(object sender, AnalyzerLoadFailureEventArgs e)
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToLoadAnalyzer
:
id
=
_language
==
LanguageNames
.
CSharp
?
WRN_UnableToLoadAnalyzerIdCS
:
WRN_UnableToLoadAnalyzerIdVB
;
messageFormat
=
ServicesVSResources
.
WRN_UnableToLoadAnalyzer
;
message
=
string
.
Format
(
ServicesVSResources
.
WRN_UnableToLoadAnalyzer
,
_fullPath
,
e
.
Exception
.
Message
);
message
=
string
.
Format
(
ServicesVSResources
.
WRN_UnableToLoadAnalyzer
,
_fullPath
,
e
.
Message
);
break
;
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
UnableToCreateAnalyzer
:
id
=
_language
==
LanguageNames
.
CSharp
?
WRN_AnalyzerCannotBeCreatedIdCS
:
WRN_AnalyzerCannotBeCreatedIdVB
;
messageFormat
=
ServicesVSResources
.
WRN_AnalyzerCannotBeCreated
;
message
=
string
.
Format
(
ServicesVSResources
.
WRN_AnalyzerCannotBeCreated
,
e
.
TypeName
,
_fullPath
,
e
.
Exception
.
Message
);
message
=
string
.
Format
(
ServicesVSResources
.
WRN_AnalyzerCannotBeCreated
,
e
.
TypeName
,
_fullPath
,
e
.
Message
);
break
;
case
AnalyzerLoadFailureEventArgs
.
FailureErrorCode
.
NoAnalyzers
:
id
=
_language
==
LanguageNames
.
CSharp
?
WRN_NoAnalyzerInAssemblyIdCS
:
WRN_NoAnalyzerInAssemblyIdVB
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录