Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b80b7040
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,发现更多精彩内容 >>
提交
b80b7040
编写于
6月 07, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make 'SplitStringLiteral' fully synchronous.
上级
1b69ef7a
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
58 addition
and
86 deletion
+58
-86
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
...rmatting/Indentation/CSharpIndentationService.Indenter.cs
+2
-2
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.cs
...CSharp/Formatting/Indentation/CSharpIndentationService.cs
+3
-4
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.InterpolatedStringSplitter.cs
...StringLiteralCommandHandler.InterpolatedStringSplitter.cs
+2
-2
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.SimpleStringSplitter.cs
.../SplitStringLiteralCommandHandler.SimpleStringSplitter.cs
+2
-2
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.StringSplitter.cs
...iteral/SplitStringLiteralCommandHandler.StringSplitter.cs
+14
-16
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.cs
...rp/SplitStringLiteral/SplitStringLiteralCommandHandler.cs
+7
-8
src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs
...s/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs
+4
-4
src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterEnterOnTokenTests.cs
.../Formatting/Indentation/SmartIndenterEnterOnTokenTests.cs
+1
-1
src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs
...s/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs
+3
-3
src/EditorFeatures/Core/Implementation/Formatting/Indentation/AbstractSmartTokenFormatterCommandHandler.cs
.../Indentation/AbstractSmartTokenFormatterCommandHandler.cs
+2
-2
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
...martIndent/AbstractIndentationService.AbstractIndenter.cs
+2
-3
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.cs
.../Implementation/SmartIndent/AbstractIndentationService.cs
+6
-6
src/EditorFeatures/Core/Implementation/SmartIndent/IIndentationService.cs
...es/Core/Implementation/SmartIndent/IIndentationService.cs
+1
-1
src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndent.cs
...orFeatures/Core/Implementation/SmartIndent/SmartIndent.cs
+5
-27
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.Indenter.vb
...ing/Indentation/VisualBasicIndentationService.Indenter.vb
+2
-2
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.vb
...c/Formatting/Indentation/VisualBasicIndentationService.vb
+2
-3
未找到文件。
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.Indenter.cs
浏览文件 @
b80b7040
...
...
@@ -24,12 +24,12 @@ internal partial class CSharpIndentationService
internal
class
Indenter
:
AbstractIndenter
{
public
Indenter
(
Synta
cticDocument
document
,
Synta
xTree
syntaxTree
,
IEnumerable
<
IFormattingRule
>
rules
,
OptionSet
optionSet
,
TextLine
line
,
CancellationToken
cancellationToken
)
:
base
(
document
,
rules
,
optionSet
,
line
,
cancellationToken
)
base
(
syntaxTree
,
rules
,
optionSet
,
line
,
cancellationToken
)
{
}
...
...
src/EditorFeatures/CSharp/Formatting/Indentation/CSharpIndentationService.cs
浏览文件 @
b80b7040
...
...
@@ -30,11 +30,10 @@ protected override IFormattingRule GetSpecializedIndentationFormattingRule()
return
s_instance
;
}
protected
override
async
Task
<
AbstractIndenter
>
GetIndenterAsync
(
Document
document
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
protected
override
AbstractIndenter
GetIndenter
(
SyntaxTree
syntaxTree
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
var
syntacticDocument
=
await
SyntacticDocument
.
CreateAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
Indenter
(
syntacticDocument
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
);
return
new
Indenter
(
syntaxTree
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
);
}
protected
override
bool
ShouldUseSmartTokenFormatterInsteadOfIndenter
(
...
...
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.InterpolatedStringSplitter.cs
浏览文件 @
b80b7040
...
...
@@ -15,10 +15,10 @@ private class InterpolatedStringSplitter : StringSplitter
public
InterpolatedStringSplitter
(
Document
document
,
int
position
,
Syntax
Tree
syntaxTree
,
Syntax
Node
root
,
SourceText
sourceText
,
SyntaxNode
root
,
SourceText
sourceText
,
InterpolatedStringExpressionSyntax
interpolatedStringExpression
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
:
base
(
document
,
position
,
syntaxTree
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
)
:
base
(
document
,
position
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
)
{
_interpolatedStringExpression
=
interpolatedStringExpression
;
}
...
...
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.SimpleStringSplitter.cs
浏览文件 @
b80b7040
...
...
@@ -12,8 +12,8 @@ private class SimpleStringSplitter : StringSplitter
private
const
char
QuoteCharacter
=
'"'
;
private
readonly
SyntaxToken
_token
;
public
SimpleStringSplitter
(
Document
document
,
int
position
,
Syntax
Tree
syntaxTree
,
Syntax
Node
root
,
SourceText
sourceText
,
SyntaxToken
token
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
:
base
(
document
,
position
,
syntaxTree
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
)
public
SimpleStringSplitter
(
Document
document
,
int
position
,
SyntaxNode
root
,
SourceText
sourceText
,
SyntaxToken
token
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
:
base
(
document
,
position
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
)
{
_token
=
token
;
}
...
...
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.StringSplitter.cs
浏览文件 @
b80b7040
...
...
@@ -19,17 +19,15 @@ private abstract class StringSplitter
protected
readonly
Document
Document
;
protected
readonly
int
CursorPosition
;
protected
readonly
SourceText
SourceText
;
protected
readonly
SyntaxTree
SyntaxTree
;
protected
readonly
SyntaxNode
Root
;
protected
readonly
int
TabSize
;
protected
readonly
bool
UseTabs
;
protected
readonly
CancellationToken
CancellationToken
;
public
StringSplitter
(
Document
document
,
int
position
,
Syntax
Tree
syntaxTree
,
Syntax
Node
root
,
SourceText
sourceText
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
public
StringSplitter
(
Document
document
,
int
position
,
SyntaxNode
root
,
SourceText
sourceText
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
{
Document
=
document
;
CursorPosition
=
position
;
SyntaxTree
=
syntaxTree
;
Root
=
root
;
SourceText
=
sourceText
;
UseTabs
=
useTabs
;
...
...
@@ -39,7 +37,7 @@ public StringSplitter(Document document, int position, SyntaxTree syntaxTree, Sy
public
static
StringSplitter
Create
(
Document
document
,
int
position
,
Syntax
Tree
syntaxTree
,
Syntax
Node
root
,
SourceText
sourceText
,
SyntaxNode
root
,
SourceText
sourceText
,
bool
useTabs
,
int
tabSize
,
CancellationToken
cancellationToken
)
{
var
token
=
root
.
FindToken
(
position
);
...
...
@@ -47,7 +45,7 @@ public StringSplitter(Document document, int position, SyntaxTree syntaxTree, Sy
if
(
token
.
IsKind
(
SyntaxKind
.
StringLiteralToken
))
{
return
new
SimpleStringSplitter
(
document
,
position
,
syntaxTree
,
root
,
document
,
position
,
root
,
sourceText
,
token
,
useTabs
,
tabSize
,
cancellationToken
);
}
...
...
@@ -56,7 +54,7 @@ public StringSplitter(Document document, int position, SyntaxTree syntaxTree, Sy
if
(
interpolatedStringExpression
!=
null
)
{
return
new
InterpolatedStringSplitter
(
document
,
position
,
syntaxTree
,
root
,
document
,
position
,
root
,
sourceText
,
interpolatedStringExpression
,
useTabs
,
tabSize
,
cancellationToken
);
}
...
...
@@ -92,19 +90,19 @@ private static bool IsInterpolationOpenBrace(SyntaxToken token, int position)
protected
abstract
BinaryExpressionSyntax
CreateSplitString
();
public
async
Task
<
int
?>
TrySplitAsync
()
public
int
?
TrySplit
()
{
if
(!
CheckToken
())
{
return
null
;
}
return
await
TrySplitWorkerAsync
().
ConfigureAwait
(
false
);
return
TrySplitWorker
(
);
}
private
async
Task
<
int
?>
TrySplitWorkerAsync
()
private
int
?
TrySplitWorker
()
{
var
newDocumentAndCaretPosition
=
await
SplitStringAsync
().
ConfigureAwait
(
false
);
var
newDocumentAndCaretPosition
=
SplitString
(
);
if
(
newDocumentAndCaretPosition
==
null
)
{
return
null
;
...
...
@@ -127,7 +125,7 @@ protected static SyntaxToken GetPlusToken()
SyntaxFactory
.
TriviaList
(
SyntaxFactory
.
ElasticCarriageReturnLineFeed
));
}
private
async
Task
<
Tuple
<
Document
,
int
>>
SplitStringAsync
()
private
Tuple
<
Document
,
int
>
SplitString
()
{
var
splitString
=
CreateSplitString
();
...
...
@@ -135,7 +133,7 @@ protected static SyntaxToken GetPlusToken()
var
newRoot
=
Root
.
ReplaceNode
(
nodeToReplace
,
splitString
);
var
rightExpression
=
newRoot
.
GetAnnotatedNodes
(
RightNodeAnnotation
).
Single
();
var
indentString
=
await
GetIndentStringAsync
(
newRoot
).
ConfigureAwait
(
false
);
var
indentString
=
GetIndentString
(
newRoot
);
if
(
indentString
==
null
)
{
return
null
;
...
...
@@ -148,21 +146,21 @@ protected static SyntaxToken GetPlusToken()
return
Tuple
.
Create
(
newDocument2
,
rightExpression
.
Span
.
Start
+
indentString
.
Length
+
StringOpenQuoteLength
());
}
private
async
Task
<
string
>
GetIndentStringAsync
(
SyntaxNode
newRoot
)
private
string
GetIndentString
(
SyntaxNode
newRoot
)
{
var
newDocument
=
Document
.
WithSyntaxRoot
(
newRoot
);
var
indentationService
=
newDocument
.
GetLanguageService
<
IIndentationService
>();
var
originalLineNumber
=
SourceText
.
Lines
.
GetLineFromPosition
(
CursorPosition
).
LineNumber
;
var
desiredIndentation
=
await
indentationService
.
GetDesiredIndentationAsync
(
newDocument
,
originalLineNumber
+
1
,
CancellationToken
)
.
ConfigureAwait
(
false
)
;
var
desiredIndentation
=
indentationService
.
GetDesiredIndentation
(
newDocument
,
originalLineNumber
+
1
,
CancellationToken
);
if
(
desiredIndentation
==
null
)
{
return
null
;
}
var
newSourceText
=
await
newDocument
.
GetTextAsync
(
CancellationToken
).
ConfigureAwait
(
false
);
var
newSourceText
=
newDocument
.
GetSyntaxRootSynchronously
(
CancellationToken
).
SyntaxTree
.
GetText
(
CancellationToken
);
var
baseLine
=
newSourceText
.
Lines
.
GetLineFromPosition
(
desiredIndentation
.
Value
.
BasePosition
);
var
baseOffsetInLine
=
desiredIndentation
.
Value
.
BasePosition
-
baseLine
.
Start
;
...
...
src/EditorFeatures/CSharp/SplitStringLiteral/SplitStringLiteralCommandHandler.cs
浏览文件 @
b80b7040
...
...
@@ -57,8 +57,8 @@ private bool SplitString(ITextView textView, ITextBuffer subjectBuffer, Snapshot
if
(
enabled
)
{
var
cursorPosition
=
SplitStringLiteral
Async
(
subjectBuffer
,
document
,
caret
.
Value
.
Position
,
CancellationToken
.
None
)
.
GetAwaiter
().
GetResult
()
;
var
cursorPosition
=
SplitStringLiteral
(
subjectBuffer
,
document
,
caret
.
Value
.
Position
,
CancellationToken
.
None
);
if
(
cursorPosition
!=
null
)
{
...
...
@@ -95,23 +95,22 @@ private bool LineContainsQuote(ITextSnapshotLine line, int caretPosition)
return
false
;
}
private
async
Task
<
int
?>
SplitStringLiteralAsync
(
private
int
?
SplitStringLiteral
(
ITextBuffer
subjectBuffer
,
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
{
var
useTabs
=
subjectBuffer
.
GetOption
(
FormattingOptions
.
UseTabs
);
var
tabSize
=
subjectBuffer
.
GetOption
(
FormattingOptions
.
TabSize
);
var
syntaxTree
=
await
document
.
GetSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
syntaxTree
.
GetRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
sourceText
=
await
syntaxTree
.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
document
.
GetSyntaxRootSynchronously
(
cancellationToken
);
var
sourceText
=
root
.
SyntaxTree
.
GetText
(
cancellationToken
);
var
splitter
=
StringSplitter
.
Create
(
document
,
position
,
syntaxTree
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
);
var
splitter
=
StringSplitter
.
Create
(
document
,
position
,
root
,
sourceText
,
useTabs
,
tabSize
,
cancellationToken
);
if
(
splitter
==
null
)
{
return
null
;
}
return
await
splitter
.
TrySplitAsync
().
ConfigureAwait
(
false
);
return
splitter
.
TrySplit
(
);
}
}
}
\ No newline at end of file
src/EditorFeatures/CSharpTest/Formatting/Indentation/FormatterTestsBase.cs
浏览文件 @
b80b7040
...
...
@@ -118,7 +118,7 @@ private static void ApplyChanges(ITextBuffer buffer, IList<TextChange> changes)
}
}
internal
static
async
Task
TestIndentationAsync
(
int
point
,
int
?
expectedIndentation
,
ITextView
textView
,
TestHostDocument
subjectDocument
)
internal
static
void
TestIndentation
(
int
point
,
int
?
expectedIndentation
,
ITextView
textView
,
TestHostDocument
subjectDocument
)
{
var
textUndoHistory
=
new
Mock
<
ITextUndoHistoryRegistry
>();
var
editorOperationsFactory
=
new
Mock
<
IEditorOperationsFactoryService
>();
...
...
@@ -140,13 +140,13 @@ internal static async Task TestIndentationAsync(int point, int? expectedIndentat
else
{
var
provider
=
new
SmartIndent
(
textView
);
actualIndentation
=
await
provider
.
GetDesiredIndentationAsync
(
indentationLineFromBuffer
);
actualIndentation
=
provider
.
GetDesiredIndentation
(
indentationLineFromBuffer
);
}
Assert
.
Equal
(
expectedIndentation
,
actualIndentation
.
Value
);
}
public
static
async
Task
TestIndentationAsync
(
int
indentationLine
,
int
?
expectedIndentation
,
TestWorkspace
workspace
)
public
static
void
TestIndentation
(
int
indentationLine
,
int
?
expectedIndentation
,
TestWorkspace
workspace
)
{
var
snapshot
=
workspace
.
Documents
.
First
().
TextBuffer
.
CurrentSnapshot
;
var
bufferGraph
=
new
Mock
<
IBufferGraph
>(
MockBehavior
.
Strict
);
...
...
@@ -180,7 +180,7 @@ public static async Task TestIndentationAsync(int indentationLine, int? expected
var
provider
=
new
SmartIndent
(
textView
.
Object
);
var
indentationLineFromBuffer
=
snapshot
.
GetLineFromLineNumber
(
indentationLine
);
var
actualIndentation
=
await
provider
.
GetDesiredIndentationAsync
(
indentationLineFromBuffer
);
var
actualIndentation
=
provider
.
GetDesiredIndentation
(
indentationLineFromBuffer
);
Assert
.
Equal
(
expectedIndentation
,
actualIndentation
);
}
...
...
src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterEnterOnTokenTests.cs
浏览文件 @
b80b7040
...
...
@@ -1395,7 +1395,7 @@ void Main(object o)
Formatter
.
GetDefaultFormattingRules
(
workspace
,
root
.
Language
),
root
,
line
.
AsTextLine
(),
document
.
Options
,
CancellationToken
.
None
));
await
TestIndentationAsync
(
indentationLine
,
expectedIndentation
,
workspace
);
TestIndentation
(
indentationLine
,
expectedIndentation
,
workspace
);
}
}
}
...
...
src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs
浏览文件 @
b80b7040
...
...
@@ -2709,7 +2709,7 @@ private static async Task AssertSmartIndentInProjectionAsync(string markup, int
var
indentationLine
=
projectedDocument
.
TextBuffer
.
CurrentSnapshot
.
GetLineFromPosition
(
projectedDocument
.
CursorPosition
.
Value
);
var
point
=
projectedDocument
.
GetTextView
().
BufferGraph
.
MapDownToBuffer
(
indentationLine
.
Start
,
PointTrackingMode
.
Negative
,
subjectDocument
.
TextBuffer
,
PositionAffinity
.
Predecessor
);
await
TestIndentationAsync
(
point
.
Value
,
expectedIndentation
,
projectedDocument
.
GetTextView
(),
subjectDocument
);
TestIndentation
(
point
.
Value
,
expectedIndentation
,
projectedDocument
.
GetTextView
(),
subjectDocument
);
}
}
}
...
...
@@ -2728,7 +2728,7 @@ private static async Task AssertSmartIndentInProjectionAsync(string markup, int
{
using
(
var
workspace
=
await
TestWorkspace
.
CreateCSharpAsync
(
code
,
parseOptions
:
option
))
{
await
TestIndentationAsync
(
indentationLine
,
expectedIndentation
,
workspace
);
TestIndentation
(
indentationLine
,
expectedIndentation
,
workspace
);
}
}
}
...
...
@@ -2748,7 +2748,7 @@ private static async Task AssertSmartIndentInProjectionAsync(string markup, int
{
var
wpfTextView
=
workspace
.
Documents
.
First
().
GetTextView
();
var
line
=
wpfTextView
.
TextBuffer
.
CurrentSnapshot
.
GetLineFromPosition
(
wpfTextView
.
Caret
.
Position
.
BufferPosition
).
LineNumber
;
await
TestIndentationAsync
(
line
,
expectedIndentation
,
workspace
);
TestIndentation
(
line
,
expectedIndentation
,
workspace
);
}
}
}
...
...
src/EditorFeatures/Core/Implementation/Formatting/Indentation/AbstractSmartTokenFormatterCommandHandler.cs
浏览文件 @
b80b7040
...
...
@@ -129,8 +129,8 @@ internal void ExecuteCommandWorker(ReturnKeyCommandArgs args, CancellationToken
}
var
indentationService
=
document
.
GetLanguageService
<
IIndentationService
>();
var
indentation
=
indentationService
.
GetDesiredIndentation
Async
(
document
,
currentPosition
.
GetContainingLine
().
LineNumber
,
cancellationToken
)
.
WaitAndGetResult
(
cancellationToken
)
;
var
indentation
=
indentationService
.
GetDesiredIndentation
(
document
,
currentPosition
.
GetContainingLine
().
LineNumber
,
cancellationToken
);
// looks like we can't.
if
(!
indentation
.
HasValue
)
...
...
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.AbstractIndenter.cs
浏览文件 @
b80b7040
...
...
@@ -34,20 +34,19 @@ internal abstract class AbstractIndenter
(
tk
.
LeadingTrivia
.
Any
(
tr
=>
tr
.
IsDirective
)
||
tk
.
TrailingTrivia
.
Any
(
tr
=>
tr
.
IsDirective
));
public
AbstractIndenter
(
Synta
cticDocument
document
,
Synta
xTree
syntaxTree
,
IEnumerable
<
IFormattingRule
>
rules
,
OptionSet
optionSet
,
TextLine
lineToBeIndented
,
CancellationToken
cancellationToken
)
{
this
.
OptionSet
=
optionSet
;
this
.
Document
=
document
;
this
.
Tree
=
syntaxTree
;
this
.
LineToBeIndented
=
lineToBeIndented
;
this
.
TabSize
=
this
.
OptionSet
.
GetOption
(
FormattingOptions
.
TabSize
,
this
.
Document
.
Root
.
Language
);
this
.
CancellationToken
=
cancellationToken
;
this
.
Rules
=
rules
;
this
.
Tree
=
this
.
Document
.
SyntaxTree
;
this
.
Finder
=
new
BottomUpBaseIndentationFinder
(
new
ChainedFormattingRules
(
this
.
Rules
,
OptionSet
),
this
.
TabSize
,
...
...
src/EditorFeatures/Core/Implementation/SmartIndent/AbstractIndentationService.cs
浏览文件 @
b80b7040
...
...
@@ -27,10 +27,10 @@ private IEnumerable<IFormattingRule> GetFormattingRules(Document document, int p
return
formattingRules
;
}
public
async
Task
<
IndentationResult
?>
GetDesiredIndentationAsync
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
)
public
IndentationResult
?
GetDesiredIndentation
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
sourceText
=
await
document
.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
document
.
GetSyntaxRootSynchronously
(
cancellationToken
);
var
sourceText
=
root
.
SyntaxTree
.
GetText
(
cancellationToken
);
var
lineToBeIndented
=
sourceText
.
Lines
[
lineNumber
];
...
...
@@ -42,12 +42,12 @@ private IEnumerable<IFormattingRule> GetFormattingRules(Document document, int p
return
null
;
}
var
indenter
=
await
GetIndenterAsync
(
document
,
lineToBeIndented
,
formattingRules
,
document
.
Options
,
cancellationToken
).
ConfigureAwait
(
false
);
var
indenter
=
GetIndenter
(
root
.
SyntaxTree
,
lineToBeIndented
,
formattingRules
,
document
.
Options
,
cancellationToken
);
return
indenter
.
GetDesiredIndentation
();
}
protected
abstract
Task
<
AbstractIndenter
>
GetIndenterAsync
(
Document
document
,
TextLine
lineToBeIndented
,
IEnumerable
<
IFormattingRule
>
formattingRules
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
);
protected
abstract
AbstractIndenter
GetIndenter
(
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/Core/Implementation/SmartIndent/IIndentationService.cs
浏览文件 @
b80b7040
...
...
@@ -40,6 +40,6 @@ public IndentationResult(int basePosition, int offset) : this()
internal
interface
IIndentationService
:
ILanguageService
{
Task
<
IndentationResult
?>
GetDesiredIndentationAsync
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
);
IndentationResult
?
GetDesiredIndentation
(
Document
document
,
int
lineNumber
,
CancellationToken
cancellationToken
);
}
}
src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndent.cs
浏览文件 @
b80b7040
...
...
@@ -2,14 +2,12 @@
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Editor.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent
{
...
...
@@ -29,19 +27,14 @@ public SmartIndent(ITextView textView)
public
int
?
GetDesiredIndentation
(
ITextSnapshotLine
line
)
{
return
GetDesiredIndentationAsync
(
line
).
WaitAndGetResult
(
CancellationToken
.
None
);
}
internal
Task
<
int
?>
GetDesiredIndentationAsync
(
ITextSnapshotLine
line
)
{
return
GetDesiredIndentationAsync
(
line
,
CancellationToken
.
None
);
return
GetDesiredIndentation
(
line
,
CancellationToken
.
None
);
}
public
void
Dispose
()
{
}
private
async
Task
<
int
?>
GetDesiredIndentationAsync
(
ITextSnapshotLine
lineToBeIndented
,
CancellationToken
cancellationToken
)
private
int
?
GetDesiredIndentation
(
ITextSnapshotLine
lineToBeIndented
,
CancellationToken
cancellationToken
)
{
if
(
lineToBeIndented
==
null
)
{
...
...
@@ -51,24 +44,9 @@ public void Dispose()
using
(
Logger
.
LogBlock
(
FunctionId
.
SmartIndentation_Start
,
cancellationToken
))
{
var
document
=
lineToBeIndented
.
Snapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
if
(
document
==
null
)
{
return
null
;
}
var
service
=
document
.
GetLanguageService
<
IIndentationService
>();
if
(
service
==
null
)
{
return
null
;
}
var
result
=
await
service
.
GetDesiredIndentationAsync
(
document
,
lineToBeIndented
.
LineNumber
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
result
==
null
)
{
return
null
;
}
return
result
.
Value
.
GetIndentation
(
_textView
,
lineToBeIndented
);
var
service
=
document
?.
GetLanguageService
<
IIndentationService
>();
var
result
=
service
?.
GetDesiredIndentation
(
document
,
lineToBeIndented
.
LineNumber
,
cancellationToken
);
return
result
?.
GetIndentation
(
_textView
,
lineToBeIndented
);
}
}
}
...
...
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.Indenter.vb
浏览文件 @
b80b7040
...
...
@@ -14,12 +14,12 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Private
Class
Indenter
Inherits
AbstractIndenter
Public
Sub
New
(
document
As
SyntacticDocument
,
Public
Sub
New
(
syntaxTree
As
SyntaxTree
,
rules
As
IEnumerable
(
Of
IFormattingRule
),
optionSet
As
OptionSet
,
line
As
TextLine
,
cancellationToken
As
CancellationToken
)
MyBase
.
New
(
document
,
rules
,
optionSet
,
line
,
cancellationToken
)
MyBase
.
New
(
syntaxTree
,
rules
,
optionSet
,
line
,
cancellationToken
)
End
Sub
Public
Overrides
Function
GetDesiredIndentation
()
As
IndentationResult
?
...
...
src/EditorFeatures/VisualBasic/Formatting/Indentation/VisualBasicIndentationService.vb
浏览文件 @
b80b7040
...
...
@@ -23,9 +23,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Formatting.Indentation
Return
s_instance
End
Function
Protected
Overrides
Async
Function
GetIndenterAsync
(
document
As
Document
,
lineToBeIndented
As
TextLine
,
formattingRules
As
IEnumerable
(
Of
IFormattingRule
),
optionSet
As
OptionSet
,
cancellationToken
As
CancellationToken
)
As
Tasks
.
Task
(
Of
AbstractIndenter
)
Dim
synDocument
=
Await
SyntacticDocument
.
CreateAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
False
)
Return
New
Indenter
(
synDocument
,
formattingRules
,
optionSet
,
lineToBeIndented
,
cancellationToken
)
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
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录