Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1c155249
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,发现更多精彩内容 >>
提交
1c155249
编写于
5月 05, 2017
作者:
C
CyrusNajmabadi
提交者:
GitHub
5月 05, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19286 from CyrusNajmabadi/addUsingNested
Fix crash in AddUsing when changing casing of a typename.
上级
d2c488a9
bfc2402b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
and
17 deletion
+73
-17
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests.cs
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests.cs
+49
-0
src/Features/Core/Portable/AddImport/CodeActions/PackageReference.ParentCodeAction.cs
...ddImport/CodeActions/PackageReference.ParentCodeAction.cs
+2
-1
src/Features/Core/Portable/AddImport/References/AssemblyReference.cs
...s/Core/Portable/AddImport/References/AssemblyReference.cs
+2
-3
src/Features/Core/Portable/AddImport/References/Reference.cs
src/Features/Core/Portable/AddImport/References/Reference.cs
+10
-6
src/Features/Core/Portable/AddImport/References/SymbolReference.cs
...res/Core/Portable/AddImport/References/SymbolReference.cs
+10
-7
未找到文件。
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests.cs
浏览文件 @
1c155249
...
...
@@ -4554,5 +4554,54 @@ void M()
}
}"
);
}
[
WorkItem
(
19218
,
"https://github.com/dotnet/roslyn/issues/19218"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddImport
)]
public
async
Task
TestChangeCaseWithUsingsInNestedNamespace
()
{
await
TestInRegularAndScriptAsync
(
@"namespace VS
{
interface IVsStatusbar
{
}
}
namespace Outer
{
using System;
class C
{
void M()
{
// Note: IVsStatusBar is cased incorrectly.
[|IVsStatusBar|] b;
}
}
}
"
,
@"namespace VS
{
interface IVsStatusbar
{
}
}
namespace Outer
{
using System;
using VS;
class C
{
void M()
{
IVsStatusbar b;
}
}
}
"
);
}
}
}
\ No newline at end of file
src/Features/Core/Portable/AddImport/CodeActions/PackageReference.ParentCodeAction.cs
浏览文件 @
1c155249
...
...
@@ -107,7 +107,8 @@ private class ParentCodeAction : CodeAction.CodeActionWithNestedActions
CancellationToken
cancellationToken
)
{
var
oldDocument
=
document
;
reference
.
ReplaceNameNode
(
ref
node
,
ref
document
,
cancellationToken
);
(
node
,
document
)
=
await
reference
.
ReplaceNameNodeAsync
(
node
,
document
,
cancellationToken
).
ConfigureAwait
(
false
);
var
newDocument
=
await
reference
.
provider
.
AddImportAsync
(
node
,
reference
.
SearchResult
.
NameParts
,
document
,
placeSystemNamespaceFirst
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
src/Features/Core/Portable/AddImport/References/AssemblyReference.cs
浏览文件 @
1c155249
...
...
@@ -105,9 +105,8 @@ protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperation
var
reference
=
service
.
GetReference
(
resolvedPath
,
MetadataReferenceProperties
.
Assembly
);
// First add the "using/import" directive in the code.
var
node
=
_node
;
var
document
=
_document
;
_reference
.
ReplaceNameNode
(
ref
node
,
ref
document
,
cancellationToken
);
(
SyntaxNode
node
,
Document
document
)
=
await
_reference
.
ReplaceNameNodeAsync
(
_node
,
_document
,
cancellationToken
).
ConfigureAwait
(
false
);
var
newDocument
=
await
_reference
.
provider
.
AddImportAsync
(
node
,
_reference
.
SearchResult
.
NameParts
,
document
,
_placeSystemNamespaceFirst
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
src/Features/Core/Portable/AddImport/References/Reference.cs
浏览文件 @
1c155249
...
...
@@ -92,12 +92,12 @@ public override int GetHashCode()
return
Hash
.
CombineValues
(
this
.
SearchResult
.
NameParts
);
}
protected
void
ReplaceNameNode
(
ref
SyntaxNode
contextNode
,
ref
Document
document
,
CancellationToken
cancellationToken
)
protected
async
Task
<(
SyntaxNode
,
Document
)>
ReplaceNameNodeAsync
(
SyntaxNode
contextNode
,
Document
document
,
CancellationToken
cancellationToken
)
{
if
(!
this
.
SearchResult
.
DesiredNameDiffersFromSourceName
())
{
return
;
return
(
contextNode
,
document
)
;
}
var
identifier
=
SearchResult
.
NameNode
.
GetFirstToken
();
...
...
@@ -107,11 +107,15 @@ public override int GetHashCode()
var
root
=
contextNode
.
SyntaxTree
.
GetRoot
(
cancellationToken
);
root
=
root
.
ReplaceToken
(
identifier
,
newIdentifier
.
WithAdditionalAnnotations
(
annotation
));
document
=
document
.
WithSyntaxRoot
(
root
);
contextNode
=
root
.
GetAnnotatedTokens
(
annotation
).
First
().
Parent
;
var
newDocument
=
document
.
WithSyntaxRoot
(
root
);
var
newRoot
=
await
newDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
newContextNode
=
newRoot
.
GetAnnotatedTokens
(
annotation
).
First
().
Parent
;
return
(
newContextNode
,
newDocument
);
}
public
abstract
Task
<
CodeAction
>
CreateCodeActionAsync
(
Document
document
,
SyntaxNode
node
,
bool
placeSystemNamespaceFirst
,
CancellationToken
cancellationToken
);
}
}
}
}
\ No newline at end of file
src/Features/Core/Portable/AddImport/References/SymbolReference.cs
浏览文件 @
1c155249
...
...
@@ -2,9 +2,11 @@
using
System
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.FindSymbols
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CodeFixes.AddImport
...
...
@@ -61,22 +63,23 @@ public override int GetHashCode()
protected
virtual
Solution
GetUpdatedSolution
(
Document
newDocument
)
=>
newDocument
.
Project
.
Solution
;
private
Task
<
Document
>
UpdateDocumentAsync
(
private
async
Task
<
Document
>
UpdateDocumentAsync
(
Document
document
,
SyntaxNode
contextNode
,
bool
placeSystemNamespaceFirst
,
bool
hasExistingImport
,
CancellationToken
cancellationToken
)
{
ReplaceNameNode
(
ref
contextNode
,
ref
document
,
cancellationToken
);
// Defer to the language to add the actual import/using.
if
(
hasExistingImport
)
{
return
Task
.
FromResult
(
document
)
;
return
document
;
}
return
provider
.
AddImportAsync
(
contextNode
,
this
.
SymbolResult
.
Symbol
,
document
,
placeSystemNamespaceFirst
,
cancellationToken
);
(
var
newContextNode
,
var
newDocument
)
=
await
ReplaceNameNodeAsync
(
contextNode
,
document
,
cancellationToken
).
ConfigureAwait
(
false
);
return
await
provider
.
AddImportAsync
(
newContextNode
,
this
.
SymbolResult
.
Symbol
,
newDocument
,
placeSystemNamespaceFirst
,
cancellationToken
).
ConfigureAwait
(
false
);
}
public
override
async
Task
<
CodeAction
>
CreateCodeActionAsync
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录