Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
42f069ac
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,发现更多精彩内容 >>
提交
42f069ac
编写于
3月 27, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use NRT
上级
ecda4320
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
14 deletion
+18
-14
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs
...Portable/Indentation/CSharpIndentationService.Indenter.cs
+2
-2
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs
...rtable/Indentation/AbstractIndentationService.Indenter.cs
+10
-8
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs
...s/Core/Portable/Indentation/AbstractIndentationService.cs
+5
-3
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb
...ble/Indentation/VisualBasicIndentationService.Indenter.vb
+1
-1
未找到文件。
src/Workspaces/CSharp/Portable/Indentation/CSharpIndentationService.Indenter.cs
浏览文件 @
42f069ac
...
...
@@ -31,9 +31,9 @@ protected override ISmartTokenFormatter CreateSmartTokenFormatter(Indenter inden
return
new
CSharpSmartTokenFormatter
(
indenter
.
OptionSet
,
rules
,
indenter
.
Root
);
}
protected
override
IndentationResult
GetDesiredIndentationWorker
(
Indenter
indenter
,
SyntaxToken
?
tokenOpt
,
SyntaxTrivia
?
triviaOpt
)
protected
override
IndentationResult
?
GetDesiredIndentationWorker
(
Indenter
indenter
,
SyntaxToken
?
tokenOpt
,
SyntaxTrivia
?
triviaOpt
)
=>
TryGetDesiredIndentation
(
indenter
,
triviaOpt
)
??
TryGetDesiredIndentation
(
indenter
,
tokenOpt
)
??
default
;
TryGetDesiredIndentation
(
indenter
,
tokenOpt
);
private
IndentationResult
?
TryGetDesiredIndentation
(
Indenter
indenter
,
SyntaxTrivia
?
triviaOpt
)
{
...
...
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.Indenter.cs
浏览文件 @
42f069ac
...
...
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#
nullable
enable
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
...
...
@@ -50,7 +52,7 @@ protected struct Indenter
Document
=
document
;
_service
=
service
;
_syntaxFacts
=
document
.
Document
.
GetLanguageService
<
ISyntaxFactsService
>();
_syntaxFacts
=
document
.
Document
.
Get
Required
LanguageService
<
ISyntaxFactsService
>();
OptionSet
=
optionSet
;
OptionService
=
document
.
Document
.
Project
.
Solution
.
Workspace
.
Services
.
GetRequiredService
<
IOptionService
>();
Root
=
(
TSyntaxRoot
)
document
.
Root
;
...
...
@@ -66,11 +68,11 @@ protected struct Indenter
tokenStream
:
null
);
}
public
IndentationResult
GetDesiredIndentation
(
FormattingOptions
.
IndentStyle
indentStyle
)
public
IndentationResult
?
GetDesiredIndentation
(
FormattingOptions
.
IndentStyle
indentStyle
)
{
// If the caller wants no indent, then we'll return an effective '0' indent.
if
(
indentStyle
==
FormattingOptions
.
IndentStyle
.
None
)
return
default
;
return
null
;
// If the user has explicitly set 'block' indentation, or they're in an inactive preprocessor region,
// then just do simple block indentation.
...
...
@@ -84,7 +86,7 @@ public IndentationResult GetDesiredIndentation(FormattingOptions.IndentStyle ind
return
GetDesiredSmartIndentation
();
}
private
readonly
IndentationResult
GetDesiredSmartIndentation
()
private
readonly
IndentationResult
?
GetDesiredSmartIndentation
()
{
// For smart indent, we generally will be computing from either the previous token in the code, or in a
// few special cases, the previous trivia.
...
...
@@ -97,7 +99,7 @@ public IndentationResult GetDesiredIndentation(FormattingOptions.IndentStyle ind
var
trivia
=
TryGetImmediatelyPrecedingVisibleTrivia
();
if
(
token
==
null
&&
trivia
==
null
)
return
default
;
return
null
;
return
_service
.
GetDesiredIndentationWorker
(
this
,
token
,
trivia
);
}
...
...
@@ -143,7 +145,7 @@ public IndentationResult GetDesiredIndentation(FormattingOptions.IndentStyle ind
return
token
;
}
private
IndentationResult
GetDesiredBlockIndentation
()
private
IndentationResult
?
GetDesiredBlockIndentation
()
{
// Block indentation is simple, we keep walking back lines until we find a line with any sort of
// text on it. We then set our indentation to whatever the indentation of that line was.
...
...
@@ -158,8 +160,8 @@ private IndentationResult GetDesiredBlockIndentation()
return
new
IndentationResult
(
basePosition
:
line
.
Start
+
offset
.
Value
,
offset
:
0
);
}
// Couldn't find a previous non-blank line.
Don't indent at all.
return
default
;
// Couldn't find a previous non-blank line.
return
null
;
}
public
bool
TryGetSmartTokenIndentation
(
out
IndentationResult
indentationResult
)
...
...
src/Workspaces/Core/Portable/Indentation/AbstractIndentationService.cs
浏览文件 @
42f069ac
...
...
@@ -2,12 +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.
#
nullable
enable
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Indentation
...
...
@@ -45,7 +46,8 @@ private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document
return
indentationResult
;
}
return
indenter
.
GetDesiredIndentation
(
indentStyle
);
// If the indenter can't produce a valid result, just default to 0 as our indentation.
return
indenter
.
GetDesiredIndentation
(
indentStyle
)
??
default
;
}
private
Indenter
GetIndenter
(
Document
document
,
int
lineNumber
,
FormattingOptions
.
IndentStyle
indentStyle
,
CancellationToken
cancellationToken
)
...
...
@@ -70,7 +72,7 @@ private Indenter GetIndenter(Document document, int lineNumber, FormattingOption
protected
abstract
bool
ShouldUseTokenIndenter
(
Indenter
indenter
,
out
SyntaxToken
token
);
protected
abstract
ISmartTokenFormatter
CreateSmartTokenFormatter
(
Indenter
indenter
);
protected
abstract
IndentationResult
GetDesiredIndentationWorker
(
protected
abstract
IndentationResult
?
GetDesiredIndentationWorker
(
Indenter
indenter
,
SyntaxToken
?
token
,
SyntaxTrivia
?
trivia
);
}
}
src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.Indenter.vb
浏览文件 @
42f069ac
...
...
@@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation
Protected
Overrides
Function
GetDesiredIndentationWorker
(
indenter
As
Indenter
,
tokenOpt
As
SyntaxToken
?
,
triviaOpt
As
SyntaxTrivia
?
)
As
IndentationResult
triviaOpt
As
SyntaxTrivia
?
)
As
IndentationResult
?
If
triviaOpt
.
HasValue
Then
Dim
trivia
=
triviaOpt
.
Value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录