Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
00181a01
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,发现更多精彩内容 >>
提交
00181a01
编写于
6月 07, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass along a syntax facts service.
上级
b80b7040
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
23 deletion
+39
-23
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
...rmatting/Indentation/CSharpIndentationService.Indenter.cs
+3
-1
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.cs
...CSharp/Formatting/Indentation/CSharpIndentationService.cs
+5
-2
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
...martIndent/AbstractIndentationService.AbstractIndenter.cs
+11
-12
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.cs
.../Implementation/SmartIndent/AbstractIndentationService.cs
+8
-4
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.Indenter.vb
...ing/Indentation/VisualBasicIndentationService.Indenter.vb
+4
-2
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.vb
...c/Formatting/Indentation/VisualBasicIndentationService.vb
+8
-2
未找到文件。
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
浏览文件 @
00181a01
...
...
@@ -11,6 +11,7 @@
using
Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -24,12 +25,13 @@ internal partial class CSharpIndentationService
internal
class
Indenter
:
AbstractIndenter
{
public
Indenter
(
ISyntaxFactsService
syntaxFacts
,
SyntaxTree
syntaxTree
,
IEnumerable
<
IFormattingRule
>
rules
,
OptionSet
optionSet
,
TextLine
line
,
CancellationToken
cancellationToken
)
:
base
(
syntaxTree
,
rules
,
optionSet
,
line
,
cancellationToken
)
base
(
syntax
Facts
,
syntax
Tree
,
rules
,
optionSet
,
line
,
cancellationToken
)
{
}
...
...
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.cs
浏览文件 @
00181a01
...
...
@@ -12,6 +12,7 @@
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -31,9 +32,11 @@ protected override IFormattingRule GetSpecializedIndentationFormattingRule()
}
protected
override
AbstractIndenter
GetIndenter
(
SyntaxTree
syntaxTree
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
ISyntaxFactsService
syntaxFacts
,
SyntaxTree
syntaxTree
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
return
new
Indenter
(
syntaxTree
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
);
return
new
Indenter
(
syntaxFacts
,
syntaxTree
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
);
}
protected
override
bool
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
...
...
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
浏览文件 @
00181a01
...
...
@@ -4,7 +4,6 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.Editor.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.LanguageServices
;
...
...
@@ -12,7 +11,6 @@
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.Text.Shared.Extensions
;
using
Microsoft.VisualStudio.Text
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
{
...
...
@@ -21,7 +19,6 @@ internal abstract partial class AbstractIndentationService
internal
abstract
class
AbstractIndenter
{
protected
readonly
OptionSet
OptionSet
;
protected
readonly
SyntacticDocument
Document
;
protected
readonly
TextLine
LineToBeIndented
;
protected
readonly
int
TabSize
;
protected
readonly
CancellationToken
CancellationToken
;
...
...
@@ -32,25 +29,30 @@ internal abstract class AbstractIndenter
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
;
public
AbstractIndenter
(
ISyntaxFactsService
syntaxFacts
,
SyntaxTree
syntaxTree
,
IEnumerable
<
IFormattingRule
>
rules
,
OptionSet
optionSet
,
TextLine
lineToBeIndented
,
CancellationToken
cancellationToken
)
{
var
syntaxRoot
=
syntaxTree
.
GetRoot
(
cancellationToken
);
this
.
_syntaxFacts
=
syntaxFacts
;
this
.
OptionSet
=
optionSet
;
this
.
Tree
=
syntaxTree
;
this
.
LineToBeIndented
=
lineToBeIndented
;
this
.
TabSize
=
this
.
OptionSet
.
GetOption
(
FormattingOptions
.
TabSize
,
this
.
Document
.
Root
.
Language
);
this
.
TabSize
=
this
.
OptionSet
.
GetOption
(
FormattingOptions
.
TabSize
,
syntax
Root
.
Language
);
this
.
CancellationToken
=
cancellationToken
;
this
.
Rules
=
rules
;
this
.
Finder
=
new
BottomUpBaseIndentationFinder
(
new
ChainedFormattingRules
(
this
.
Rules
,
OptionSet
),
this
.
TabSize
,
this
.
OptionSet
.
GetOption
(
FormattingOptions
.
IndentationSize
,
this
.
Document
.
Root
.
Language
),
this
.
OptionSet
.
GetOption
(
FormattingOptions
.
IndentationSize
,
syntax
Root
.
Language
),
tokenStream
:
null
,
lastToken
:
default
(
SyntaxToken
));
}
...
...
@@ -87,15 +89,13 @@ protected IndentationResult GetIndentationOfLine(TextLine lineToMatch, int added
protected
IndentationResult
GetIndentationOfPosition
(
int
position
,
int
addedSpaces
)
{
var
tree
=
Document
.
SyntaxTree
;
if
(
tree
.
OverlapsHiddenPosition
(
GetNormalizedSpan
(
position
),
CancellationToken
))
if
(
this
.
Tree
.
OverlapsHiddenPosition
(
GetNormalizedSpan
(
position
),
CancellationToken
))
{
// Oops, the line we want to line up to is either hidden, or is in a different
// visible region.
var
root
=
tree
.
GetRoot
(
CancellationToken
.
None
);
var
root
=
t
his
.
T
ree
.
GetRoot
(
CancellationToken
.
None
);
var
token
=
root
.
FindTokenFromEnd
(
LineToBeIndented
.
Start
);
var
indentation
=
Finder
.
GetIndentationOfCurrentPosition
(
tree
,
token
,
LineToBeIndented
.
Start
,
CancellationToken
.
None
);
var
indentation
=
Finder
.
GetIndentationOfCurrentPosition
(
t
his
.
T
ree
,
token
,
LineToBeIndented
.
Start
,
CancellationToken
.
None
);
return
new
IndentationResult
(
LineToBeIndented
.
Start
,
indentation
);
}
...
...
@@ -125,7 +125,6 @@ private TextSpan GetNormalizedSpan(int position)
return
null
;
}
var
syntaxFacts
=
this
.
Document
.
Document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
sourceText
=
this
.
LineToBeIndented
.
Text
;
var
lineNumber
=
this
.
LineToBeIndented
.
LineNumber
-
1
;
...
...
@@ -150,7 +149,7 @@ private TextSpan GetNormalizedSpan(int position)
// This line is inside an inactive region. Examine the
// first preceding line not in an inactive region.
var
disabledSpan
=
syntaxFacts
.
GetInactiveRegionSpanAroundPosition
(
this
.
Tree
,
actualLine
.
Span
.
Start
,
CancellationToken
);
var
disabledSpan
=
_
syntaxFacts
.
GetInactiveRegionSpanAroundPosition
(
this
.
Tree
,
actualLine
.
Span
.
Start
,
CancellationToken
);
if
(
disabledSpan
!=
default
(
TextSpan
))
{
var
targetLine
=
sourceText
.
Lines
.
GetLineFromPosition
(
disabledSpan
.
Start
).
LineNumber
;
...
...
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.cs
浏览文件 @
00181a01
...
...
@@ -3,12 +3,12 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Formatting.Rules
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.VisualStudio.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
...
...
@@ -42,12 +42,16 @@ private IEnumerable<IFormattingRule> GetFormattingRules(Document document, int p
return
null
;
}
var
indenter
=
GetIndenter
(
root
.
SyntaxTree
,
lineToBeIndented
,
formattingRules
,
document
.
Options
,
cancellationToken
);
var
indenter
=
GetIndenter
(
document
.
GetLanguageService
<
ISyntaxFactsService
>(),
root
.
SyntaxTree
,
lineToBeIndented
,
formattingRules
,
document
.
Options
,
cancellationToken
);
return
indenter
.
GetDesiredIndentation
();
}
protected
abstract
AbstractIndenter
GetIndenter
(
SyntaxTree
syntaxTree
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
);
ISyntaxFactsService
syntaxFacts
,
SyntaxTree
syntaxTree
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
);
protected
abstract
bool
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
IEnumerable
<
IFormattingRule
>
formattingRules
,
SyntaxNode
root
,
TextLine
line
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
);
...
...
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.Indenter.vb
浏览文件 @
00181a01
...
...
@@ -3,6 +3,7 @@
Imports
System.Threading
Imports
Microsoft.CodeAnalysis.Formatting
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.LanguageServices
Imports
Microsoft.CodeAnalysis.Options
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.Text.Shared.Extensions
...
...
@@ -14,12 +15,13 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Private
Class
Indenter
Inherits
AbstractIndenter
Public
Sub
New
(
syntaxTree
As
SyntaxTree
,
Public
Sub
New
(
syntaxFacts
As
ISyntaxFactsService
,
syntaxTree
As
SyntaxTree
,
rules
As
IEnumerable
(
Of
IFormattingRule
),
optionSet
As
OptionSet
,
line
As
TextLine
,
cancellationToken
As
CancellationToken
)
MyBase
.
New
(
syntaxTree
,
rules
,
optionSet
,
line
,
cancellationToken
)
MyBase
.
New
(
syntax
Facts
,
syntax
Tree
,
rules
,
optionSet
,
line
,
cancellationToken
)
End
Sub
Public
Overrides
Function
GetDesiredIndentation
()
As
IndentationResult
?
...
...
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.vb
浏览文件 @
00181a01
...
...
@@ -6,6 +6,7 @@ Imports Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
Imports
Microsoft.CodeAnalysis.Formatting.Rules
Imports
Microsoft.CodeAnalysis.Host
Imports
Microsoft.CodeAnalysis.Host.Mef
Imports
Microsoft.CodeAnalysis.LanguageServices
Imports
Microsoft.CodeAnalysis.Options
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.Text.Shared.Extensions
...
...
@@ -23,8 +24,13 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Return
s_instance
End
Function
Protected
Overrides
Function
GetIndenter
(
syntaxTree
As
SyntaxTree
,
lineToBeIndented
As
TextLine
,
formattingRules
As
IEnumerable
(
Of
IFormattingRule
),
optionSet
As
OptionSet
,
cancellationToken
As
CancellationToken
)
As
AbstractIndenter
Return
New
Indenter
(
syntaxTree
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
)
Protected
Overrides
Function
GetIndenter
(
syntaxFacts
As
ISyntaxFactsService
,
syntaxTree
As
SyntaxTree
,
lineToBeIndented
As
TextLine
,
formattingRules
As
IEnumerable
(
Of
IFormattingRule
),
optionSet
As
OptionSet
,
cancellationToken
As
CancellationToken
)
As
AbstractIndenter
Return
New
Indenter
(
syntaxFacts
,
syntaxTree
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
)
End
Function
Protected
Overrides
Function
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
formattingRules
As
IEnumerable
(
Of
IFormattingRule
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录