Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c34727d8
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,发现更多精彩内容 >>
未验证
提交
c34727d8
编写于
2月 05, 2020
作者:
A
Allison Chou
提交者:
GitHub
2月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #41377 from allisonchou/ExtractLocalFunctionBug4055
Fix extract local function crash
上级
48b5e934
95cbe4ca
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
166 addition
and
11 deletion
+166
-11
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
...st/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
+152
-0
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
...es/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
+8
-6
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
+2
-2
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.vb
...asic/Portable/ExtractMethod/VisualBasicMethodExtractor.vb
+4
-3
未找到文件。
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
浏览文件 @
c34727d8
...
...
@@ -4282,6 +4282,158 @@ static void NewMethod()
await
TestInRegularAndScriptAsync
(
input
,
expected
,
CodeActionIndex
);
}
[
WorkItem
(
40555
,
"https://github.com/dotnet/roslyn/issues/40555"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestOnLocalFunctionHeader_Parameter
()
{
var
input
=
@"
using System;
class C
{
void M(Action a)
{
M(() =>
{
void F(int [|x|])
{
}
});
}
}"
;
var
expected
=
@"
using System;
class C
{
void M(Action a)
{
M({|Rename:NewMethod|}());
static Action NewMethod()
{
return () =>
{
void F(int x)
{
}
};
}
}
}"
;
await
TestInRegularAndScriptAsync
(
input
,
expected
,
CodeActionIndex
);
}
[
WorkItem
(
40555
,
"https://github.com/dotnet/roslyn/issues/40555"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestOnLocalFunctionHeader_Parameter_ExpressionBody
()
{
var
input
=
@"
using System;
class C
{
void M(Action a)
{
M(() =>
{
int F(int [|x|]) => 1;
});
}
}"
;
var
expected
=
@"
using System;
class C
{
void M(Action a)
{
M({|Rename:NewMethod|}());
static Action NewMethod()
{
return () =>
{
int F(int x) => 1;
};
}
}
}"
;
await
TestInRegularAndScriptAsync
(
input
,
expected
,
CodeActionIndex
);
}
[
WorkItem
(
40555
,
"https://github.com/dotnet/roslyn/issues/40555"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestOnLocalFunctionHeader_Identifier
()
{
var
input
=
@"
using System;
class C
{
void M(Action a)
{
M(() =>
{
void [|F|](int x)
{
}
});
}
}"
;
var
expected
=
@"
using System;
class C
{
void M(Action a)
{
M({|Rename:NewMethod|}());
static Action NewMethod()
{
return () =>
{
void F(int x)
{
}
};
}
}
}"
;
await
TestInRegularAndScriptAsync
(
input
,
expected
,
CodeActionIndex
);
}
[
WorkItem
(
40555
,
"https://github.com/dotnet/roslyn/issues/40555"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestOnLocalFunctionHeader_Identifier_ExpressionBody
()
{
var
input
=
@"
using System;
class C
{
void M(Action a)
{
M(() =>
{
int [|F|](int x) => 1;
});
}
}"
;
var
expected
=
@"
using System;
class C
{
void M(Action a)
{
M({|Rename:NewMethod|}());
static Action NewMethod()
{
return () =>
{
int F(int x) => 1;
};
}
}
}"
;
await
TestInRegularAndScriptAsync
(
input
,
expected
,
CodeActionIndex
);
}
[
WorkItem
(
40654
,
"https://github.com/dotnet/roslyn/issues/40654"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestMissingOnUsingStatement
()
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs
浏览文件 @
c34727d8
...
...
@@ -28,21 +28,23 @@ public CSharpMethodExtractor(CSharpSelectionResult result, bool localFunction)
protected
override
Task
<
AnalyzerResult
>
AnalyzeAsync
(
SelectionResult
selectionResult
,
bool
localFunction
,
CancellationToken
cancellationToken
)
=>
CSharpAnalyzer
.
AnalyzeAsync
(
selectionResult
,
localFunction
,
cancellationToken
);
protected
override
async
Task
<
InsertionPoint
>
GetInsertionPointAsync
(
SemanticDocument
document
,
int
position
,
CancellationToken
cancellationToken
)
protected
override
async
Task
<
InsertionPoint
>
GetInsertionPointAsync
(
SemanticDocument
document
,
CancellationToken
cancellationToken
)
{
Contract
.
ThrowIfFalse
(
position
>=
0
);
var
originalSpanStart
=
OriginalSelectionResult
.
OriginalSpan
.
Start
;
Contract
.
ThrowIfFalse
(
originalSpanStart
>=
0
);
var
root
=
await
document
.
Document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
basePosition
=
root
.
FindToken
(
position
);
var
basePosition
=
root
.
FindToken
(
originalSpanStart
);
if
(
LocalFunction
)
{
// If we are extracting a local function and are within a local function, then we want the new function to be created within the
// existing local function instead of the overarching method.
var
localMethodNode
=
basePosition
.
GetAncestor
<
LocalFunctionStatementSyntax
>(
node
=>
node
.
SpanStart
!=
basePosition
.
SpanStart
);
if
(
localMethodNode
is
object
)
var
localFunctionNode
=
basePosition
.
GetAncestor
<
LocalFunctionStatementSyntax
>(
node
=>
(
node
.
Body
!=
null
&&
node
.
Body
.
Span
.
Contains
(
OriginalSelectionResult
.
OriginalSpan
))
||
(
node
.
ExpressionBody
!=
null
&&
node
.
ExpressionBody
.
Span
.
Contains
(
OriginalSelectionResult
.
OriginalSpan
)));
if
(
localFunctionNode
is
object
)
{
return
await
InsertionPoint
.
CreateAsync
(
document
,
local
Method
Node
,
cancellationToken
).
ConfigureAwait
(
false
);
return
await
InsertionPoint
.
CreateAsync
(
document
,
local
Function
Node
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
...
...
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
浏览文件 @
c34727d8
...
...
@@ -27,7 +27,7 @@ public MethodExtractor(SelectionResult selectionResult, bool localFunction)
}
protected
abstract
Task
<
AnalyzerResult
>
AnalyzeAsync
(
SelectionResult
selectionResult
,
bool
localFunction
,
CancellationToken
cancellationToken
);
protected
abstract
Task
<
InsertionPoint
>
GetInsertionPointAsync
(
SemanticDocument
document
,
int
position
,
CancellationToken
cancellationToken
);
protected
abstract
Task
<
InsertionPoint
>
GetInsertionPointAsync
(
SemanticDocument
document
,
CancellationToken
cancellationToken
);
protected
abstract
Task
<
TriviaResult
>
PreserveTriviaAsync
(
SelectionResult
selectionResult
,
CancellationToken
cancellationToken
);
protected
abstract
Task
<
SemanticDocument
>
ExpandAsync
(
SelectionResult
selection
,
CancellationToken
cancellationToken
);
...
...
@@ -53,7 +53,7 @@ public async Task<ExtractMethodResult> ExtractMethodAsync(CancellationToken canc
return
new
FailedExtractMethodResult
(
operationStatus
);
}
var
insertionPoint
=
await
GetInsertionPointAsync
(
analyzeResult
.
SemanticDocument
,
OriginalSelectionResult
.
OriginalSpan
.
Start
,
cancellationToken
).
ConfigureAwait
(
false
);
var
insertionPoint
=
await
GetInsertionPointAsync
(
analyzeResult
.
SemanticDocument
,
cancellationToken
).
ConfigureAwait
(
false
);
cancellationToken
.
ThrowIfCancellationRequested
();
var
triviaResult
=
await
PreserveTriviaAsync
(
OriginalSelectionResult
.
With
(
insertionPoint
.
SemanticDocument
),
cancellationToken
).
ConfigureAwait
(
false
);
...
...
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.vb
浏览文件 @
c34727d8
...
...
@@ -24,11 +24,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
Return
VisualBasicAnalyzer
.
AnalyzeResultAsync
(
selectionResult
,
cancellationToken
)
End
Function
Protected
Overrides
Async
Function
GetInsertionPointAsync
(
document
As
SemanticDocument
,
position
As
Integer
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
InsertionPoint
)
Contract
.
ThrowIfFalse
(
position
>=
0
)
Protected
Overrides
Async
Function
GetInsertionPointAsync
(
document
As
SemanticDocument
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
InsertionPoint
)
Dim
originalSpanStart
=
OriginalSelectionResult
.
OriginalSpan
.
Start
Contract
.
ThrowIfFalse
(
originalSpanStart
>=
0
)
Dim
root
=
Await
document
.
Document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
False
)
Dim
basePosition
=
root
.
FindToken
(
position
)
Dim
basePosition
=
root
.
FindToken
(
originalSpanStart
)
Dim
enclosingTopLevelNode
As
SyntaxNode
=
basePosition
.
GetAncestor
(
Of
PropertyBlockSyntax
)()
If
enclosingTopLevelNode
Is
Nothing
Then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录