Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
75f08f86
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
75f08f86
编写于
9月 30, 2020
作者:
M
msftbot[bot]
提交者:
GitHub
9月 30, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #48167 from dibarbet/disable_file_rename_razor
Disable document rename for razor mapped files
上级
4af4f1a6
91075e24
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
72 addition
and
0 deletion
+72
-0
src/Workspaces/Core/Portable/Rename/Renamer.cs
src/Workspaces/Core/Portable/Rename/Renamer.cs
+7
-0
src/Workspaces/CoreTest/Renamer/CSharpRenamerTests.cs
src/Workspaces/CoreTest/Renamer/CSharpRenamerTests.cs
+13
-0
src/Workspaces/CoreTest/Renamer/RenamerTests.cs
src/Workspaces/CoreTest/Renamer/RenamerTests.cs
+31
-0
src/Workspaces/CoreTestUtilities/TestDocumentServiceProvider.cs
...rkspaces/CoreTestUtilities/TestDocumentServiceProvider.cs
+21
-0
未找到文件。
src/Workspaces/Core/Portable/Rename/Renamer.cs
浏览文件 @
75f08f86
...
...
@@ -8,6 +8,7 @@
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.PooledObjects
;
...
...
@@ -75,6 +76,12 @@ public static partial class Renamer
throw
new
ArgumentNullException
(
nameof
(
document
));
}
if
(
document
.
Services
.
GetService
<
ISpanMappingService
>()
!=
null
)
{
// Don't advertise that we can file rename generated documents that map to a different file.
return
new
RenameDocumentActionSet
(
ImmutableArray
<
RenameDocumentAction
>.
Empty
,
document
.
Id
,
document
.
Name
,
document
.
Folders
.
ToImmutableArray
(),
document
.
Project
.
Solution
.
Options
);
}
using
var
_
=
ArrayBuilder
<
RenameDocumentAction
>.
GetInstance
(
out
var
actions
);
if
(
newDocumentName
!=
null
&&
!
newDocumentName
.
Equals
(
document
.
Name
))
...
...
src/Workspaces/CoreTest/Renamer/CSharpRenamerTests.cs
浏览文件 @
75f08f86
...
...
@@ -5,6 +5,7 @@
#
nullable
disable
using
System.Threading.Tasks
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.UnitTests.Renamer
...
...
@@ -368,5 +369,17 @@ class C2
documentName
:
@"C.cs"
,
newDocumentName
:
@"C2"
,
newDocumentPath
:
@"Test\C2.cs"
);
[
Fact
]
[
WorkItem
(
46580
,
"https://github.com/dotnet/roslyn/issues/46580"
)]
public
Task
CSharp_RenameDocument_MappedDocumentHasNoResults
()
{
var
documentName
=
"Component1.razor"
;
var
documentText
=
@"<h3>Component1</h3>
@code {}"
;
return
TestRenameMappedFile
(
documentText
,
documentName
,
newDocumentName
:
"MyComponent.razor"
);
}
}
}
src/Workspaces/CoreTest/Renamer/RenamerTests.cs
浏览文件 @
75f08f86
...
...
@@ -203,5 +203,36 @@ protected async Task TestEmptyActionSet(string startText, string newDocumentName
Assert
.
Empty
(
documentRenameResult
.
ApplicableActions
);
}
}
protected
async
Task
TestRenameMappedFile
(
string
startText
,
string
documentName
,
string
newDocumentName
)
{
using
var
workspace
=
new
AdhocWorkspace
();
var
solution
=
workspace
.
CurrentSolution
;
var
projectId
=
ProjectId
.
CreateNewId
();
var
projectInfo
=
ProjectInfo
.
Create
(
projectId
,
VersionStamp
.
Create
(),
"ProjectName"
,
"AssemblyName"
,
LanguageName
,
filePath
:
""
);
solution
=
solution
.
AddProject
(
projectInfo
);
var
startSourceText
=
SourceText
.
From
(
startText
);
var
documentId
=
DocumentId
.
CreateNewId
(
projectId
);
var
documentInfo
=
DocumentInfo
.
Create
(
documentId
,
documentName
,
GetDocumentFolders
(
s_defaultDocumentPath
),
SourceCodeKind
.
Regular
,
TextLoader
.
From
(
TextAndVersion
.
Create
(
startSourceText
,
VersionStamp
.
Create
(),
documentName
)),
s_defaultDocumentPath
,
isGenerated
:
true
,
designTimeOnly
:
false
,
new
TestDocumentServiceProvider
());
solution
=
solution
.
AddDocument
(
documentInfo
);
var
document
=
solution
.
GetDocument
(
documentId
);
var
documentRenameResult
=
await
Rename
.
Renamer
.
RenameDocumentAsync
(
document
,
newDocumentName
,
GetDocumentFolders
(
s_defaultDocumentPath
));
Assert
.
Empty
(
documentRenameResult
.
ApplicableActions
);
}
}
}
src/Workspaces/CoreTestUtilities/TestDocumentServiceProvider.cs
浏览文件 @
75f08f86
...
...
@@ -4,7 +4,12 @@
#
nullable
disable
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Text
;
namespace
Microsoft.CodeAnalysis.Test.Utilities
{
...
...
@@ -17,16 +22,24 @@ public TestDocumentServiceProvider(bool canApplyChange = true, bool supportDiagn
CanApplyChange
=
canApplyChange
,
SupportDiagnostics
=
supportDiagnostics
};
SpanMappingService
=
new
TestSpanMappingService
();
}
public
IDocumentOperationService
DocumentOperationService
{
get
;
}
public
ISpanMappingService
SpanMappingService
{
get
;
}
public
TService
GetService
<
TService
>()
where
TService
:
class
,
IDocumentService
{
if
(
DocumentOperationService
is
TService
service
)
{
return
service
;
}
else
if
(
SpanMappingService
is
TService
spanMappingService
)
{
return
spanMappingService
;
}
return
null
;
}
...
...
@@ -40,5 +53,13 @@ public TestDocumentOperationService()
public
bool
CanApplyChange
{
get
;
set
;
}
public
bool
SupportDiagnostics
{
get
;
set
;
}
}
private
class
TestSpanMappingService
:
ISpanMappingService
{
public
Task
<
ImmutableArray
<
MappedSpanResult
>>
MapSpansAsync
(
Document
document
,
IEnumerable
<
TextSpan
>
spans
,
CancellationToken
cancellationToken
)
{
return
Task
.
FromResult
(
ImmutableArray
<
MappedSpanResult
>.
Empty
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录