Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
83d1a5dc
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,体验更适合开发者的 AI 搜索 >>
提交
83d1a5dc
编写于
3月 04, 2019
作者:
D
David Barbet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add toggle block comment command handler + refactor existing comment
selection handler.
上级
36d6458c
变更
24
展开全部
隐藏空白更改
内联
并排
Showing
24 changed file
with
2756 addition
and
118 deletion
+2756
-118
src/EditorFeatures/CSharp/CommentSelection/ToggleBlockCommentCommandHandler.cs
...harp/CommentSelection/ToggleBlockCommentCommandHandler.cs
+454
-0
src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs
...SharpTest/CommentSelection/CSharpCommentSelectionTests.cs
+1
-1
src/EditorFeatures/CSharpTest/CommentSelection/ToggleBlockCommentCommandHandlerTests.cs
...CommentSelection/ToggleBlockCommentCommandHandlerTests.cs
+1910
-0
src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs
src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs
+18
-0
src/EditorFeatures/Core/EditorFeaturesResources.resx
src/EditorFeatures/Core/EditorFeaturesResources.resx
+6
-0
src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionCommandHandler.cs
...ommentSelection/AbstractCommentSelectionCommandHandler.cs
+145
-0
src/EditorFeatures/Core/Implementation/CommentSelection/CommentTrackingSpan.cs
...re/Implementation/CommentSelection/CommentTrackingSpan.cs
+52
-0
src/EditorFeatures/Core/Implementation/CommentSelection/CommentUncommentSelectionCommandHandler.cs
...mmentSelection/CommentUncommentSelectionCommandHandler.cs
+26
-104
src/EditorFeatures/Core/xlf/EditorFeaturesResources.cs.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.cs.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.de.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.de.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.es.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.es.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.fr.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.fr.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.it.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.it.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ja.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ja.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ko.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ko.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.pl.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.pl.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.pt-BR.xlf
...EditorFeatures/Core/xlf/EditorFeaturesResources.pt-BR.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ru.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ru.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.tr.xlf
src/EditorFeatures/Core/xlf/EditorFeaturesResources.tr.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.zh-Hans.xlf
...itorFeatures/Core/xlf/EditorFeaturesResources.zh-Hans.xlf
+10
-0
src/EditorFeatures/Core/xlf/EditorFeaturesResources.zh-Hant.xlf
...itorFeatures/Core/xlf/EditorFeaturesResources.zh-Hant.xlf
+10
-0
src/EditorFeatures/Test/CommentSelection/CommentUncommentSelectionCommandHandlerTests.cs
...Selection/CommentUncommentSelectionCommandHandlerTests.cs
+9
-9
src/EditorFeatures/VisualBasicTest/CommentSelection/VisualBasicCommentSelectionTests.vb
...Test/CommentSelection/VisualBasicCommentSelectionTests.vb
+4
-4
src/Test/Utilities/Portable/Traits/Traits.cs
src/Test/Utilities/Portable/Traits/Traits.cs
+1
-0
未找到文件。
src/EditorFeatures/CSharp/CommentSelection/ToggleBlockCommentCommandHandler.cs
0 → 100644
浏览文件 @
83d1a5dc
此差异已折叠。
点击以展开。
src/EditorFeatures/CSharpTest/CommentSelection/CSharpCommentSelectionTests.cs
浏览文件 @
83d1a5dc
...
...
@@ -118,7 +118,7 @@ private static void UncommentSelection(string markup, string expected)
workspace
.
ExportProvider
.
GetExportedValue
<
IEditorOperationsFactoryService
>());
var
textView
=
doc
.
GetTextView
();
var
textBuffer
=
doc
.
GetTextBuffer
();
commandHandler
.
ExecuteCommand
(
textView
,
textBuffer
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Uncomment
,
TestCommandExecutionContext
.
Create
());
commandHandler
.
ExecuteCommand
(
textView
,
textBuffer
,
Operation
.
Uncomment
,
TestCommandExecutionContext
.
Create
());
Assert
.
Equal
(
expected
,
doc
.
TextBuffer
.
CurrentSnapshot
.
GetText
());
}
...
...
src/EditorFeatures/CSharpTest/CommentSelection/ToggleBlockCommentCommandHandlerTests.cs
0 → 100644
浏览文件 @
83d1a5dc
此差异已折叠。
点击以展开。
src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs
浏览文件 @
83d1a5dc
...
...
@@ -1890,6 +1890,24 @@ internal class EditorFeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Toggle Block Comment.
/// </summary>
internal
static
string
Toggle_Block_Comment
{
get
{
return
ResourceManager
.
GetString
(
"Toggle_Block_Comment"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Toggling block comment on selection....
/// </summary>
internal
static
string
Toggling_block_comment_on_selection
{
get
{
return
ResourceManager
.
GetString
(
"Toggling_block_comment_on_selection"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Type Parts.
/// </summary>
...
...
src/EditorFeatures/Core/EditorFeaturesResources.resx
浏览文件 @
83d1a5dc
...
...
@@ -889,4 +889,10 @@ Do you want to proceed?</value>
<data
name=
"Operation_is_not_ready_for_0_yet_see_task_center_for_more_detail"
xml:space=
"preserve"
>
<value>
Operation is not ready for "{0}" yet. See bottom left corner for more details.
</value>
</data>
<data
name=
"Toggle_Block_Comment"
xml:space=
"preserve"
>
<value>
Toggle Block Comment
</value>
</data>
<data
name=
"Toggling_block_comment_on_selection"
xml:space=
"preserve"
>
<value>
Toggling block comment on selection...
</value>
</data>
</root>
\ No newline at end of file
src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionCommandHandler.cs
0 → 100644
浏览文件 @
83d1a5dc
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.CommentSelection
;
using
Microsoft.CodeAnalysis.Editor.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.VisualStudio.Commanding
;
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor
;
using
Microsoft.VisualStudio.Text.Operations
;
using
Roslyn.Utilities
;
using
VSCommanding
=
Microsoft
.
VisualStudio
.
Commanding
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.CommentSelection
{
internal
enum
Operation
{
Comment
,
Uncomment
,
Toggle
}
abstract
class
AbstractCommentSelectionCommandHandler
{
protected
readonly
ITextUndoHistoryRegistry
_undoHistoryRegistry
;
protected
readonly
IEditorOperationsFactoryService
_editorOperationsFactoryService
;
internal
AbstractCommentSelectionCommandHandler
(
ITextUndoHistoryRegistry
undoHistoryRegistry
,
IEditorOperationsFactoryService
editorOperationsFactoryService
)
{
Contract
.
ThrowIfNull
(
undoHistoryRegistry
);
Contract
.
ThrowIfNull
(
editorOperationsFactoryService
);
_undoHistoryRegistry
=
undoHistoryRegistry
;
_editorOperationsFactoryService
=
editorOperationsFactoryService
;
}
protected
static
VSCommanding
.
CommandState
GetCommandState
(
ITextBuffer
buffer
)
{
if
(!
buffer
.
CanApplyChangeDocumentToWorkspace
())
{
return
VSCommanding
.
CommandState
.
Unspecified
;
}
return
VSCommanding
.
CommandState
.
Available
;
}
protected
static
void
Format
(
ICommentSelectionService
service
,
ITextSnapshot
snapshot
,
IEnumerable
<
CommentTrackingSpan
>
changes
,
CancellationToken
cancellationToken
)
{
var
document
=
snapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
;
}
// Only format uncomment actions.
var
textSpans
=
changes
.
Where
(
change
=>
change
.
Operation
==
Operation
.
Uncomment
)
.
Select
(
uncommentChange
=>
uncommentChange
.
ToSnapshotSpan
(
snapshot
).
Span
.
ToTextSpan
())
.
ToImmutableArray
();
var
newDocument
=
service
.
FormatAsync
(
document
,
textSpans
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
newDocument
.
Project
.
Solution
.
Workspace
.
ApplyDocumentChanges
(
newDocument
,
cancellationToken
);
}
private
static
ICommentSelectionService
GetService
(
Document
document
)
{
// First, try to get the new service for comment selection.
var
service
=
document
.
GetLanguageService
<
ICommentSelectionService
>();
if
(
service
!=
null
)
{
return
service
;
}
// If we couldn't find one, fallback to the legacy service.
#pragma warning disable CS0618 // Type or member is obsolete
var
legacyService
=
document
.
GetLanguageService
<
ICommentUncommentService
>();
#pragma warning restore CS0618 // Type or member is obsolete
if
(
legacyService
!=
null
)
{
return
new
CommentSelectionServiceProxy
(
legacyService
);
}
return
null
;
}
internal
bool
ExecuteCommand
(
ITextView
textView
,
ITextBuffer
subjectBuffer
,
Operation
operation
,
CommandExecutionContext
context
)
{
var
title
=
GetTitle
(
operation
);
var
message
=
GetMessage
(
operation
);
using
(
context
.
OperationContext
.
AddScope
(
allowCancellation
:
false
,
message
))
{
var
document
=
subjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
true
;
}
var
service
=
GetService
(
document
);
if
(
service
==
null
)
{
return
true
;
}
var
trackingSpans
=
new
List
<
CommentTrackingSpan
>();
var
textChanges
=
new
List
<
TextChange
>();
CollectEdits
(
document
,
service
,
textView
.
Selection
.
GetSnapshotSpansOnBuffer
(
subjectBuffer
),
textChanges
,
trackingSpans
,
operation
,
CancellationToken
.
None
);
using
(
var
transaction
=
new
CaretPreservingEditTransaction
(
title
,
textView
,
_undoHistoryRegistry
,
_editorOperationsFactoryService
))
{
document
.
Project
.
Solution
.
Workspace
.
ApplyTextChanges
(
document
.
Id
,
textChanges
.
Distinct
(),
CancellationToken
.
None
);
transaction
.
Complete
();
}
using
(
var
transaction
=
new
CaretPreservingEditTransaction
(
title
,
textView
,
_undoHistoryRegistry
,
_editorOperationsFactoryService
))
{
Format
(
service
,
subjectBuffer
.
CurrentSnapshot
,
trackingSpans
,
CancellationToken
.
None
);
transaction
.
Complete
();
}
if
(
trackingSpans
.
Any
())
{
SetTrackingSpans
(
textView
,
subjectBuffer
,
trackingSpans
);
}
}
return
true
;
}
public
abstract
string
DisplayName
{
get
;
}
internal
abstract
string
GetTitle
(
Operation
operation
);
internal
abstract
string
GetMessage
(
Operation
operation
);
internal
abstract
void
CollectEdits
(
Document
document
,
ICommentSelectionService
service
,
NormalizedSnapshotSpanCollection
selectedSpans
,
List
<
TextChange
>
textChanges
,
List
<
CommentTrackingSpan
>
trackingSpans
,
Operation
operation
,
CancellationToken
cancellationToken
);
internal
abstract
void
SetTrackingSpans
(
ITextView
textView
,
ITextBuffer
buffer
,
List
<
CommentTrackingSpan
>
trackingSpans
);
}
}
src/EditorFeatures/Core/Implementation/CommentSelection/CommentTrackingSpan.cs
0 → 100644
浏览文件 @
83d1a5dc
using
Microsoft.VisualStudio.Text
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.CommentSelection
{
/// <summary>
/// Wrapper around an ITrackingSpan that holds extra data used to format and modify span.
/// </summary>
internal
struct
CommentTrackingSpan
{
public
Operation
Operation
{
get
;
}
private
readonly
ITrackingSpan
_trackingSpan
;
// In some cases, the tracking span needs to be adjusted by a specific amount after the changes have been applied.
// These fields store the amount to adjust the span by after edits have been applied.
private
readonly
int
_amountToAddToStart
;
private
readonly
int
_amountToAddToEnd
;
public
CommentTrackingSpan
(
ITrackingSpan
trackingSpan
,
Operation
operation
)
{
Operation
=
operation
;
_trackingSpan
=
trackingSpan
;
_amountToAddToStart
=
0
;
_amountToAddToEnd
=
0
;
}
public
CommentTrackingSpan
(
ITrackingSpan
trackingSpan
,
Operation
operation
,
int
amountToAddToStart
,
int
amountToAddToEnd
)
{
Operation
=
operation
;
_trackingSpan
=
trackingSpan
;
_amountToAddToStart
=
amountToAddToStart
;
_amountToAddToEnd
=
amountToAddToEnd
;
}
public
Selection
ToSelection
(
ITextBuffer
buffer
)
{
return
new
Selection
(
ToSnapshotSpan
(
buffer
.
CurrentSnapshot
));
}
public
SnapshotSpan
ToSnapshotSpan
(
ITextSnapshot
snapshot
)
{
var
snapshotSpan
=
_trackingSpan
.
GetSpan
(
snapshot
);
if
(
_amountToAddToStart
!=
0
||
_amountToAddToEnd
!=
0
)
{
var
spanExpandedByAmount
=
Span
.
FromBounds
(
snapshotSpan
.
Start
.
Position
+
_amountToAddToStart
,
snapshotSpan
.
End
.
Position
+
_amountToAddToEnd
);
snapshotSpan
=
new
SnapshotSpan
(
snapshot
,
spanExpandedByAmount
);
}
return
snapshotSpan
;
}
}
}
src/EditorFeatures/Core/Implementation/CommentSelection/CommentUncommentSelectionCommandHandler.cs
浏览文件 @
83d1a5dc
...
...
@@ -8,7 +8,6 @@
using
System.Threading
;
using
Microsoft.CodeAnalysis.CommentSelection
;
using
Microsoft.CodeAnalysis.Editor.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.Text.Shared.Extensions
;
...
...
@@ -17,45 +16,24 @@
using
Microsoft.VisualStudio.Text.Editor
;
using
Microsoft.VisualStudio.Text.Editor.Commanding.Commands
;
using
Microsoft.VisualStudio.Text.Operations
;
using
Microsoft.VisualStudio.Utilities
;
using
Roslyn.Utilities
;
using
VSCommanding
=
Microsoft
.
VisualStudio
.
Commanding
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.CommentSelection
{
[
Export
(
typeof
(
VSCommanding
.
ICommandHandler
))]
[
ContentType
(
ContentTypeNames
.
RoslynContentType
)]
[
Name
(
PredefinedCommandHandlerNames
.
CommentSelection
)]
//
[Export(typeof(VSCommanding.ICommandHandler))]
//
[ContentType(ContentTypeNames.RoslynContentType)]
//
[Name(PredefinedCommandHandlerNames.CommentSelection)]
internal
class
CommentUncommentSelectionCommandHandler
:
AbstractCommentSelectionCommandHandler
,
VSCommanding
.
ICommandHandler
<
CommentSelectionCommandArgs
>,
VSCommanding
.
ICommandHandler
<
UncommentSelectionCommandArgs
>
{
private
readonly
ITextUndoHistoryRegistry
_undoHistoryRegistry
;
private
readonly
IEditorOperationsFactoryService
_editorOperationsFactoryService
;
[
ImportingConstructor
]
internal
CommentUncommentSelectionCommandHandler
(
ITextUndoHistoryRegistry
undoHistoryRegistry
,
IEditorOperationsFactoryService
editorOperationsFactoryService
)
{
Contract
.
ThrowIfNull
(
undoHistoryRegistry
);
Contract
.
ThrowIfNull
(
editorOperationsFactoryService
);
_undoHistoryRegistry
=
undoHistoryRegistry
;
_editorOperationsFactoryService
=
editorOperationsFactoryService
;
}
public
string
DisplayName
=>
EditorFeaturesResources
.
Comment_Uncomment_Selection
;
private
static
VSCommanding
.
CommandState
GetCommandState
(
ITextBuffer
buffer
)
{
if
(!
buffer
.
CanApplyChangeDocumentToWorkspace
())
{
return
VSCommanding
.
CommandState
.
Unspecified
;
}
return
VSCommanding
.
CommandState
.
Available
;
}
IEditorOperationsFactoryService
editorOperationsFactoryService
)
:
base
(
undoHistoryRegistry
,
editorOperationsFactoryService
)
{
}
public
VSCommanding
.
CommandState
GetCommandState
(
CommentSelectionCommandArgs
args
)
{
...
...
@@ -83,107 +61,51 @@ public bool ExecuteCommand(UncommentSelectionCommandArgs args, CommandExecutionC
return
this
.
ExecuteCommand
(
args
.
TextView
,
args
.
SubjectBuffer
,
Operation
.
Uncomment
,
context
);
}
internal
bool
ExecuteCommand
(
ITextView
textView
,
ITextBuffer
subjectBuffer
,
Operation
operation
,
CommandExecutionContext
context
)
{
var
title
=
operation
==
Operation
.
Comment
?
EditorFeaturesResources
.
Comment_Selection
:
EditorFeaturesResources
.
Uncomment_Selection
;
var
message
=
operation
==
Operation
.
Comment
?
EditorFeaturesResources
.
Commenting_currently_selected_text
:
EditorFeaturesResources
.
Uncommenting_currently_selected_text
;
using
(
context
.
OperationContext
.
AddScope
(
allowCancellation
:
false
,
message
))
{
var
document
=
subjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
true
;
}
var
service
=
GetService
(
document
);
if
(
service
==
null
)
{
return
true
;
}
var
trackingSpans
=
new
List
<
ITrackingSpan
>();
var
textChanges
=
new
List
<
TextChange
>();
CollectEdits
(
document
,
service
,
textView
.
Selection
.
GetSnapshotSpansOnBuffer
(
subjectBuffer
),
textChanges
,
trackingSpans
,
operation
,
CancellationToken
.
None
);
public
override
string
DisplayName
=>
EditorFeaturesResources
.
Comment_Uncomment_Selection
;
using
(
var
transaction
=
new
CaretPreservingEditTransaction
(
title
,
textView
,
_undoHistoryRegistry
,
_editorOperationsFactoryService
))
{
document
.
Project
.
Solution
.
Workspace
.
ApplyTextChanges
(
document
.
Id
,
textChanges
,
CancellationToken
.
None
);
transaction
.
Complete
();
}
if
(
operation
==
Operation
.
Uncomment
)
{
using
(
var
transaction
=
new
CaretPreservingEditTransaction
(
title
,
textView
,
_undoHistoryRegistry
,
_editorOperationsFactoryService
))
{
Format
(
service
,
subjectBuffer
.
CurrentSnapshot
,
trackingSpans
,
CancellationToken
.
None
);
transaction
.
Complete
();
}
}
if
(
trackingSpans
.
Any
())
{
// TODO, this doesn't currently handle block selection
textView
.
SetSelection
(
trackingSpans
.
First
().
GetSpan
(
subjectBuffer
.
CurrentSnapshot
));
}
}
return
true
;
internal
override
string
GetTitle
(
Operation
operation
)
{
return
operation
==
Operation
.
Comment
?
EditorFeaturesResources
.
Comment_Selection
:
EditorFeaturesResources
.
Uncomment_Selection
;
}
private
ICommentSelectionService
GetService
(
Document
document
)
internal
override
string
GetMessage
(
Operation
operation
)
{
// First, try to get the new service for comment selection.
var
service
=
document
.
GetLanguageService
<
ICommentSelectionService
>();
if
(
service
!=
null
)
{
return
service
;
}
return
null
;
return
operation
==
Operation
.
Comment
?
EditorFeaturesResources
.
Commenting_currently_selected_text
:
EditorFeaturesResources
.
Uncommenting_currently_selected_text
;
}
private
void
Format
(
ICommentSelectionService
service
,
ITextSnapshot
snapshot
,
IEnumerable
<
ITrackingSpan
>
changes
,
CancellationToken
cancellationToken
)
internal
override
void
SetTrackingSpans
(
ITextView
textView
,
ITextBuffer
buffer
,
List
<
CommentTrackingSpan
>
trackingSpans
)
{
var
document
=
snapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
;
}
var
textSpans
=
changes
.
Select
(
s
=>
s
.
GetSpan
(
snapshot
).
Span
.
ToTextSpan
()).
ToImmutableArray
();
var
newDocument
=
service
.
FormatAsync
(
document
,
textSpans
,
cancellationToken
).
WaitAndGetResult
(
cancellationToken
);
newDocument
.
Project
.
Solution
.
Workspace
.
ApplyDocumentChanges
(
newDocument
,
cancellationToken
);
// TODO, this doesn't currently handle block selection
textView
.
SetSelection
(
trackingSpans
.
First
().
ToSnapshotSpan
(
buffer
.
CurrentSnapshot
));
}
internal
enum
Operation
{
Comment
,
Uncomment
}
/// <summary>
/// Add the necessary edits to the given spans. Also collect tracking spans over each span.
///
/// Internal so that it can be called by unit tests.
/// </summary>
internal
void
CollectEdits
(
internal
override
void
CollectEdits
(
Document
document
,
ICommentSelectionService
service
,
NormalizedSnapshotSpanCollection
selectedSpans
,
List
<
TextChange
>
textChanges
,
List
<
I
TrackingSpan
>
trackingSpans
,
Operation
operation
,
CancellationToken
cancellationToken
)
List
<
TextChange
>
textChanges
,
List
<
Comment
TrackingSpan
>
trackingSpans
,
Operation
operation
,
CancellationToken
cancellationToken
)
{
var
spanTrackingList
=
new
List
<
ITrackingSpan
>();
foreach
(
var
span
in
selectedSpans
)
{
if
(
operation
==
Operation
.
Comment
)
{
CommentSpan
(
document
,
service
,
span
,
textChanges
,
trackingSpans
,
cancellationToken
);
CommentSpan
(
document
,
service
,
span
,
textChanges
,
spanTrackingList
,
cancellationToken
);
}
else
{
UncommentSpan
(
document
,
service
,
span
,
textChanges
,
trackingSpans
,
cancellationToken
);
UncommentSpan
(
document
,
service
,
span
,
textChanges
,
spanTrackingList
,
cancellationToken
);
}
}
foreach
(
var
internalTrackingSpan
in
spanTrackingList
)
{
trackingSpans
.
Add
(
new
CommentTrackingSpan
(
internalTrackingSpan
,
operation
));
}
}
/// <summary>
...
...
src/EditorFeatures/Core/xlf/EditorFeaturesResources.cs.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Chcete pokračovat?</target>
<target
state=
"translated"
>
Inteligentní formátování tokenů
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.de.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Möchten Sie fortfahren?</target>
<target
state=
"translated"
>
Intelligente Tokenformatierung
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.es.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
Formateador de token inteligente
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.fr.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Voulez-vous continuer ?</target>
<target
state=
"translated"
>
Formateur de jeton intelligent
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.it.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Continuare?</target>
<target
state=
"translated"
>
Formattatore di token intelligente
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ja.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
スマート トークン フォーマッタ
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ko.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
스마트 토큰 포맷터
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.pl.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Czy chcesz kontynuować?</target>
<target
state=
"translated"
>
Inteligentny element formatujący tokeny
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.pt-BR.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Deseja continuar?</target>
<target
state=
"translated"
>
Formatador de Token Inteligente
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.ru.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
Средство форматирования смарт-токена
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.tr.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Devam etmek istiyor musunuz?</target>
<target
state=
"translated"
>
Akıllı Belirteç Biçimlendirici
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.zh-Hans.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
智能令牌格式化程序
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Core/xlf/EditorFeaturesResources.zh-Hant.xlf
浏览文件 @
83d1a5dc
...
...
@@ -1284,6 +1284,16 @@ Do you want to proceed?</source>
<target
state=
"translated"
>
智慧權杖格式器
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggling_block_comment_on_selection"
>
<source>
Toggling block comment on selection...
</source>
<target
state=
"new"
>
Toggling block comment on selection...
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Toggle_Block_Comment"
>
<source>
Toggle Block Comment
</source>
<target
state=
"new"
>
Toggle Block Comment
</target>
<note
/>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
src/EditorFeatures/Test/CommentSelection/CommentUncommentSelectionCommandHandlerTests.cs
浏览文件 @
83d1a5dc
...
...
@@ -717,27 +717,27 @@ class A
private
static
void
UncommentSelection
(
string
code
,
IEnumerable
<
TextChange
>
expectedChanges
,
Span
expectedSelectedSpan
,
bool
supportBlockComments
)
{
CommentOrUncommentSelection
(
code
,
expectedChanges
,
new
[]
{
expectedSelectedSpan
},
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Uncomment
);
CommentOrUncommentSelection
(
code
,
expectedChanges
,
new
[]
{
expectedSelectedSpan
},
supportBlockComments
,
Operation
.
Uncomment
);
}
private
static
void
UncommentSelection
(
string
code
,
IEnumerable
<
TextChange
>
expectedChanges
,
IEnumerable
<
Span
>
expectedSelectedSpans
,
bool
supportBlockComments
)
{
CommentOrUncommentSelection
(
code
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Uncomment
);
CommentOrUncommentSelection
(
code
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
Operation
.
Uncomment
);
}
private
static
void
CommentSelection
(
string
code
,
IEnumerable
<
TextChange
>
expectedChanges
,
bool
supportBlockComments
)
{
CommentOrUncommentSelection
(
code
,
expectedChanges
,
null
/*expectedSelectedSpans*/
,
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Comment
);
CommentOrUncommentSelection
(
code
,
expectedChanges
,
null
/*expectedSelectedSpans*/
,
supportBlockComments
,
Operation
.
Comment
);
}
private
static
void
CommentSelection
(
string
code
,
IEnumerable
<
TextChange
>
expectedChanges
,
IEnumerable
<
Span
>
expectedSelectedSpans
,
bool
supportBlockComments
)
{
CommentOrUncommentSelection
(
code
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Comment
);
CommentOrUncommentSelection
(
code
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
Operation
.
Comment
);
}
private
static
void
CommentSelection
(
ITextView
textView
,
IEnumerable
<
TextChange
>
expectedChanges
,
IEnumerable
<
Span
>
expectedSelectedSpans
,
bool
supportBlockComments
)
{
CommentOrUncommentSelection
(
textView
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Comment
);
CommentOrUncommentSelection
(
textView
,
expectedChanges
,
expectedSelectedSpans
,
supportBlockComments
,
Operation
.
Comment
);
}
private
static
void
CommentOrUncommentSelection
(
...
...
@@ -745,7 +745,7 @@ private static void CommentSelection(ITextView textView, IEnumerable<TextChange>
IEnumerable
<
TextChange
>
expectedChanges
,
IEnumerable
<
Span
>
expectedSelectedSpans
,
bool
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
operation
)
Operation
operation
)
{
using
(
var
disposableView
=
EditorFactory
.
CreateView
(
TestExportProvider
.
ExportProviderWithCSharpAndVisualBasic
,
code
))
{
...
...
@@ -760,14 +760,14 @@ private static void CommentSelection(ITextView textView, IEnumerable<TextChange>
IEnumerable
<
TextChange
>
expectedChanges
,
IEnumerable
<
Span
>
expectedSelectedSpans
,
bool
supportBlockComments
,
CommentUncommentSelectionCommandHandler
.
Operation
operation
)
Operation
operation
)
{
var
textUndoHistoryRegistry
=
TestExportProvider
.
ExportProviderWithCSharpAndVisualBasic
.
GetExportedValue
<
ITextUndoHistoryRegistry
>();
var
editorOperationsFactory
=
TestExportProvider
.
ExportProviderWithCSharpAndVisualBasic
.
GetExportedValue
<
IEditorOperationsFactoryService
>();
var
commandHandler
=
new
CommentUncommentSelectionCommandHandler
(
textUndoHistoryRegistry
,
editorOperationsFactory
);
var
service
=
new
MockCommentSelectionService
(
supportBlockComments
);
var
trackingSpans
=
new
List
<
I
TrackingSpan
>();
var
trackingSpans
=
new
List
<
Comment
TrackingSpan
>();
var
textChanges
=
new
List
<
TextChange
>();
commandHandler
.
CollectEdits
(
...
...
@@ -786,7 +786,7 @@ private static void CommentSelection(ITextView textView, IEnumerable<TextChange>
if
(
trackingSpans
.
Any
())
{
textView
.
SetSelection
(
trackingSpans
.
First
().
GetSpan
(
textView
.
Tex
tSnapshot
));
textView
.
SetSelection
(
trackingSpans
.
First
().
ToSnapshotSpan
(
textView
.
TextBuffer
.
Curren
tSnapshot
));
}
if
(
expectedSelectedSpans
!=
null
)
...
...
src/EditorFeatures/VisualBasicTest/CommentSelection/VisualBasicCommentSelectionTests.vb
浏览文件 @
83d1a5dc
...
...
@@ -29,7 +29,7 @@ End Module</code>
'End Sub
End
Module
</
code
>
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Comment
)
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
Operation
.
Comment
)
End
Sub
...
...
@@ -47,7 +47,7 @@ End Module</code>
End
Sub
End
Module
</
code
>
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Uncomment
)
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
Operation
.
Uncomment
)
End
Sub
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CommentSelection
)
>
...
...
@@ -64,10 +64,10 @@ End Module</code>
End
Sub
End
Module
</
code
>
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
CommentUncommentSelectionCommandHandler
.
Operation
.
Uncomment
)
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
.
Value
,
expected
.
Value
,
Operation
.
Uncomment
)
End
Sub
Private
Shared
Sub
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
As
String
,
expected
As
String
,
operation
As
CommentUncommentSelectionCommandHandler
.
Operation
)
Private
Shared
Sub
InvokeCommentOperationOnSelectionAfterReplacingLfToCrLf
(
code
As
String
,
expected
As
String
,
operation
As
Operation
)
' do this since xml value put only vbLf
code
=
code
.
Replace
(
vbLf
,
vbCrLf
)
expected
=
expected
.
Replace
(
vbLf
,
vbCrLf
)
...
...
src/Test/Utilities/Portable/Traits/Traits.cs
浏览文件 @
83d1a5dc
...
...
@@ -247,6 +247,7 @@ public static class Features
public
const
string
SuggestionTags
=
nameof
(
SuggestionTags
);
public
const
string
TextStructureNavigator
=
nameof
(
TextStructureNavigator
);
public
const
string
TodoComments
=
nameof
(
TodoComments
);
public
const
string
ToggleBlockComment
=
nameof
(
ToggleBlockComment
);
public
const
string
TypeInferenceService
=
nameof
(
TypeInferenceService
);
public
const
string
Venus
=
nameof
(
Venus
);
public
const
string
ValidateFormatString
=
nameof
(
ValidateFormatString
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录