Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2b14447d
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,发现更多精彩内容 >>
提交
2b14447d
编写于
3月 16, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unify tests
上级
184b238e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
119 addition
and
133 deletion
+119
-133
src/EditorFeatures/CSharpTest/TodoComment/TodoCommentTests.cs
...EditorFeatures/CSharpTest/TodoComment/TodoCommentTests.cs
+5
-51
src/EditorFeatures/TestUtilities/TodoComments/AbtractTodoCommentTests.cs
...res/TestUtilities/TodoComments/AbtractTodoCommentTests.cs
+56
-0
src/EditorFeatures/VisualBasicTest/TodoComment/TodoCommentTests.vb
...rFeatures/VisualBasicTest/TodoComment/TodoCommentTests.vb
+9
-46
src/Features/Core/Portable/TodoComments/ITodoCommentService.cs
...eatures/Core/Portable/TodoComments/ITodoCommentService.cs
+28
-0
src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs
...Studio/Core/Test.Next/Services/ServiceHubServicesTests.cs
+1
-1
src/VisualStudio/Core/Test/Diagnostics/TodoListTableDataSourceTests.vb
...dio/Core/Test/Diagnostics/TodoListTableDataSourceTests.vb
+18
-7
src/Workspaces/Core/Portable/TodoComments/TodoCommentInfo.cs
src/Workspaces/Core/Portable/TodoComments/TodoCommentInfo.cs
+0
-1
src/Workspaces/Remote/ServiceHub/Services/TodoComments/RemoteTodoCommentsIncrementalAnalyzer.cs
...ces/TodoComments/RemoteTodoCommentsIncrementalAnalyzer.cs
+1
-26
src/Workspaces/Remote/ServiceHub/Services/TodoComments/RemoteTodoCommentsIncrementalAnalyzerProvider.cs
...Comments/RemoteTodoCommentsIncrementalAnalyzerProvider.cs
+1
-1
未找到文件。
src/EditorFeatures/CSharpTest/TodoComment/TodoCommentTests.cs
浏览文件 @
2b14447d
...
...
@@ -2,25 +2,20 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Editor.Implementation.TodoComments
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.SolutionCrawler
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.CodeAnalysis.Test.Utilities.RemoteHost
;
using
Microsoft.CodeAnalysis.Text.Shared.Extensions
;
using
Roslyn.Utilities
;
using
Microsoft.CodeAnalysis.Test.Utilities.TodoComments
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.TodoComment
{
[
UseExportProvider
]
public
class
TodoCommentTests
public
class
TodoCommentTests
:
AbstractTodoCommentTests
{
protected
override
TestWorkspace
CreateWorkspace
(
string
codeWithMarker
)
=>
TestWorkspace
.
CreateCSharp
(
codeWithMarker
);
[
Fact
]
public
async
Task
SingleLineTodoComment_Colon
()
{
...
...
@@ -170,46 +165,5 @@ public async Task SinglelineDocumentComment_Multiline()
await
TestAsync
(
code
);
}
private
static
async
Task
TestAsync
(
string
codeWithMarker
)
{
await
TestAsync
(
codeWithMarker
,
remote
:
false
);
await
TestAsync
(
codeWithMarker
,
remote
:
true
);
}
private
static
async
Task
TestAsync
(
string
codeWithMarker
,
bool
remote
)
{
using
var
workspace
=
TestWorkspace
.
CreateCSharp
(
codeWithMarker
,
openDocuments
:
false
);
workspace
.
TryApplyChanges
(
workspace
.
CurrentSolution
.
WithOptions
(
workspace
.
Options
.
WithChangedOption
(
RemoteHostOptions
.
RemoteHostTest
,
remote
)));
var
commentTokens
=
new
TodoCommentTokens
();
var
provider
=
new
TodoCommentIncrementalAnalyzerProvider
(
commentTokens
,
Array
.
Empty
<
Lazy
<
IEventListener
,
EventListenerMetadata
>>());
var
worker
=
(
TodoCommentIncrementalAnalyzer
)
provider
.
CreateIncrementalAnalyzer
(
workspace
);
var
document
=
workspace
.
Documents
.
First
();
var
initialTextSnapshot
=
document
.
GetTextBuffer
().
CurrentSnapshot
;
var
documentId
=
document
.
Id
;
var
reasons
=
new
InvocationReasons
(
PredefinedInvocationReasons
.
DocumentAdded
);
await
worker
.
AnalyzeSyntaxAsync
(
workspace
.
CurrentSolution
.
GetDocument
(
documentId
),
InvocationReasons
.
Empty
,
CancellationToken
.
None
);
var
todoLists
=
worker
.
GetItems_TestingOnly
(
documentId
);
var
expectedLists
=
document
.
SelectedSpans
;
Assert
.
Equal
(
todoLists
.
Length
,
expectedLists
.
Count
);
for
(
var
i
=
0
;
i
<
todoLists
.
Length
;
i
++)
{
var
todo
=
todoLists
[
i
];
var
span
=
expectedLists
[
i
];
var
line
=
initialTextSnapshot
.
GetLineFromPosition
(
span
.
Start
);
var
text
=
initialTextSnapshot
.
GetText
(
span
.
ToSpan
());
Assert
.
Equal
(
todo
.
MappedLine
,
line
.
LineNumber
);
Assert
.
Equal
(
todo
.
MappedColumn
,
span
.
Start
-
line
.
Start
);
Assert
.
Equal
(
todo
.
Message
,
text
);
}
}
}
}
src/EditorFeatures/TestUtilities/TodoComments/AbtractTodoCommentTests.cs
0 → 100644
浏览文件 @
2b14447d
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Editor.Implementation.TodoComments
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text.Shared.Extensions
;
using
Microsoft.CodeAnalysis.TodoComments
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Test.Utilities.TodoComments
{
public
abstract
class
AbstractTodoCommentTests
{
protected
abstract
TestWorkspace
CreateWorkspace
(
string
codeWithMarker
);
protected
async
Task
TestAsync
(
string
codeWithMarker
)
{
using
var
workspace
=
CreateWorkspace
(
codeWithMarker
);
var
hostDocument
=
workspace
.
Documents
.
First
();
var
initialTextSnapshot
=
hostDocument
.
GetTextBuffer
().
CurrentSnapshot
;
var
documentId
=
hostDocument
.
Id
;
var
document
=
workspace
.
CurrentSolution
.
GetDocument
(
documentId
);
var
service
=
document
.
GetLanguageService
<
ITodoCommentService
>();
var
todoLists
=
await
service
.
GetTodoCommentsAsync
(
document
,
TodoCommentDescriptor
.
Parse
(
TodoCommentOptions
.
TokenList
.
DefaultValue
),
CancellationToken
.
None
);
var
expectedLists
=
hostDocument
.
SelectedSpans
;
Assert
.
Equal
(
todoLists
.
Length
,
expectedLists
.
Count
);
var
sourceText
=
await
document
.
GetTextAsync
();
var
tree
=
await
document
.
GetSyntaxTreeAsync
();
for
(
var
i
=
0
;
i
<
todoLists
.
Length
;
i
++)
{
var
todo
=
todoLists
[
i
];
var
span
=
expectedLists
[
i
];
var
line
=
initialTextSnapshot
.
GetLineFromPosition
(
span
.
Start
);
var
text
=
initialTextSnapshot
.
GetText
(
span
.
ToSpan
());
var
converted
=
todo
.
Convert
(
document
,
sourceText
,
tree
);
Assert
.
Equal
(
converted
.
MappedLine
,
line
.
LineNumber
);
Assert
.
Equal
(
converted
.
MappedColumn
,
span
.
Start
-
line
.
Start
);
Assert
.
Equal
(
converted
.
Message
,
text
);
}
}
}
}
src/EditorFeatures/VisualBasicTest/TodoComment/TodoCommentTests.vb
浏览文件 @
2b14447d
...
...
@@ -2,20 +2,19 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports
System.Collections.Immutable
Imports
System.Threading
Imports
Microsoft.CodeAnalysis
Imports
Microsoft.CodeAnalysis.Editor.Implementation.TodoComments
Imports
Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
Imports
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports
Microsoft.CodeAnalysis.Host
Imports
Microsoft.CodeAnalysis.SolutionCrawler
Imports
Microsoft.CodeAnalysis.Test.Utilities.RemoteHost
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.Test.Utilities.TodoComments
Namespace
Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.TodoComment
<
[
UseExportProvider
]
>
Public
Class
TodoCommentTests
Inherits
AbstractTodoCommentTests
Protected
Overrides
Function
CreateWorkspace
(
codeWithMarker
As
String
)
As
TestWorkspace
Return
TestWorkspace
.
CreateVisualBasic
(
codeWithMarker
)
End
Function
<
Fact
>
Public
Async
Function
TestSingleLineTodoComment_Colon
()
As
Task
Dim
code
=
<
code
>
' [|TODO:test|]</code>
...
...
@@ -172,44 +171,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.TodoComment
Await
TestAsync
(
code
)
End
Function
Private
Shared
Async
Function
TestAsync
(
codeWithMarker
As
XElement
)
As
Tasks
.
Task
Await
TestAsync
(
codeWithMarker
,
remote
:
=
False
)
Await
TestAsync
(
codeWithMarker
,
remote
:
=
True
)
End
Function
Private
Shared
Async
Function
TestAsync
(
codeWithMarker
As
XElement
,
remote
As
Boolean
)
As
Task
Dim
code
As
String
=
Nothing
Dim
list
As
ImmutableArray
(
Of
TextSpan
)
=
Nothing
MarkupTestFile
.
GetSpans
(
codeWithMarker
.
NormalizedValue
,
code
,
list
)
Using
workspace
=
TestWorkspace
.
CreateVisualBasic
(
code
,
openDocuments
:
=
False
)
workspace
.
TryApplyChanges
(
workspace
.
CurrentSolution
.
WithOptions
(
workspace
.
Options
_
.
WithChangedOption
(
RemoteHostOptions
.
RemoteHostTest
,
remote
)))
Dim
commentTokens
=
New
TodoCommentTokens
()
Dim
provider
=
New
TodoCommentIncrementalAnalyzerProvider
(
commentTokens
,
Array
.
Empty
(
Of
Lazy
(
Of
IEventListener
,
EventListenerMetadata
))())
Dim
worker
=
DirectCast
(
provider
.
CreateIncrementalAnalyzer
(
workspace
),
TodoCommentIncrementalAnalyzer
)
Dim
document
=
workspace
.
Documents
.
First
()
Dim
initialTextSnapshot
=
document
.
GetTextBuffer
().
CurrentSnapshot
Dim
documentId
=
document
.
Id
Await
worker
.
AnalyzeSyntaxAsync
(
workspace
.
CurrentSolution
.
GetDocument
(
documentId
),
InvocationReasons
.
Empty
,
CancellationToken
.
None
)
Dim
todoLists
=
worker
.
GetItems_TestingOnly
(
documentId
)
Assert
.
Equal
(
todoLists
.
Count
,
list
.
Count
)
For
i
=
0
To
todoLists
.
Count
-
1
Step
1
Dim
todo
=
todoLists
(
i
)
Dim
span
=
list
(
i
)
Dim
line
=
initialTextSnapshot
.
GetLineFromPosition
(
span
.
Start
)
Assert
.
Equal
(
todo
.
MappedLine
,
line
.
LineNumber
)
Assert
.
Equal
(
todo
.
MappedColumn
,
span
.
Start
-
line
.
Start
.
Position
)
Assert
.
Equal
(
todo
.
Message
,
code
.
Substring
(
span
.
Start
,
span
.
Length
))
Next
End
Using
Private
Overloads
Function
TestAsync
(
codeWithMarker
As
XElement
)
As
Task
Return
TestAsync
(
codeWithMarker
.
NormalizedValue
())
End
Function
End
Class
End
Namespace
src/Features/Core/Portable/TodoComments/ITodoCommentService.cs
浏览文件 @
2b14447d
...
...
@@ -2,10 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Collections.Immutable
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
namespace
Microsoft.CodeAnalysis.TodoComments
{
...
...
@@ -24,6 +27,31 @@ public TodoComment(TodoCommentDescriptor descriptor, string message, int positio
Message
=
message
;
Position
=
position
;
}
internal
TodoCommentInfo
Convert
(
Document
document
,
SourceText
text
,
SyntaxTree
tree
)
{
// make sure given position is within valid text range.
var
textSpan
=
new
TextSpan
(
Math
.
Min
(
text
.
Length
,
Math
.
Max
(
0
,
this
.
Position
)),
0
);
var
location
=
tree
.
GetLocation
(
textSpan
);
// var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan);
var
originalLineInfo
=
location
.
GetLineSpan
();
var
mappedLineInfo
=
location
.
GetMappedLineSpan
();
return
new
TodoCommentInfo
{
Priority
=
this
.
Descriptor
.
Priority
,
Message
=
this
.
Message
,
DocumentId
=
document
.
Id
,
OriginalLine
=
originalLineInfo
.
StartLinePosition
.
Line
,
OriginalColumn
=
originalLineInfo
.
StartLinePosition
.
Character
,
OriginalFilePath
=
document
.
FilePath
,
MappedLine
=
mappedLineInfo
.
StartLinePosition
.
Line
,
MappedColumn
=
mappedLineInfo
.
StartLinePosition
.
Character
,
MappedFilePath
=
mappedLineInfo
.
GetMappedFilePathIfExist
(),
};
}
}
internal
interface
ITodoCommentService
:
ILanguageService
...
...
src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs
浏览文件 @
2b14447d
...
...
@@ -146,7 +146,7 @@ public async Task TestTodoComments()
var
comments
=
await
client
.
TryRunRemoteAsync
<
IList
<
TodoComment
>>(
WellKnownServiceHubServices
.
CodeAnalysisService
,
nameof
(
IRemoteTodoCommentsService
.
Get
TodoCommentsAsync
),
nameof
(
IRemoteTodoCommentsService
.
Compute
TodoCommentsAsync
),
solution
,
new
object
[]
{
solution
.
Projects
.
First
().
DocumentIds
.
First
(),
ImmutableArray
.
Create
(
new
TodoCommentDescriptor
(
"TODO"
,
0
))
},
callbackTarget
:
null
,
...
...
src/VisualStudio/Core/Test/Diagnostics/TodoListTableDataSourceTests.vb
浏览文件 @
2b14447d
...
...
@@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Common
Imports
Microsoft.CodeAnalysis.Editor
Imports
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports
Microsoft.CodeAnalysis.Test.Utilities
Imports
Microsoft.CodeAnalysis.TodoComments
Imports
Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource
Imports
Microsoft.VisualStudio.Shell.TableManager
Imports
Roslyn.Test.Utilities
...
...
@@ -83,11 +84,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
Dim
sink
=
DirectCast
(
sinkAndSubscription
.
Key
,
TestTableManagerProvider
.
TestTableManager
.
TestSink
)
provider
.
Items
=
New
Todo
Item
()
{
CreateItem
(
documentId
)}
provider
.
Items
=
New
Todo
CommentInfo
()
{
CreateItem
(
documentId
)}
provider
.
RaiseTodoListUpdated
(
workspace
)
Assert
.
Equal
(
1
,
sink
.
Entries
.
Count
)
provider
.
Items
=
Array
.
Empty
(
Of
Todo
Item
)()
provider
.
Items
=
Array
.
Empty
(
Of
Todo
CommentInfo
)()
provider
.
RaiseClearTodoListUpdated
(
workspace
,
documentId
)
Assert
.
Equal
(
0
,
sink
.
Entries
.
Count
)
End
Using
...
...
@@ -267,9 +268,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
Dim
factory
=
TryCast
(
sink
.
Entries
.
First
(),
TableEntriesFactory
(
Of
TodoTableItem
))
Dim
snapshot1
=
factory
.
GetCurrentSnapshot
()
provider
.
Items
=
New
Todo
Item
()
{
New
Todo
Item
(
1
,
"test2"
,
documentId
,
11
,
11
,
21
,
21
,
Nothing
,
"test2"
),
New
Todo
Item
(
0
,
"test3"
,
documentId
,
11
,
11
,
21
,
21
,
Nothing
,
"test3"
)}
provider
.
Items
=
New
Todo
CommentInfo
()
{
New
Todo
CommentInfo
(
1
,
"test2"
,
documentId
,
11
,
11
,
21
,
21
,
Nothing
,
"test2"
),
New
Todo
CommentInfo
(
0
,
"test3"
,
documentId
,
11
,
11
,
21
,
21
,
Nothing
,
"test3"
)}
provider
.
RaiseTodoListUpdated
(
workspace
)
...
...
@@ -356,8 +357,18 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
End
Using
End
Sub
Private
Function
CreateItem
(
documentId
As
DocumentId
)
As
TodoItem
Return
New
TodoItem
(
0
,
"test"
,
documentId
,
10
,
10
,
20
,
20
,
Nothing
,
"test1"
)
Private
Function
CreateItem
(
documentId
As
DocumentId
)
As
TodoCommentInfo
Return
New
TodoCommentInfo
With
{
.
Priority
=
0
,
.
Message
=
"test"
,
.
DocumentId
=
documentId
,
.
MappedLine
=
10
,
.
OriginalLine
=
10
,
.
MappedColumn
=
20
,
.
OriginalColumn
=
20
,
.
MappedFilePath
=
Nothing
,
.
OriginalFilePath
=
"test1"
}
End
Function
Private
Class
TestTodoListProvider
...
...
src/Workspaces/Core/Portable/TodoComments/TodoCommentInfo.cs
浏览文件 @
2b14447d
...
...
@@ -5,7 +5,6 @@
#
nullable
enable
using
System
;
using
System.Collections.Immutable
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Roslyn.Utilities
;
...
...
src/Workspaces/Remote/ServiceHub/Services/TodoComments/RemoteTodoCommentsIncrementalAnalyzer.cs
浏览文件 @
2b14447d
...
...
@@ -88,32 +88,7 @@ public override async Task AnalyzeSyntaxAsync(Document document, InvocationReaso
var
syntaxTree
=
await
document
.
GetRequiredSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
foreach
(
var
comment
in
todoComments
)
converted
.
Add
(
Convert
(
document
,
sourceText
,
syntaxTree
,
comment
));
}
private
TodoCommentInfo
Convert
(
Document
document
,
SourceText
text
,
SyntaxTree
tree
,
TodoComment
comment
)
{
// make sure given position is within valid text range.
var
textSpan
=
new
TextSpan
(
Math
.
Min
(
text
.
Length
,
Math
.
Max
(
0
,
comment
.
Position
)),
0
);
var
location
=
tree
.
GetLocation
(
textSpan
);
// var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan);
var
originalLineInfo
=
location
.
GetLineSpan
();
var
mappedLineInfo
=
location
.
GetMappedLineSpan
();
return
new
TodoCommentInfo
{
Priority
=
comment
.
Descriptor
.
Priority
,
Message
=
comment
.
Message
,
DocumentId
=
document
.
Id
,
OriginalLine
=
originalLineInfo
.
StartLinePosition
.
Line
,
OriginalColumn
=
originalLineInfo
.
StartLinePosition
.
Character
,
OriginalFilePath
=
document
.
FilePath
,
MappedLine
=
mappedLineInfo
.
StartLinePosition
.
Line
,
MappedColumn
=
mappedLineInfo
.
StartLinePosition
.
Character
,
MappedFilePath
=
mappedLineInfo
.
GetMappedFilePathIfExist
(),
};
converted
.
Add
(
comment
.
Convert
(
document
,
sourceText
,
syntaxTree
));
}
}
}
src/Workspaces/Remote/ServiceHub/Services/TodoComments/RemoteTodoCommentsIncrementalAnalyzerProvider.cs
浏览文件 @
2b14447d
...
...
@@ -23,6 +23,6 @@ public RemoteTodoCommentsIncrementalAnalyzerProvider(RemoteEndPoint endPoint)
}
public
IIncrementalAnalyzer
CreateIncrementalAnalyzer
(
Workspace
workspace
)
=>
new
RemoteTodoCommentsIncrementalAnalyzer
(
workspace
,
_endPoint
);
=>
new
RemoteTodoCommentsIncrementalAnalyzer
(
_endPoint
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录