Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
9fc80d30
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
9fc80d30
编写于
5月 23, 2017
作者:
H
Heejae Chang
提交者:
GitHub
5月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19561 from heejaechang/fsharpbuild
tweak how we merge build and live errors for language such as F#
上级
52076203
c32a0ef5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
95 addition
and
2 deletion
+95
-2
src/EditorFeatures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs
...atures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs
+87
-2
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs
...cs/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs
+8
-0
未找到文件。
src/EditorFeatures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs
浏览文件 @
9fc80d30
...
...
@@ -5,9 +5,11 @@
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.Shared.TestHooks
;
using
Microsoft.CodeAnalysis.SolutionCrawler
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.VisualStudio.Composition
;
using
Roslyn.Test.Utilities
;
using
Roslyn.Utilities
;
using
Xunit
;
...
...
@@ -138,6 +140,71 @@ public async Task TestOpenFileOnlyAnalyzerDiagnostics()
await
listener
.
CreateWaitTask
().
ConfigureAwait
(
false
);
}
[
Fact
]
public
async
Task
TestSynchronizeWithBuild
()
{
var
workspace
=
new
AdhocWorkspace
(
MefV1HostServices
.
Create
(
TestExportProvider
.
ExportProviderWithCSharpAndVisualBasic
.
AsExportProvider
()));
var
language
=
Workspaces
.
NoCompilationConstants
.
LanguageName
;
var
project
=
workspace
.
AddProject
(
ProjectInfo
.
Create
(
ProjectId
.
CreateNewId
(),
VersionStamp
.
Create
(),
"NoNameProject"
,
"NoNameProject"
,
language
));
var
filePath
=
"NoNameDoc.other"
;
var
document
=
workspace
.
AddDocument
(
DocumentInfo
.
Create
(
DocumentId
.
CreateNewId
(
project
.
Id
),
"Empty"
,
loader
:
TextLoader
.
From
(
TextAndVersion
.
Create
(
SourceText
.
From
(
""
),
VersionStamp
.
Create
(),
filePath
)),
filePath
:
filePath
));
// create listener/service/analyzer
var
listener
=
new
AsynchronousOperationListener
();
var
service
=
new
MyDiagnosticAnalyzerService
(
new
NoNameAnalyzer
(),
listener
,
language
);
var
analyzer
=
service
.
CreateIncrementalAnalyzer
(
workspace
);
bool
syntax
=
false
;
// listen to events
service
.
DiagnosticsUpdated
+=
(
s
,
a
)
=>
{
switch
(
a
.
Diagnostics
.
Length
)
{
case
0
:
return
;
case
1
:
syntax
|=
a
.
Diagnostics
[
0
].
Id
==
NoNameAnalyzer
.
s_syntaxRule
.
Id
;
return
;
default
:
AssertEx
.
Fail
(
"shouldn't reach here"
);
return
;
}
};
// cause analysis
await
service
.
SynchronizeWithBuildAsync
(
workspace
,
ImmutableDictionary
<
ProjectId
,
ImmutableArray
<
DiagnosticData
>>.
Empty
.
Add
(
document
.
Project
.
Id
,
ImmutableArray
.
Create
(
Diagnostic
.
Create
(
NoNameAnalyzer
.
s_syntaxRule
,
Location
.
Create
(
document
.
FilePath
,
TextSpan
.
FromBounds
(
0
,
0
),
new
LinePositionSpan
(
new
LinePosition
(
0
,
0
),
new
LinePosition
(
0
,
0
)))).
ToDiagnosticData
(
project
))));
// wait for all events to raised
await
listener
.
CreateWaitTask
().
ConfigureAwait
(
false
);
// two should have been called.
Assert
.
True
(
syntax
);
// we should reach here without crashing
}
private
static
Document
GetDocumentFromIncompleteProject
(
AdhocWorkspace
workspace
)
{
var
project
=
workspace
.
AddProject
(
...
...
@@ -160,11 +227,11 @@ private static async Task RunAllAnalysisAsync(IIncrementalAnalyzer analyzer, Doc
private
class
MyDiagnosticAnalyzerService
:
DiagnosticAnalyzerService
{
internal
MyDiagnosticAnalyzerService
(
DiagnosticAnalyzer
analyzer
,
IAsynchronousOperationListener
listener
)
internal
MyDiagnosticAnalyzerService
(
DiagnosticAnalyzer
analyzer
,
IAsynchronousOperationListener
listener
,
string
language
=
LanguageNames
.
CSharp
)
:
base
(
new
HostAnalyzerManager
(
ImmutableArray
.
Create
<
AnalyzerReference
>(
new
TestAnalyzerReferenceByLanguage
(
ImmutableDictionary
<
string
,
ImmutableArray
<
DiagnosticAnalyzer
>>.
Empty
.
Add
(
LanguageNames
.
CSharp
,
ImmutableArray
.
Create
(
analyzer
)))),
ImmutableDictionary
<
string
,
ImmutableArray
<
DiagnosticAnalyzer
>>.
Empty
.
Add
(
language
,
ImmutableArray
.
Create
(
analyzer
)))),
hostDiagnosticUpdateSource
:
null
),
hostDiagnosticUpdateSource
:
null
,
registrationService
:
new
MockDiagnosticUpdateSourceRegistrationService
(),
...
...
@@ -210,5 +277,23 @@ public bool OpenFileOnly(Workspace workspace)
return
true
;
}
}
private
class
NoNameAnalyzer
:
DocumentDiagnosticAnalyzer
{
internal
static
readonly
DiagnosticDescriptor
s_syntaxRule
=
new
DiagnosticDescriptor
(
"syntax"
,
"test"
,
"test"
,
"test"
,
DiagnosticSeverity
.
Error
,
isEnabledByDefault
:
true
);
public
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
s_syntaxRule
);
public
override
async
Task
<
ImmutableArray
<
Diagnostic
>>
AnalyzeSyntaxAsync
(
Document
document
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
ImmutableArray
.
Create
(
Diagnostic
.
Create
(
s_syntaxRule
,
Location
.
Create
(
document
.
FilePath
,
TextSpan
.
FromBounds
(
0
,
0
),
new
LinePositionSpan
(
new
LinePosition
(
0
,
0
),
new
LinePosition
(
0
,
0
)))));
}
public
override
Task
<
ImmutableArray
<
Diagnostic
>>
AnalyzeSemanticsAsync
(
Document
document
,
CancellationToken
cancellationToken
)
{
return
SpecializedTasks
.
Default
<
ImmutableArray
<
Diagnostic
>>();
}
}
}
}
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs
浏览文件 @
9fc80d30
...
...
@@ -122,6 +122,14 @@ public StateSet GetOrCreateStateSet(Project project, DiagnosticAnalyzer analyzer
/// </summary>
public
ImmutableArray
<
StateSet
>
CreateBuildOnlyProjectStateSet
(
Project
project
)
{
if
(!
project
.
SupportsCompilation
)
{
// languages which don't use our compilation model but diagnostic framework,
// all their analyzer should be host analyzers. return all host analyzers
// for the language
return
_hostStates
.
GetOrCreateStateSets
(
project
.
Language
).
ToImmutableArray
();
}
// create project analyzer reference identity map
var
referenceIdentities
=
project
.
AnalyzerReferences
.
Select
(
r
=>
_analyzerManager
.
GetAnalyzerReferenceIdentity
(
r
)).
ToSet
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录