Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3f518522
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,发现更多精彩内容 >>
提交
3f518522
编写于
10月 16, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify logic and add more invariant checking.
上级
0a31f0c9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
33 deletion
+32
-33
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
...rmatting/Indentation/CSharpIndentationService.Indenter.cs
+0
-1
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
...martIndent/AbstractIndentationService.AbstractIndenter.cs
+32
-32
未找到文件。
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
浏览文件 @
3f518522
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
...
...
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
浏览文件 @
3f518522
...
...
@@ -2,6 +2,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.Formatting
;
...
...
@@ -63,60 +64,64 @@ internal abstract class AbstractIndenter
var
indentStyle
=
OptionSet
.
GetOption
(
FormattingOptions
.
SmartIndent
,
document
.
Project
.
Language
);
if
(
indentStyle
==
FormattingOptions
.
IndentStyle
.
None
)
{
// If there is no indent style, then do nothing.
return
null
;
}
// find previous line that is not blank
var
previousLine
=
GetPreviousNonBlankOrPreprocessorLine
();
// find previous line that is not blank. this will skip over things like preprocessor
// regions and inactive code.
var
previousLineOpt
=
GetPreviousNonBlankOrPreprocessorLine
();
// it is beginning of the file, there is no previous line exists.
// in that case, indentation 0 is our base indentation.
if
(
previousLine
==
null
)
if
(
previousLine
Opt
==
null
)
{
return
IndentFromStartOfLine
(
0
);
}
// okay, now see whether previous line has anything meaningful
var
lastNonWhitespacePosition
=
previousLine
.
Value
.
GetLastNonWhitespacePosition
();
if
(
lastNonWhitespacePosition
==
null
)
var
previousNonWhitespaceOrPreprocessorLine
=
previousLineOpt
.
Value
;
// If the user wants block indentation, then we just return the indentation
// of the last piece of real code.
//
// TODO(cyrusn): It's not clear to me that this is correct. Block indentation
// should probably follow the indentation of hte last non-blank line *regardless
// if it is inactive/preprocessor region. By skipping over thse, we are essentially
// being 'smart', and that seems to be overriding the user desire to have Block
// indentation.
if
(
indentStyle
==
FormattingOptions
.
IndentStyle
.
Block
)
{
return
null
;
// If it's block indentation, then just base
return
GetIndentationOfLine
(
previousNonWhitespaceOrPreprocessorLine
);
}
// there is known parameter list "," parse bug. if previous token is "," from parameter list,
// FindToken will not be able to find them.
var
token
=
Tree
.
GetRoot
(
CancellationToken
).
FindToken
(
lastNonWhitespacePosition
.
Value
);
if
(
token
.
RawKind
==
0
||
indentStyle
==
FormattingOptions
.
IndentStyle
.
Block
)
{
return
GetIndentationOfLine
(
previousLine
.
Value
);
}
Debug
.
Assert
(
indentStyle
==
FormattingOptions
.
IndentStyle
.
Smart
);
// Because we know that previousLine is not-whitespace, we know that we should be
// able to get the last non-whitespace position.
var
lastNonWhitespacePosition
=
previousNonWhitespaceOrPreprocessorLine
.
GetLastNonWhitespacePosition
().
Value
;
var
token
=
Tree
.
GetRoot
(
CancellationToken
).
FindToken
(
lastNonWhitespacePosition
);
Debug
.
Assert
(
token
.
RawKind
!=
0
,
"FindToken should always return a valid token"
);
return
GetDesiredIndentationWorker
(
token
,
previous
Line
.
Value
,
lastNonWhitespacePosition
.
Value
);
token
,
previous
NonWhitespaceOrPreprocessorLine
,
lastNonWhitespacePosition
);
}
protected
abstract
IndentationResult
?
GetDesiredIndentationWorker
(
SyntaxToken
token
,
TextLine
previousLine
,
int
lastNonWhitespacePosition
);
protected
IndentationResult
IndentFromStartOfLine
(
int
addedSpaces
)
{
return
new
IndentationResult
(
this
.
LineToBeIndented
.
Start
,
addedSpaces
);
}
=>
new
IndentationResult
(
this
.
LineToBeIndented
.
Start
,
addedSpaces
);
protected
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
)
{
return
GetIndentationOfToken
(
token
,
addedSpaces
:
0
);
}
=>
GetIndentationOfToken
(
token
,
addedSpaces
:
0
);
protected
IndentationResult
GetIndentationOfToken
(
SyntaxToken
token
,
int
addedSpaces
)
{
return
GetIndentationOfPosition
(
token
.
SpanStart
,
addedSpaces
);
}
=>
GetIndentationOfPosition
(
token
.
SpanStart
,
addedSpaces
);
protected
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
)
{
return
GetIndentationOfLine
(
lineToMatch
,
addedSpaces
:
0
);
}
=>
GetIndentationOfLine
(
lineToMatch
,
addedSpaces
:
0
);
protected
IndentationResult
GetIndentationOfLine
(
TextLine
lineToMatch
,
int
addedSpaces
)
{
...
...
@@ -154,11 +159,6 @@ private TextSpan GetNormalizedSpan(int position)
protected
TextLine
?
GetPreviousNonBlankOrPreprocessorLine
()
{
if
(
Tree
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
Tree
));
}
if
(
LineToBeIndented
.
LineNumber
<=
0
)
{
return
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录