Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
991018a0
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,发现更多精彩内容 >>
提交
991018a0
编写于
10月 31, 2018
作者:
H
HeeJae Chang
提交者:
Sam Harwell
11月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add IDocumentOperationService.SupportDiagnostics
上级
6262cc0d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
69 addition
and
20 deletion
+69
-20
src/Features/Core/Portable/Diagnostics/DiagnosticResultSerializer.cs
...s/Core/Portable/Diagnostics/DiagnosticResultSerializer.cs
+12
-3
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs
...cs/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs
+16
-10
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs
...neV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs
+2
-1
src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs
...ces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs
+21
-5
src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResultBuilder.cs
...e/Portable/Diagnostics/DiagnosticAnalysisResultBuilder.cs
+2
-1
src/Workspaces/Core/Portable/Workspace/Host/DocumentService/Extensions.cs
...ore/Portable/Workspace/Host/DocumentService/Extensions.cs
+10
-0
src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentOperationService.cs
...rkspace/Host/DocumentService/IDocumentOperationService.cs
+5
-0
src/Workspaces/Core/Portable/Workspace/Solution/DefaultTextDocumentServiceProvider.cs
.../Workspace/Solution/DefaultTextDocumentServiceProvider.cs
+1
-0
未找到文件。
src/Features/Core/Portable/Diagnostics/DiagnosticResultSerializer.cs
浏览文件 @
991018a0
...
...
@@ -5,8 +5,8 @@
using
System.Collections.Immutable
;
using
System.Runtime.CompilerServices
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Diagnostics.Telemetry
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Workspaces.Diagnostics
;
using
Roslyn.Utilities
;
...
...
@@ -77,7 +77,7 @@ internal static class DiagnosticResultSerializer
var
others
=
diagnosticDataSerializer
.
ReadFrom
(
reader
,
project
,
cancellationToken
);
var
analysisResult
=
DiagnosticAnalysisResult
.
CreateFromSerialization
(
project
.
Id
,
project
,
version
,
syntaxLocalMap
,
semanticLocalMap
,
...
...
@@ -143,7 +143,16 @@ internal static class DiagnosticResultSerializer
for
(
var
i
=
0
;
i
<
count
;
i
++)
{
var
documentId
=
DocumentId
.
ReadFrom
(
reader
);
var
diagnostics
=
serializer
.
ReadFrom
(
reader
,
project
.
GetDocument
(
documentId
),
cancellationToken
);
var
document
=
project
.
GetDocument
(
documentId
);
var
diagnostics
=
serializer
.
ReadFrom
(
reader
,
document
,
cancellationToken
);
if
(
document
?.
SupportsDiagnostics
()
==
false
)
{
// drop diagnostics for document that doesn't support
// diagnostics
continue
;
}
map
.
Add
(
documentId
,
GetOrDefault
(
diagnostics
));
}
...
...
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs
浏览文件 @
991018a0
...
...
@@ -7,6 +7,7 @@
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Experimentation
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Shared.Options
;
using
Microsoft.CodeAnalysis.Workspaces.Diagnostics
;
using
Roslyn.Utilities
;
...
...
@@ -82,7 +83,7 @@ public async Task<DiagnosticAnalysisResult> GetAnalysisDataAsync(Project project
// loading data can be cancelled any time.
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
lastResult
.
Version
);
var
builder
=
new
Builder
(
project
.
Id
,
lastResult
.
Version
,
lastResult
.
DocumentIds
);
var
builder
=
new
Builder
(
project
,
lastResult
.
Version
,
lastResult
.
DocumentIds
);
foreach
(
var
documentId
in
lastResult
.
DocumentIds
)
{
...
...
@@ -141,7 +142,7 @@ public async Task<DiagnosticAnalysisResult> GetAnalysisDataAsync(Document docume
// loading data can be cancelled any time.
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
lastResult
.
Version
);
var
builder
=
new
Builder
(
document
.
Project
.
Id
,
lastResult
.
Version
);
var
builder
=
new
Builder
(
document
.
Project
,
lastResult
.
Version
);
if
(!
await
TryDeserializeDocumentAsync
(
serializer
,
document
,
builder
,
cancellationToken
).
ConfigureAwait
(
false
))
{
...
...
@@ -182,7 +183,7 @@ public async Task<DiagnosticAnalysisResult> GetProjectAnalysisDataAsync(Project
// loading data can be cancelled any time.
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
lastResult
.
Version
);
var
builder
=
new
Builder
(
project
.
Id
,
lastResult
.
Version
);
var
builder
=
new
Builder
(
project
,
lastResult
.
Version
);
if
(!
await
TryDeserializeAsync
(
serializer
,
project
,
project
.
Id
,
_owner
.
NonLocalStateName
,
s_addOthers
,
builder
,
cancellationToken
).
ConfigureAwait
(
false
))
{
...
...
@@ -300,7 +301,7 @@ private async Task<DiagnosticAnalysisResult> LoadInitialAnalysisDataAsync(Projec
// loading data can be cancelled any time.
var
version
=
await
GetDiagnosticVersionAsync
(
project
,
cancellationToken
).
ConfigureAwait
(
false
);
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
version
);
var
builder
=
new
Builder
(
project
.
Id
,
version
);
var
builder
=
new
Builder
(
project
,
version
);
foreach
(
var
document
in
project
.
Documents
)
{
...
...
@@ -327,7 +328,7 @@ private async Task<DiagnosticAnalysisResult> LoadInitialAnalysisDataAsync(Docume
var
version
=
await
GetDiagnosticVersionAsync
(
project
,
cancellationToken
).
ConfigureAwait
(
false
);
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
version
);
var
builder
=
new
Builder
(
project
.
Id
,
version
);
var
builder
=
new
Builder
(
project
,
version
);
if
(!
await
TryDeserializeDocumentAsync
(
serializer
,
document
,
builder
,
cancellationToken
).
ConfigureAwait
(
false
))
{
...
...
@@ -342,7 +343,7 @@ private async Task<DiagnosticAnalysisResult> LoadInitialProjectAnalysisDataAsync
// loading data can be cancelled any time.
var
version
=
await
GetDiagnosticVersionAsync
(
project
,
cancellationToken
).
ConfigureAwait
(
false
);
var
serializer
=
new
DiagnosticDataSerializer
(
_owner
.
AnalyzerVersion
,
version
);
var
builder
=
new
Builder
(
project
.
Id
,
version
);
var
builder
=
new
Builder
(
project
,
version
);
if
(!
await
TryDeserializeAsync
(
serializer
,
project
,
project
.
Id
,
_owner
.
NonLocalStateName
,
s_addOthers
,
builder
,
cancellationToken
).
ConfigureAwait
(
false
))
{
...
...
@@ -458,7 +459,7 @@ private bool IsEmpty(DiagnosticAnalysisResult result, DocumentId documentId)
// we have this builder to avoid allocating collections unnecessarily.
private
class
Builder
{
private
readonly
Project
Id
_projectId
;
private
readonly
Project
_project
;
private
readonly
VersionStamp
_version
;
private
readonly
ImmutableHashSet
<
DocumentId
>
_documentIds
;
...
...
@@ -467,9 +468,9 @@ private class Builder
private
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>.
Builder
_nonLocals
;
private
ImmutableArray
<
DiagnosticData
>
_others
;
public
Builder
(
Project
Id
projectId
,
VersionStamp
version
,
ImmutableHashSet
<
DocumentId
>
documentIds
=
null
)
public
Builder
(
Project
project
,
VersionStamp
version
,
ImmutableHashSet
<
DocumentId
>
documentIds
=
null
)
{
_project
Id
=
projectId
;
_project
=
project
;
_version
=
version
;
_documentIds
=
documentIds
;
}
...
...
@@ -496,13 +497,18 @@ public void AddOthers(ProjectId unused, ImmutableArray<DiagnosticData> diagnosti
private
void
Add
(
ref
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>.
Builder
locals
,
DocumentId
documentId
,
ImmutableArray
<
DiagnosticData
>
diagnostics
)
{
if
(
_project
.
GetDocument
(
documentId
)?.
SupportsDiagnostics
()
==
false
)
{
return
;
}
locals
=
locals
??
ImmutableDictionary
.
CreateBuilder
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>();
locals
.
Add
(
documentId
,
diagnostics
);
}
public
DiagnosticAnalysisResult
ToResult
()
{
return
DiagnosticAnalysisResult
.
CreateFromSerialization
(
_project
Id
,
_version
,
return
DiagnosticAnalysisResult
.
CreateFromSerialization
(
_project
,
_version
,
_syntaxLocals
?.
ToImmutable
()
??
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>.
Empty
,
_semanticLocals
?.
ToImmutable
()
??
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>.
Empty
,
_nonLocals
?.
ToImmutable
()
??
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>.
Empty
,
...
...
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs
浏览文件 @
991018a0
...
...
@@ -8,6 +8,7 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Diagnostics.Telemetry
;
using
Microsoft.CodeAnalysis.ErrorReporting
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Remote
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
...
...
@@ -227,7 +228,7 @@ private static bool AnalysisEnabled(Document document)
{
// change it to check active file (or visible files), not open files if active file tracking is enabled.
// otherwise, use open file.
return
document
.
IsOpen
();
return
document
.
IsOpen
()
&&
document
.
SupportsDiagnostics
()
;
}
private
IEnumerable
<
StateSet
>
GetStateSetsForFullSolutionAnalysis
(
IEnumerable
<
StateSet
>
stateSets
,
Project
project
)
...
...
src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs
浏览文件 @
991018a0
// 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.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Host
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Workspaces.Diagnostics
...
...
@@ -100,8 +102,9 @@ public static DiagnosticAnalysisResult CreateFromBuild(Project project, Immutabl
// so we put everything in as semantic local with default version. this lets us to replace those to live diagnostics when needed easily.
var
version
=
VersionStamp
.
Default
;
// filter out any document that doesn't support diagnostics
var
group
=
diagnostics
.
GroupBy
(
d
=>
d
.
DocumentId
);
// filter out any document that doesn't support diagnostics.
// g.Key == null means diagnostics on the project which assigned to "others" error category
var
group
=
diagnostics
.
GroupBy
(
d
=>
d
.
DocumentId
).
Where
(
g
=>
g
.
Key
==
null
||
project
.
GetDocument
(
g
.
Key
).
SupportsDiagnostics
()).
ToList
();
var
result
=
new
DiagnosticAnalysisResult
(
project
.
Id
,
...
...
@@ -117,7 +120,7 @@ public static DiagnosticAnalysisResult CreateFromBuild(Project project, Immutabl
}
public
static
DiagnosticAnalysisResult
CreateFromSerialization
(
Project
Id
projectId
,
Project
project
,
VersionStamp
version
,
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>
syntaxLocalMap
,
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>
semanticLocalMap
,
...
...
@@ -125,8 +128,12 @@ public static DiagnosticAnalysisResult CreateFromBuild(Project project, Immutabl
ImmutableArray
<
DiagnosticData
>
others
,
ImmutableHashSet
<
DocumentId
>
documentIds
=
null
)
{
VerifyDocumentMap
(
project
,
syntaxLocalMap
);
VerifyDocumentMap
(
project
,
semanticLocalMap
);
VerifyDocumentMap
(
project
,
nonLocalMap
);
return
new
DiagnosticAnalysisResult
(
projectId
,
project
.
Id
,
version
,
syntaxLocalMap
,
semanticLocalMap
,
...
...
@@ -139,7 +146,7 @@ public static DiagnosticAnalysisResult CreateFromBuild(Project project, Immutabl
public
static
DiagnosticAnalysisResult
CreateFromBuilder
(
DiagnosticAnalysisResultBuilder
builder
)
{
return
CreateFromSerialization
(
builder
.
Project
.
Id
,
builder
.
Project
,
builder
.
Version
,
builder
.
SyntaxLocals
,
builder
.
SemanticLocals
,
...
...
@@ -233,5 +240,14 @@ private ImmutableHashSet<DocumentId> CreateDocumentIds()
return
ImmutableHashSet
.
CreateRange
(
documents
);
}
[
Conditional
(
"DEBUG"
)]
private
static
void
VerifyDocumentMap
(
Project
project
,
ImmutableDictionary
<
DocumentId
,
ImmutableArray
<
DiagnosticData
>>
map
)
{
foreach
(
var
documentId
in
map
.
Keys
)
{
Debug
.
Assert
(
project
.
GetDocument
(
documentId
)?.
SupportsDiagnostics
()
==
true
);
}
}
}
}
src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResultBuilder.cs
浏览文件 @
991018a0
...
...
@@ -5,6 +5,7 @@
using
System.Diagnostics
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Host
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Workspaces.Diagnostics
...
...
@@ -112,7 +113,7 @@ public void AddExternalSemanticDiagnostics(DocumentId documentId, IEnumerable<Di
private
void
AppendDiagnostics
(
ref
Dictionary
<
DocumentId
,
List
<
DiagnosticData
>>
map
,
Document
documentOpt
,
Diagnostic
diagnostic
)
{
if
(
documentOpt
is
null
)
if
(
documentOpt
?.
SupportsDiagnostics
()
==
false
)
{
return
;
}
...
...
src/Workspaces/Core/Portable/Workspace/Host/DocumentService/Extensions.cs
浏览文件 @
991018a0
...
...
@@ -13,5 +13,15 @@ public static bool CanApplyChange(this TextDocumentState document)
{
return
document
?.
Services
.
GetService
<
IDocumentOperationService
>().
CanApplyChange
??
false
;
}
public
static
bool
SupportsDiagnostics
(
this
TextDocument
document
)
{
return
document
?.
State
.
SupportsDiagnostics
()
??
false
;
}
public
static
bool
SupportsDiagnostics
(
this
TextDocumentState
document
)
{
return
document
?.
Services
.
GetService
<
IDocumentOperationService
>().
SupportDiagnostics
??
false
;
}
}
}
src/Workspaces/Core/Portable/Workspace/Host/DocumentService/IDocumentOperationService.cs
浏览文件 @
991018a0
...
...
@@ -13,5 +13,10 @@ internal interface IDocumentOperationService : IDocumentService
/// document version of <see cref="Workspace.CanApplyChange(ApplyChangesKind)"/>
/// </summary>
bool
CanApplyChange
{
get
;
}
/// <summary>
/// indicates whether this document supports diagnostics or not
/// </summary>
bool
SupportDiagnostics
{
get
;
}
}
}
src/Workspaces/Core/Portable/Workspace/Solution/DefaultTextDocumentServiceProvider.cs
浏览文件 @
991018a0
...
...
@@ -40,6 +40,7 @@ private class DocumentOperationService : IDocumentOperationService
// even support rename through IDynamicFileInfoProvider pattern once we address that in next
// iteration for razor. for now, we keep existing behavior
public
bool
CanApplyChange
=>
true
;
public
bool
SupportDiagnostics
=>
true
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录