Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fda2c31c
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,发现更多精彩内容 >>
提交
fda2c31c
编写于
3月 27, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify
上级
76fc0e8c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
16 deletion
+51
-16
src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs
.../BlockCommentEditing/BlockCommentEditingCommandHandler.cs
+34
-12
src/EditorFeatures/Text/Shared/Extensions/ITextSnapshotLineExtensions.cs
...res/Text/Shared/Extensions/ITextSnapshotLineExtensions.cs
+15
-4
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/DocumentExtensions.cs
...xtensions/Workspace/Core/Extensions/DocumentExtensions.cs
+2
-0
未找到文件。
src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs
浏览文件 @
fda2c31c
...
...
@@ -98,25 +98,28 @@ private Span GetReplacementSpan(SnapshotPoint caretPosition)
if
(
firstNonWhitespacePosition
==
-
1
)
return
null
;
var
startsWithBlockCommentStartString
=
currentLine
.
StartsWith
(
firstNonWhitespacePosition
,
"/*"
,
ignoreCase
:
false
);
var
startsWithBlockCommentEndString
=
currentLine
.
StartsWith
(
firstNonWhitespacePosition
,
"*/"
,
ignoreCase
:
false
);
// Do quick textual checks to see if it looks like we're inside a comment. That way we only do the expensive
// syntactic work when necessary.
//
// The line either has to contain `/*` or it has to start with `*`. The former looks like we're starting a
// comment in this line. The latter looks like the continuation of a block comment.
var
containsBlockCommentStartString
=
currentLine
.
Contains
(
firstNonWhitespacePosition
,
"/*"
,
ignoreCase
:
false
);
var
startsWithBlockCommentMiddleString
=
currentLine
.
StartsWith
(
firstNonWhitespacePosition
,
"*"
,
ignoreCase
:
false
);
if
(!
startsWith
BlockCommentStartString
&&
if
(!
contains
BlockCommentStartString
&&
!
startsWithBlockCommentMiddleString
)
{
return
null
;
}
if
(!
IsCaretInsideBlockCommentSyntax
(
caretPosition
,
out
var
document
,
out
var
blockComment
))
// Now do more expensive syntactic check to see if we're actually in the block comment.
if
(!
IsCaretInsideBlockCommentSyntax
(
caretPosition
,
out
var
blockComment
,
out
var
newLine
))
return
null
;
var
textSnapshot
=
caretPosition
.
Snapshot
;
// The whitespace indentation on the line where the block-comment starts.
var
commentIndentation
=
textSnapshot
.
GetText
(
Span
.
FromBounds
(
textSnapshot
.
GetLineFromPosition
(
blockComment
.
FullSpan
.
Start
).
Start
,
blockComment
.
FullSpan
.
Start
));
var
commentIndentation
=
GetCommentIndentation
();
// The whitespace indentation on the current line up to the first non-whitespace char.
var
lineIndentation
=
textSnapshot
.
GetText
(
Span
.
FromBounds
(
...
...
@@ -127,13 +130,26 @@ private Span GetReplacementSpan(SnapshotPoint caretPosition)
if
(
exteriorText
==
null
)
return
null
;
var
options
=
document
.
Project
.
Solution
.
Options
;
var
newLine
=
options
.
GetOption
(
FormattingOptions
.
NewLine
,
LanguageNames
.
CSharp
);
return
newLine
+
exteriorText
;
string
GetCommentIndentation
()
{
var
sb
=
PooledStringBuilder
.
GetInstance
();
var
commentStart
=
blockComment
.
FullSpan
.
Start
;
var
commentLine
=
textSnapshot
.
GetLineFromPosition
(
commentStart
);
for
(
var
i
=
commentLine
.
Start
.
Position
;
i
<
commentStart
;
i
++)
{
var
ch
=
textSnapshot
[
i
];
sb
.
Builder
.
Append
(
ch
==
'\t'
?
ch
:
' '
);
}
return
sb
.
ToStringAndFree
();
}
string
?
GetExteriorText
()
{
if
(
startsWith
BlockCommentStartString
)
if
(
contains
BlockCommentStartString
)
{
if
(
BlockCommentEndsRightAfterCaret
(
caretPosition
))
{
...
...
@@ -163,6 +179,7 @@ private Span GetReplacementSpan(SnapshotPoint caretPosition)
}
}
var
startsWithBlockCommentEndString
=
currentLine
.
StartsWith
(
firstNonWhitespacePosition
,
"*/"
,
ignoreCase
:
false
);
if
(
startsWithBlockCommentEndString
)
{
if
(
BlockCommentEndsRightAfterCaret
(
caretPosition
))
...
...
@@ -235,12 +252,14 @@ private static bool BlockCommentEndsRightAfterCaret(SnapshotPoint caretPosition)
public
static
bool
IsCaretInsideBlockCommentSyntax
(
SnapshotPoint
caretPosition
,
[
NotNullWhen
(
true
)]
out
Document
?
document
,
out
SyntaxTrivia
trivia
)
out
SyntaxTrivia
trivia
,
[
NotNullWhen
(
true
)]
out
string
?
newLine
)
{
trivia
=
default
;
newLine
=
null
;
var
snapshot
=
caretPosition
.
Snapshot
;
document
=
snapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
var
document
=
snapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
return
false
;
...
...
@@ -250,6 +269,9 @@ private static bool BlockCommentEndsRightAfterCaret(SnapshotPoint caretPosition)
var
isBlockComment
=
trivia
.
IsKind
(
SyntaxKind
.
MultiLineCommentTrivia
)
||
trivia
.
IsKind
(
SyntaxKind
.
MultiLineDocumentationCommentTrivia
);
if
(
isBlockComment
)
{
var
options
=
document
.
Project
.
Solution
.
Options
;
newLine
=
options
.
GetOption
(
FormattingOptions
.
NewLine
,
LanguageNames
.
CSharp
);
var
span
=
trivia
.
FullSpan
;
if
(
span
.
Start
<
caretPosition
&&
caretPosition
<
span
.
End
)
return
true
;
...
...
src/EditorFeatures/Text/Shared/Extensions/ITextSnapshotLineExtensions.cs
浏览文件 @
fda2c31c
...
...
@@ -144,9 +144,7 @@ public static bool StartsWith(this ITextSnapshotLine line, int index, string val
{
var
snapshot
=
line
.
Snapshot
;
if
(
index
+
value
.
Length
>
snapshot
.
Length
)
{
return
false
;
}
for
(
var
i
=
0
;
i
<
value
.
Length
;
i
++)
{
...
...
@@ -161,12 +159,25 @@ public static bool StartsWith(this ITextSnapshotLine line, int index, string val
}
if
(
actualCharacter
!=
expectedCharacter
)
{
return
false
;
}
}
return
true
;
}
public
static
bool
Contains
(
this
ITextSnapshotLine
line
,
int
index
,
string
value
,
bool
ignoreCase
)
{
var
snapshot
=
line
.
Snapshot
;
for
(
var
i
=
index
;
i
<
line
.
End
;
i
++)
{
if
(
i
+
value
.
Length
>
snapshot
.
Length
)
return
false
;
if
(
line
.
StartsWith
(
i
,
value
,
ignoreCase
))
return
true
;
}
return
false
;
}
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/DocumentExtensions.cs
浏览文件 @
fda2c31c
...
...
@@ -41,11 +41,13 @@ public static async Task<SyntaxTree> GetRequiredSyntaxTreeAsync(this Document do
return
syntaxTree
??
throw
new
InvalidOperationException
(
string
.
Format
(
WorkspaceExtensionsResources
.
SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0
,
document
.
Name
));
}
#if !CODE_STYLE
public
static
SyntaxTree
GetRequiredSyntaxTreeSynchronously
(
this
Document
document
,
CancellationToken
cancellationToken
)
{
var
syntaxTree
=
document
.
GetSyntaxTreeSynchronously
(
cancellationToken
);
return
syntaxTree
??
throw
new
InvalidOperationException
(
string
.
Format
(
WorkspaceExtensionsResources
.
SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0
,
document
.
Name
));
}
#endif
public
static
async
Task
<
SyntaxNode
>
GetRequiredSyntaxRootAsync
(
this
Document
document
,
CancellationToken
cancellationToken
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录