Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b9a3e825
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,发现更多精彩内容 >>
提交
b9a3e825
编写于
5月 04, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix crash in AddUsing when changing casing of a typename.
上级
ca1b475e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
79 addition
and
25 deletion
+79
-25
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
+16
-14
src/Features/Core/Portable/AddImport/References/SymbolReference.cs
...res/Core/Portable/AddImport/References/SymbolReference.cs
+10
-7
未找到文件。
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests.cs
浏览文件 @
b9a3e825
...
...
@@ -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
浏览文件 @
b9a3e825
...
...
@@ -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
浏览文件 @
b9a3e825
...
...
@@ -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
浏览文件 @
b9a3e825
...
...
@@ -92,14 +92,11 @@ 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
())
if
(
this
.
SearchResult
.
DesiredNameDiffersFromSourceName
())
{
return
;
}
var
identifier
=
SearchResult
.
NameNode
.
GetFirstToken
();
var
generator
=
SyntaxGenerator
.
GetGenerator
(
document
);
var
newIdentifier
=
generator
.
IdentifierName
(
SearchResult
.
DesiredName
).
GetFirstToken
().
WithTriviaFrom
(
identifier
);
...
...
@@ -108,7 +105,12 @@ 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
currentRoot
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
contextNode
=
currentRoot
.
GetAnnotatedTokens
(
annotation
).
First
().
Parent
;
}
return
(
contextNode
,
document
);
}
public
abstract
Task
<
CodeAction
>
CreateCodeActionAsync
(
Document
document
,
SyntaxNode
node
,
bool
placeSystemNamespaceFirst
,
CancellationToken
cancellationToken
);
...
...
src/Features/Core/Portable/AddImport/References/SymbolReference.cs
浏览文件 @
b9a3e825
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录