Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
11ed85f5
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,发现更多精彩内容 >>
提交
11ed85f5
编写于
2月 12, 2019
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Keep track of the original compilation when navigating to metadata
Fixes #6859
上级
5c4bd7a7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
24 addition
and
33 deletion
+24
-33
src/EditorFeatures/CSharp/DecompiledSource/CSharpDecompiledSourceService.cs
.../CSharp/DecompiledSource/CSharpDecompiledSourceService.cs
+3
-5
src/EditorFeatures/Core/IDecompiledSourceService.cs
src/EditorFeatures/Core/IDecompiledSourceService.cs
+2
-1
src/EditorFeatures/Core/Implementation/MetadataAsSource/MetadataAsSourceFileService.cs
...mentation/MetadataAsSource/MetadataAsSourceFileService.cs
+3
-2
src/Features/CSharp/Portable/MetadataAsSource/CSharpMetadataAsSourceService.cs
...ortable/MetadataAsSource/CSharpMetadataAsSourceService.cs
+2
-3
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs
...table/MetadataAsSource/AbstractMetadataAsSourceService.cs
+8
-3
src/Features/Core/Portable/MetadataAsSource/IMetadataAsSourceService.cs
...ore/Portable/MetadataAsSource/IMetadataAsSourceService.cs
+3
-2
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
...Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
+1
-13
src/Features/VisualBasic/Portable/MetadataAsSource/VisualBasicMetadataAsSourceService.vb
...le/MetadataAsSource/VisualBasicMetadataAsSourceService.vb
+2
-4
未找到文件。
src/EditorFeatures/CSharp/DecompiledSource/CSharpDecompiledSourceService.cs
浏览文件 @
11ed85f5
...
...
@@ -38,14 +38,12 @@ public CSharpDecompiledSourceService(HostLanguageServices provider)
this
.
provider
=
provider
;
}
public
async
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
public
async
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
{
// Get the name of the type the symbol is in
var
containingOrThis
=
symbol
.
GetContainingTypeOrThis
();
var
fullName
=
GetFullReflectionName
(
containingOrThis
);
var
compilation
=
await
document
.
Project
.
GetCompilationAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
string
assemblyLocation
=
null
;
var
isReferenceAssembly
=
symbol
.
ContainingAssembly
.
GetAttributes
().
Any
(
attribute
=>
attribute
.
AttributeClass
.
Name
==
nameof
(
ReferenceAssemblyAttribute
)
&&
attribute
.
AttributeClass
.
ToNameDisplayString
()
==
typeof
(
ReferenceAssemblyAttribute
).
FullName
);
...
...
@@ -63,7 +61,7 @@ public async Task<Document> AddSourceToAsync(Document document, ISymbol symbol,
if
(
assemblyLocation
==
null
)
{
var
reference
=
MetadataAsSourceHelpers
.
TryGetAssemblyReference
(
compilation
,
symbol
.
ContainingAssembly
);
var
reference
=
symbolCompilation
.
GetMetadataReference
(
symbol
.
ContainingAssembly
);
assemblyLocation
=
(
reference
as
PortableExecutableReference
)?.
FilePath
;
if
(
assemblyLocation
==
null
)
{
...
...
@@ -72,7 +70,7 @@ public async Task<Document> AddSourceToAsync(Document document, ISymbol symbol,
}
// Decompile
document
=
PerformDecompilation
(
document
,
fullName
,
c
ompilation
,
assemblyLocation
);
document
=
PerformDecompilation
(
document
,
fullName
,
symbolC
ompilation
,
assemblyLocation
);
document
=
await
AddAssemblyInfoRegionAsync
(
document
,
symbol
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
src/EditorFeatures/Core/IDecompiledSourceService.cs
浏览文件 @
11ed85f5
...
...
@@ -14,9 +14,10 @@ internal interface IDecompiledSourceService : ILanguageService
/// into the given document
/// </summary>
/// <param name="document">The document to generate source into</param>
/// <param name="symbolCompilation">The <see cref="Compilation"/> in which symbol is resolved.</param>
/// <param name="symbol">The symbol to generate source for</param>
/// <param name="cancellationToken">To cancel document operations</param>
/// <returns>The updated document</returns>
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
);
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
);
}
}
src/EditorFeatures/Core/Implementation/MetadataAsSource/MetadataAsSourceFileService.cs
浏览文件 @
11ed85f5
...
...
@@ -91,6 +91,7 @@ public async Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, I
Location
navigateLocation
=
null
;
var
topLevelNamedType
=
MetadataAsSourceHelpers
.
GetTopLevelContainingNamedType
(
symbol
);
var
symbolId
=
SymbolKey
.
Create
(
symbol
,
cancellationToken
);
var
compilation
=
await
project
.
GetCompilationAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
using
(
await
_gate
.
DisposableWaitAsync
(
cancellationToken
).
ConfigureAwait
(
false
))
{
...
...
@@ -123,7 +124,7 @@ public async Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, I
var
decompiledSourceService
=
temporaryDocument
.
GetLanguageService
<
IDecompiledSourceService
>();
if
(
decompiledSourceService
!=
null
)
{
temporaryDocument
=
await
decompiledSourceService
.
AddSourceToAsync
(
temporaryDocument
,
symbol
,
cancellationToken
).
ConfigureAwait
(
false
);
temporaryDocument
=
await
decompiledSourceService
.
AddSourceToAsync
(
temporaryDocument
,
compilation
,
symbol
,
cancellationToken
).
ConfigureAwait
(
false
);
}
else
{
...
...
@@ -139,7 +140,7 @@ public async Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, I
if
(!
useDecompiler
)
{
var
sourceFromMetadataService
=
temporaryDocument
.
Project
.
LanguageServices
.
GetService
<
IMetadataAsSourceService
>();
temporaryDocument
=
await
sourceFromMetadataService
.
AddSourceToAsync
(
temporaryDocument
,
symbol
,
cancellationToken
).
ConfigureAwait
(
false
);
temporaryDocument
=
await
sourceFromMetadataService
.
AddSourceToAsync
(
temporaryDocument
,
compilation
,
symbol
,
cancellationToken
).
ConfigureAwait
(
false
);
}
// We have the content, so write it out to disk
...
...
src/Features/CSharp/Portable/MetadataAsSource/CSharpMetadataAsSourceService.cs
浏览文件 @
11ed85f5
...
...
@@ -31,11 +31,10 @@ public CSharpMetadataAsSourceService(HostLanguageServices languageServices)
{
}
protected
override
async
Task
<
Document
>
AddAssemblyInfoRegionAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
protected
override
async
Task
<
Document
>
AddAssemblyInfoRegionAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
{
string
assemblyInfo
=
MetadataAsSourceHelpers
.
GetAssemblyInfo
(
symbol
.
ContainingAssembly
);
var
compilation
=
await
document
.
Project
.
GetCompilationAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
string
assemblyPath
=
MetadataAsSourceHelpers
.
GetAssemblyDisplay
(
compilation
,
symbol
.
ContainingAssembly
);
string
assemblyPath
=
MetadataAsSourceHelpers
.
GetAssemblyDisplay
(
symbolCompilation
,
symbol
.
ContainingAssembly
);
var
regionTrivia
=
SyntaxFactory
.
RegionDirectiveTrivia
(
true
)
.
WithTrailingTrivia
(
new
[]
{
SyntaxFactory
.
Space
,
SyntaxFactory
.
PreprocessingMessage
(
assemblyInfo
)
});
...
...
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs
浏览文件 @
11ed85f5
...
...
@@ -26,7 +26,7 @@ protected AbstractMetadataAsSourceService(ICodeGenerationService codeGenerationS
_codeGenerationService
=
codeGenerationService
;
}
public
async
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
public
async
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
)
{
if
(
document
==
null
)
{
...
...
@@ -47,7 +47,7 @@ public async Task<Document> AddSourceToAsync(Document document, ISymbol symbol,
var
docCommentFormattingService
=
document
.
GetLanguageService
<
IDocumentationCommentFormattingService
>();
var
docWithDocComments
=
await
ConvertDocCommentsToRegularComments
(
document
,
docCommentFormattingService
,
cancellationToken
).
ConfigureAwait
(
false
);
var
docWithAssemblyInfo
=
await
AddAssemblyInfoRegionAsync
(
docWithDocComments
,
symbol
.
GetOriginalUnreducedDefinition
(),
cancellationToken
).
ConfigureAwait
(
false
);
var
docWithAssemblyInfo
=
await
AddAssemblyInfoRegionAsync
(
docWithDocComments
,
symbol
Compilation
,
symbol
.
GetOriginalUnreducedDefinition
(),
cancellationToken
).
ConfigureAwait
(
false
);
var
node
=
await
docWithAssemblyInfo
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
formattedDoc
=
await
Formatter
.
FormatAsync
(
docWithAssemblyInfo
,
SpecializedCollections
.
SingletonEnumerable
(
node
.
FullSpan
),
options
:
null
,
rules
:
GetFormattingRules
(
docWithAssemblyInfo
),
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -68,7 +68,12 @@ public async Task<Document> AddSourceToAsync(Document document, ISymbol symbol,
/// a string similar to "location unknown" will be placed in the comment inside the region
/// instead of the path.
/// </summary>
protected
abstract
Task
<
Document
>
AddAssemblyInfoRegionAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
);
/// <param name="document">The document to generate source into</param>
/// <param name="symbolCompilation">The <see cref="Compilation"/> in which symbol is resolved.</param>
/// <param name="symbol">The symbol to generate source for</param>
/// <param name="cancellationToken">To cancel document operations</param>
/// <returns>The updated document</returns>
protected
abstract
Task
<
Document
>
AddAssemblyInfoRegionAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
);
protected
abstract
Task
<
Document
>
ConvertDocCommentsToRegularComments
(
Document
document
,
IDocumentationCommentFormattingService
docCommentFormattingService
,
CancellationToken
cancellationToken
);
...
...
src/Features/Core/Portable/MetadataAsSource/IMetadataAsSourceService.cs
浏览文件 @
11ed85f5
...
...
@@ -14,9 +14,10 @@ internal interface IMetadataAsSourceService : ILanguageService
/// which the given ISymbol is or is a part of into the given document
/// </summary>
/// <param name="document">The document to generate source into</param>
/// <param name="symbol">The symbol whose interface to generate source for</param>
/// <param name="symbolCompilation">The <see cref="Compilation"/> in which <paramref name="symbol"/> is resolved.</param>
/// <param name="symbol">The symbol to generate source for</param>
/// <param name="cancellationToken">To cancel document operations</param>
/// <returns>The updated document</returns>
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
ISymbol
symbol
,
CancellationToken
cancellationToken
=
default
);
Task
<
Document
>
AddSourceToAsync
(
Document
document
,
Compilation
symbolCompilation
,
ISymbol
symbol
,
CancellationToken
cancellationToken
=
default
);
}
}
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
浏览文件 @
11ed85f5
...
...
@@ -51,22 +51,10 @@ public static string GetAssemblyDisplay(Compilation compilation, IAssemblySymbol
// This method is only used to generate a comment at the top of Metadata-as-Source documents and
// previous submissions are never viewed as metadata (i.e. we always have compilations) so there's no
// need to consume compilation.ScriptCompilationInfo.PreviousScriptCompilation.
var
assemblyReference
=
TryGetAssemblyReference
(
compilation
,
assemblySymbol
);
var
assemblyReference
=
compilation
.
GetMetadataReference
(
assemblySymbol
);
return
assemblyReference
?.
Display
??
FeaturesResources
.
location_unknown
;
}
public
static
MetadataReference
TryGetAssemblyReference
(
Compilation
compilation
,
IAssemblySymbol
assemblySymbol
)
{
return
compilation
.
References
.
Where
(
r
=>
{
var
referencedSymbol
=
compilation
.
GetAssemblyOrModuleSymbol
(
r
)
as
IAssemblySymbol
;
return
referencedSymbol
!=
null
&&
referencedSymbol
.
MetadataName
==
assemblySymbol
.
MetadataName
;
})
.
FirstOrDefault
();
}
public
static
INamedTypeSymbol
GetTopLevelContainingNamedType
(
ISymbol
symbol
)
{
// Traverse up until we find a named type that is parented by the namespace
...
...
src/Features/VisualBasic/Portable/MetadataAsSource/VisualBasicMetadataAsSourceService.vb
浏览文件 @
11ed85f5
...
...
@@ -11,7 +11,6 @@ Imports Microsoft.CodeAnalysis.MetadataAsSource
Imports
Microsoft.CodeAnalysis.Options
Imports
Microsoft.CodeAnalysis.Simplification
Imports
Microsoft.CodeAnalysis.VisualBasic
Imports
Microsoft.CodeAnalysis.VisualBasic.DocumentationComments
Imports
Microsoft.CodeAnalysis.VisualBasic.Simplification
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -25,10 +24,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.MetadataAsSource
MyBase
.
New
(
languageServices
.
GetService
(
Of
ICodeGenerationService
)())
End
Sub
Protected
Overrides
Async
Function
AddAssemblyInfoRegionAsync
(
document
As
Document
,
symbol
As
ISymbol
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
Document
)
Protected
Overrides
Async
Function
AddAssemblyInfoRegionAsync
(
document
As
Document
,
symbol
Compilation
As
Compilation
,
symbol
As
ISymbol
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
Document
)
Dim
assemblyInfo
=
MetadataAsSourceHelpers
.
GetAssemblyInfo
(
symbol
.
ContainingAssembly
)
Dim
compilation
=
Await
document
.
Project
.
GetCompilationAsync
(
cancellationToken
).
ConfigureAwait
(
False
)
Dim
assemblyPath
=
MetadataAsSourceHelpers
.
GetAssemblyDisplay
(
compilation
,
symbol
.
ContainingAssembly
)
Dim
assemblyPath
=
MetadataAsSourceHelpers
.
GetAssemblyDisplay
(
symbolCompilation
,
symbol
.
ContainingAssembly
)
Dim
regionTrivia
=
SyntaxFactory
.
RegionDirectiveTrivia
(
SyntaxFactory
.
Token
(
SyntaxKind
.
HashToken
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录