Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
648893fd
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,发现更多精彩内容 >>
未验证
提交
648893fd
编写于
7月 16, 2019
作者:
G
Gen Lu
提交者:
GitHub
7月 16, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #36012 from CyrusNajmabadi/noIndenter
Remove the AbstractIndenter type (and subtypes).
上级
c78871b2
516c342f
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
620 addition
and
664 deletion
+620
-664
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs
...Portable/Indentation/CSharpIndentationService.Indenter.cs
+316
-332
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs
...s/CSharp/Portable/Indentation/CSharpIndentationService.cs
+0
-3
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.AbstractIndenter.cs
...ndentation/AbstractIndentationService.AbstractIndenter.cs
+26
-34
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs
...s/Core/Portable/Indentation/AbstractIndentationService.cs
+13
-11
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb
...ble/Indentation/VisualBasicIndentationService.Indenter.vb
+265
-276
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb
...sic/Portable/Indentation/VisualBasicIndentationService.vb
+0
-8
未找到文件。
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs
浏览文件 @
648893fd
此差异已折叠。
点击以展开。
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.cs
浏览文件 @
648893fd
...
...
@@ -35,9 +35,6 @@ protected override AbstractFormattingRule GetSpecializedIndentationFormattingRul
return
s_instance
;
}
protected
override
AbstractIndenter
GetIndenter
(
SyntacticDocument
document
,
TextLine
lineToBeIndented
,
IEnumerable
<
AbstractFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
=>
new
Indenter
(
document
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
);
public
static
bool
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
IEnumerable
<
AbstractFormattingRule
>
formattingRules
,
CompilationUnitSyntax
root
,
...
...
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.AbstractIndenter.cs
浏览文件 @
648893fd
...
...
@@ -17,25 +17,28 @@ namespace Microsoft.CodeAnalysis.Indentation
{
internal
abstract
partial
class
AbstractIndentationService
<
TSyntaxRoot
>
{
internal
abstract
class
Abstract
Indenter
protected
struct
Indenter
{
private
readonly
AbstractIndentationService
<
TSyntaxRoot
>
_service
;
public
readonly
OptionSet
OptionSet
;
public
readonly
TextLine
LineToBeIndented
;
protected
readonly
int
TabSize
;
protected
readonly
CancellationToken
CancellationToken
;
public
readonly
CancellationToken
CancellationToken
;
p
rotected
readonly
SyntacticDocument
Document
;
p
rotected
readonly
TSyntaxRoot
Root
;
p
rotected
SyntaxTree
Tree
=>
Document
.
SyntaxTree
;
p
rotected
readonly
IEnumerable
<
AbstractFormattingRule
>
Rules
;
p
rotected
readonly
BottomUpBaseIndentationFinder
Finder
;
p
ublic
readonly
SyntacticDocument
Document
;
p
ublic
readonly
TSyntaxRoot
Root
;
p
ublic
SyntaxTree
Tree
=>
Document
.
SyntaxTree
;
p
ublic
readonly
IEnumerable
<
AbstractFormattingRule
>
Rules
;
p
ublic
readonly
BottomUpBaseIndentationFinder
Finder
;
private
static
readonly
Func
<
SyntaxToken
,
bool
>
s_tokenHasDirective
=
tk
=>
tk
.
ContainsDirectives
&&
(
tk
.
LeadingTrivia
.
Any
(
tr
=>
tr
.
IsDirective
)
||
tk
.
TrailingTrivia
.
Any
(
tr
=>
tr
.
IsDirective
));
private
readonly
ISyntaxFactsService
_syntaxFacts
;
private
readonly
int
TabSize
;
public
AbstractIndenter
(
public
Indenter
(
AbstractIndentationService
<
TSyntaxRoot
>
service
,
SyntacticDocument
document
,
IEnumerable
<
AbstractFormattingRule
>
rules
,
OptionSet
optionSet
,
...
...
@@ -44,6 +47,7 @@ internal abstract class AbstractIndenter
{
Document
=
document
;
this
.
_service
=
service
;
this
.
_syntaxFacts
=
document
.
Document
.
GetLanguageService
<
ISyntaxFactsService
>();
this
.
OptionSet
=
optionSet
;
this
.
Root
=
(
TSyntaxRoot
)
document
.
Root
;
...
...
@@ -59,18 +63,6 @@ internal abstract class AbstractIndenter
tokenStream
:
null
);
}
/// <summary>
/// Returns <see langword="true"/> if the language specific <see
/// cref="ISmartTokenFormatter"/> should be deferred to figure out indentatation. If
/// so, it will be asked to <see cref="ISmartTokenFormatter.FormatTokenAsync"/> the
/// resultant <paramref name="token"/> provided by this method.
/// </summary>
protected
abstract
bool
ShouldUseTokenIndenter
(
out
SyntaxToken
token
);
protected
abstract
ISmartTokenFormatter
CreateSmartTokenFormatter
();
protected
abstract
IndentationResult
GetDesiredIndentationWorker
(
SyntaxToken
token
,
TextLine
previousLine
,
int
lastNonWhitespacePosition
);
public
IndentationResult
GetDesiredIndentation
(
FormattingOptions
.
IndentStyle
indentStyle
)
{
// If the caller wants no indent, then we'll return an effective '0' indent.
...
...
@@ -115,18 +107,18 @@ public IndentationResult GetDesiredIndentation(FormattingOptions.IndentStyle ind
var
token
=
Root
.
FindToken
(
lastNonWhitespacePosition
);
Debug
.
Assert
(
token
.
RawKind
!=
0
,
"FindToken should always return a valid token"
);
return
GetDesiredIndentationWorker
(
token
,
previousNonWhitespaceOrPreprocessorLine
,
lastNonWhitespacePosition
);
return
_service
.
GetDesiredIndentationWorker
(
t
his
,
t
oken
,
previousNonWhitespaceOrPreprocessorLine
,
lastNonWhitespacePosition
);
}
public
bool
TryGetSmartTokenIndentation
(
out
IndentationResult
indentationResult
)
{
if
(
ShouldUseTokenIndenter
(
out
var
token
))
if
(
_service
.
ShouldUseTokenIndenter
(
this
,
out
var
token
))
{
// var root = document.GetSyntaxRootSynchronously(cancellationToken);
var
sourceText
=
Tree
.
GetText
(
CancellationToken
);
var
formatter
=
CreateSmartTokenFormatter
(
);
var
formatter
=
_service
.
CreateSmartTokenFormatter
(
this
);
var
changes
=
formatter
.
FormatTokenAsync
(
Document
.
Project
.
Solution
.
Workspace
,
token
,
CancellationToken
)
.
WaitAndGetResult
(
CancellationToken
);
...
...
@@ -149,19 +141,19 @@ public bool TryGetSmartTokenIndentation(out IndentationResult indentationResult)
return
false
;
}
p
rotected
IndentationResult
IndentFromStartOfLine
(
int
addedSpaces
)
p
ublic
IndentationResult
IndentFromStartOfLine
(
int
addedSpaces
)
=>
new
IndentationResult
(
this
.
LineToBeIndented
.
Start
,
addedSpaces
);
p
rotected
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
)
p
ublic
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
)
=>
GetIndentationOfToken
(
token
,
addedSpaces
:
0
);
p
rotected
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
,
int
addedSpaces
)
p
ublic
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
,
int
addedSpaces
)
=>
GetIndentationOfPosition
(
token
.
SpanStart
,
addedSpaces
);
p
rotected
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
)
p
ublic
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
)
=>
GetIndentationOfLine
(
lineToMatch
,
addedSpaces
:
0
);
p
rotected
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
,
int
addedSpaces
)
p
ublic
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
,
int
addedSpaces
)
{
var
firstNonWhitespace
=
lineToMatch
.
GetFirstNonWhitespacePosition
();
firstNonWhitespace
??=
lineToMatch
.
End
;
...
...
@@ -169,7 +161,7 @@ protected IndentationResult GetIndentationOfLine(TextLine lineToMatch, int added
return
GetIndentationOfPosition
(
firstNonWhitespace
.
Value
,
addedSpaces
);
}
pr
otected
IndentationResult
GetIndentationOfPosition
(
int
position
,
int
addedSpaces
)
pr
ivate
IndentationResult
GetIndentationOfPosition
(
int
position
,
int
addedSpaces
)
{
if
(
this
.
Tree
.
OverlapsHiddenPosition
(
GetNormalizedSpan
(
position
),
CancellationToken
))
{
...
...
@@ -194,7 +186,7 @@ private TextSpan GetNormalizedSpan(int position)
return
TextSpan
.
FromBounds
(
position
,
LineToBeIndented
.
Start
);
}
pr
otected
TextLine
?
GetPreviousNonBlankOrPreprocessorLine
()
pr
ivate
TextLine
?
GetPreviousNonBlankOrPreprocessorLine
()
{
if
(
LineToBeIndented
.
LineNumber
<=
0
)
{
...
...
@@ -246,10 +238,10 @@ private TextSpan GetNormalizedSpan(int position)
return
null
;
}
p
rotected
int
GetCurrentPositionNotBelongToEndOfFileToken
(
int
position
)
p
ublic
int
GetCurrentPositionNotBelongToEndOfFileToken
(
int
position
)
=>
Math
.
Min
(
Root
.
EndOfFileToken
.
FullSpan
.
Start
,
position
);
pr
otected
bool
HasPreprocessorCharacter
(
TextLine
currentLine
)
pr
ivate
bool
HasPreprocessorCharacter
(
TextLine
currentLine
)
{
var
text
=
currentLine
.
ToString
();
Debug
.
Assert
(!
string
.
IsNullOrWhiteSpace
(
text
));
...
...
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs
浏览文件 @
648893fd
...
...
@@ -47,14 +47,7 @@ private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document
return
indenter
.
GetDesiredIndentation
(
indentStyle
);
}
public
IndentationResult
GetBlankLineIndentation
(
Document
document
,
int
lineNumber
,
FormattingOptions
.
IndentStyle
indentStyle
,
CancellationToken
cancellationToken
)
{
var
indenter
=
GetIndenter
(
document
,
lineNumber
,
cancellationToken
);
return
indenter
.
GetDesiredIndentation
(
indentStyle
);
}
private
AbstractIndenter
GetIndenter
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
)
private
Indenter
GetIndenter
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
)
{
var
documentOptions
=
document
.
GetOptionsAsync
(
cancellationToken
).
WaitAndGetResult_CanCallOnBackground
(
cancellationToken
);
var
syntacticDoc
=
SyntacticDocument
.
CreateAsync
(
document
,
cancellationToken
).
WaitAndGetResult_CanCallOnBackground
(
cancellationToken
);
...
...
@@ -64,10 +57,19 @@ private AbstractIndenter GetIndenter(Document document, int lineNumber, Cancella
var
formattingRules
=
GetFormattingRules
(
document
,
lineToBeIndented
.
Start
);
return
GetIndenter
(
syntacticDoc
,
lineToBeIndented
,
formattingRules
,
documentOptions
,
cancellationToken
);
return
new
Indenter
(
this
,
syntacticDoc
,
formattingRules
,
documentOptions
,
lineToBeIndented
,
cancellationToken
);
}
protected
abstract
AbstractIndenter
GetIndenter
(
SyntacticDocument
document
,
TextLine
lineToBeIndented
,
IEnumerable
<
AbstractFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
);
/// <summary>
/// Returns <see langword="true"/> if the language specific <see
/// cref="ISmartTokenFormatter"/> should be deferred to figure out indentation. If so, it
/// will be asked to <see cref="ISmartTokenFormatter.FormatTokenAsync"/> the resultant
/// <paramref name="token"/> provided by this method.
/// </summary>
protected
abstract
bool
ShouldUseTokenIndenter
(
Indenter
indenter
,
out
SyntaxToken
token
);
protected
abstract
ISmartTokenFormatter
CreateSmartTokenFormatter
(
Indenter
indenter
);
protected
abstract
IndentationResult
GetDesiredIndentationWorker
(
Indenter
indenter
,
SyntaxToken
token
,
TextLine
previousLine
,
int
lastNonWhitespacePosition
);
}
}
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb
浏览文件 @
648893fd
此差异已折叠。
点击以展开。
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb
浏览文件 @
648893fd
...
...
@@ -32,14 +32,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
Return
_specializedIndentationRule
End
Function
Protected
Overrides
Function
GetIndenter
(
document
As
SyntacticDocument
,
lineToBeIndented
As
TextLine
,
formattingRules
As
IEnumerable
(
Of
AbstractFormattingRule
),
optionSet
As
OptionSet
,
cancellationToken
As
CancellationToken
)
As
AbstractIndenter
Return
New
Indenter
(
document
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
)
End
Function
Public
Overloads
Shared
Function
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
formattingRules
As
IEnumerable
(
Of
AbstractFormattingRule
),
root
As
CompilationUnitSyntax
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录