Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d83c3e60
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,发现更多精彩内容 >>
提交
d83c3e60
编写于
2月 20, 2015
作者:
T
Tomas Matousek
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #764 from tmat/AddFilter
Add filter
上级
1066b9d4
10722b9f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
65 deletion
+73
-65
src/Features/Core/SolutionCrawler/AbstractDocumentDifferenceService.cs
...Core/SolutionCrawler/AbstractDocumentDifferenceService.cs
+73
-65
未找到文件。
src/Features/Core/SolutionCrawler/AbstractDocumentDifferenceService.cs
浏览文件 @
d83c3e60
...
...
@@ -7,9 +7,11 @@
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.ErrorReporting
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.SolutionCrawler
{
...
...
@@ -17,89 +19,95 @@ internal abstract class AbstractDocumentDifferenceService : IDocumentDifferenceS
{
public
async
Task
<
DocumentDifferenceResult
>
GetDifferenceAsync
(
Document
oldDocument
,
Document
newDocument
,
CancellationToken
cancellationToken
)
{
var
syntaxFactsService
=
newDocument
.
Project
.
LanguageServices
.
GetService
<
ISyntaxFactsService
>();
if
(
syntaxFactsService
==
null
)
try
{
// somehow, we can't get the service. without it, there is nothing we can do.
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
var
syntaxFactsService
=
newDocument
.
Project
.
LanguageServices
.
GetService
<
ISyntaxFactsService
>();
if
(
syntaxFactsService
==
null
)
{
// somehow, we can't get the service. without it, there is nothing we can do.
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
// this is based on the implementation detail where opened documents use strong references
// to tree and text rather than recoverable versions.
SourceText
oldText
;
SourceText
newText
;
if
(!
oldDocument
.
TryGetText
(
out
oldText
)
||
!
newDocument
.
TryGetText
(
out
newText
))
{
// no cheap way to determine top level changes. assumes top level has changed
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
// this is based on the implementation detail where opened documents use strong references
// to tree and text rather than recoverable versions.
SourceText
oldText
;
SourceText
newText
;
if
(!
oldDocument
.
TryGetText
(
out
oldText
)
||
!
newDocument
.
TryGetText
(
out
newText
))
{
// no cheap way to determine top level changes. assumes top level has changed
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
// quick check whether two tree versions are same
VersionStamp
oldVersion
;
VersionStamp
newVersion
;
if
(
oldDocument
.
TryGetSyntaxVersion
(
out
oldVersion
)
&&
newDocument
.
TryGetSyntaxVersion
(
out
newVersion
)
&&
oldVersion
.
Equals
(
newVersion
))
{
// nothing has changed. don't do anything.
// this could happen if a document is opened/closed without any buffer change
return
null
;
}
// quick check whether two tree versions are same
VersionStamp
oldVersion
;
VersionStamp
newVersion
;
if
(
oldDocument
.
TryGetSyntaxVersion
(
out
oldVersion
)
&&
newDocument
.
TryGetSyntaxVersion
(
out
newVersion
)
&&
oldVersion
.
Equals
(
newVersion
))
{
// nothing has changed. don't do anything.
// this could happen if a document is opened/closed without any buffer change
return
null
;
}
var
range
=
newText
.
GetEncompassingTextChangeRange
(
oldText
);
if
(
range
==
default
(
TextChangeRange
))
{
// nothing has changed. don't do anything
return
null
;
}
var
range
=
newText
.
GetEncompassingTextChangeRange
(
oldText
);
if
(
range
==
default
(
TextChangeRange
))
{
// nothing has changed. don't do anything
return
null
;
}
var
incrementalParsingCandidate
=
range
.
NewLength
!=
newText
.
Length
;
var
incrementalParsingCandidate
=
range
.
NewLength
!=
newText
.
Length
;
// see whether we can get it without explicit parsing
SyntaxNode
oldRoot
;
SyntaxNode
newRoot
;
if
(!
oldDocument
.
TryGetSyntaxRoot
(
out
oldRoot
)
||
!
newDocument
.
TryGetSyntaxRoot
(
out
newRoot
))
{
if
(!
incrementalParsingCandidate
)
// see whether we can get it without explicit parsing
SyntaxNode
oldRoot
;
SyntaxNode
newRoot
;
if
(!
oldDocument
.
TryGetSyntaxRoot
(
out
oldRoot
)
||
!
newDocument
.
TryGetSyntaxRoot
(
out
newRoot
))
{
// no cheap way to determine top level changes. assumes top level has changed
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
if
(!
incrementalParsingCandidate
)
{
// no cheap way to determine top level changes. assumes top level has changed
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
// explicitly parse them
oldRoot
=
await
oldDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
continueOnCapturedContext
:
false
);
newRoot
=
await
newDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
continueOnCapturedContext
:
false
);
}
// explicitly parse them
oldRoot
=
await
oldDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
continueOnCapturedContext
:
false
);
newRoot
=
await
newDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
continueOnCapturedContext
:
false
);
}
// at this point, we must have these version already calculated
VersionStamp
oldTopLevelChangeVersion
;
VersionStamp
newTopLevelChangeVersion
;
if
(!
oldDocument
.
TryGetTopLevelChangeTextVersion
(
out
oldTopLevelChangeVersion
)
||
!
newDocument
.
TryGetTopLevelChangeTextVersion
(
out
newTopLevelChangeVersion
))
{
throw
ExceptionUtilities
.
Unreachable
;
}
// at this point, we must have these version already calculated
VersionStamp
oldTopLevelChangeVersion
;
VersionStamp
newTopLevelChangeVersion
;
if
(!
oldDocument
.
TryGetTopLevelChangeTextVersion
(
out
oldTopLevelChangeVersion
)
||
!
newDocument
.
TryGetTopLevelChangeTextVersion
(
out
newTopLevelChangeVersion
))
{
Debug
.
Fail
(
"How?"
);
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
// quicker common case
if
(
incrementalParsingCandidate
)
{
if
(
oldTopLevelChangeVersion
.
Equals
(
newTopLevelChangeVersion
))
{
return
new
DocumentDifferenceResult
(
InvocationReasons
.
SyntaxChanged
,
GetChangedMember
(
syntaxFactsService
,
oldRoot
,
newRoot
,
range
));
}
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
,
GetBestGuessChangedMember
(
syntaxFactsService
,
oldRoot
,
newRoot
,
range
));
}
// quicker common case
if
(
incrementalParsingCandidate
)
{
if
(
oldTopLevelChangeVersion
.
Equals
(
newTopLevelChangeVersion
))
{
return
new
DocumentDifferenceResult
(
InvocationReasons
.
SyntaxChanged
,
GetChangedMember
(
syntaxFactsService
,
oldRoot
,
newRoot
,
range
)
);
return
new
DocumentDifferenceResult
(
InvocationReasons
.
SyntaxChanged
);
}
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
,
GetBestGuessChangedMember
(
syntaxFactsService
,
oldRoot
,
newRoot
,
range
)
);
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
if
(
oldTopLevelChangeVersion
.
Equals
(
newTopLevelChangeVersion
))
catch
(
Exception
e
)
when
(
FatalError
.
ReportUnlessCanceled
(
e
))
{
return
new
DocumentDifferenceResult
(
InvocationReasons
.
SyntaxChanged
)
;
throw
ExceptionUtilities
.
Unreachable
;
}
return
new
DocumentDifferenceResult
(
InvocationReasons
.
DocumentChanged
);
}
private
static
SyntaxNode
GetChangedMember
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录