Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5011213d
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,发现更多精彩内容 >>
未验证
提交
5011213d
编写于
7月 15, 2018
作者:
D
David Poeschl
提交者:
GitHub
7月 15, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #28537 from dotnet/merges/dev15.8.x-to-dev15.9.x
Merge dev15.8.x to dev15.9.x
上级
7108f0c9
824f0259
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
75 addition
and
19 deletion
+75
-19
src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.FormatDocument.cs
...ntation/Formatting/FormatCommandHandler.FormatDocument.cs
+11
-4
src/Features/CSharp/Portable/CodeCleanup/CSharpCodeCleanupService.cs
...s/CSharp/Portable/CodeCleanup/CSharpCodeCleanupService.cs
+20
-8
src/Features/Core/Portable/CodeCleanup/CodeCleanupLogMessage.cs
...atures/Core/Portable/CodeCleanup/CodeCleanupLogMessage.cs
+21
-0
src/Features/Core/Portable/CodeCleanup/CodeCleanupOptions.cs
src/Features/Core/Portable/CodeCleanup/CodeCleanupOptions.cs
+5
-1
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReference.Snapshot.cs
...adataReferences/VisualStudioMetadataReference.Snapshot.cs
+6
-2
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReference.cs
...ystem/MetadataReferences/VisualStudioMetadataReference.cs
+1
-3
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReferenceManager.cs
...etadataReferences/VisualStudioMetadataReferenceManager.cs
+1
-1
src/Workspaces/Core/Portable/Log/FunctionId.cs
src/Workspaces/Core/Portable/Log/FunctionId.cs
+10
-0
未找到文件。
src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.FormatDocument.cs
浏览文件 @
5011213d
...
...
@@ -8,6 +8,8 @@
using
Microsoft.CodeAnalysis.CodeCleanup
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Extensions
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -29,6 +31,7 @@ public VSCommanding.CommandState GetCommandState(FormatDocumentCommandArgs args)
private
void
ShowGoldBarForCodeCleanupConfigurationIfNeeded
(
Document
document
)
{
AssertIsForeground
();
Logger
.
Log
(
FunctionId
.
CodeCleanupInfobar_BarDisplayed
,
KeyValueLogMessage
.
NoProperty
);
var
workspace
=
document
.
Project
.
Solution
.
Workspace
;
...
...
@@ -53,12 +56,14 @@ private void ShowGoldBarForCodeCleanupConfigurationIfNeeded(Document document)
kind
:
InfoBarUI
.
UIKind
.
Button
,
()
=>
{
Logger
.
Log
(
FunctionId
.
CodeCleanupInfobar_ConfigureNow
,
KeyValueLogMessage
.
NoProperty
);
optionPageService
.
ShowFormattingOptionPage
();
}),
new
InfoBarUI
(
EditorFeaturesResources
.
Do_not_show_this_message_again
,
kind
:
InfoBarUI
.
UIKind
.
Button
,
()
=>
{
Logger
.
Log
(
FunctionId
.
CodeCleanupInfobar_NeverShowCodeCleanupInfoBarAgain
,
KeyValueLogMessage
.
NoProperty
);
workspace
.
Options
=
workspace
.
Options
.
WithChangedOption
(
CodeCleanupOptions
.
NeverShowCodeCleanupInfoBarAgain
,
document
.
Project
.
Language
,
value
:
true
);
}));
...
...
@@ -78,6 +83,7 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
}
context
.
OperationContext
.
TakeOwnership
();
_waitIndicator
.
Wait
(
EditorFeaturesResources
.
Formatting_document
,
EditorFeaturesResources
.
Formatting_document
,
...
...
@@ -85,19 +91,20 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
showProgress
:
true
,
c
=>
{
var
cancellationToken
=
context
.
OperationContext
.
UserCancellationToken
;
var
docOptions
=
document
.
GetOptionsAsync
(
c
.
CancellationToken
).
WaitAndGetResult
(
c
.
CancellationToken
)
;
using
(
Logger
.
LogBlock
(
FunctionId
.
FormatDocument
,
CodeCleanupLogMessage
.
Create
(
docOptions
),
c
.
CancellationToken
))
using
(
var
transaction
=
new
CaretPreservingEditTransaction
(
EditorFeaturesResources
.
Formatting
,
args
.
TextView
,
_undoHistoryRegistry
,
_editorOperationsFactoryService
))
{
var
codeCleanupService
=
document
.
GetLanguageService
<
ICodeCleanupService
>();
if
(
codeCleanupService
==
null
)
{
Format
(
args
.
TextView
,
document
,
selectionOpt
:
null
,
cancellationToken
);
Format
(
args
.
TextView
,
document
,
selectionOpt
:
null
,
c
.
C
ancellationToken
);
}
else
{
CodeCleanupOrFormat
(
args
,
document
,
c
.
ProgressTracker
,
cancellationToken
);
CodeCleanupOrFormat
(
args
,
document
,
c
.
ProgressTracker
,
c
.
C
ancellationToken
);
}
transaction
.
Complete
();
...
...
@@ -141,7 +148,7 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
}
private
async
Task
<
ImmutableArray
<
TextChange
>>
GetCodeCleanupAndFormatChangesAsync
(
Document
document
,
ICodeCleanupService
codeCleanupService
,
Document
document
,
ICodeCleanupService
codeCleanupService
,
IProgressTracker
progressTracker
,
CancellationToken
cancellationToken
)
{
var
newDoc
=
await
codeCleanupService
.
CleanupAsync
(
...
...
src/Features/CSharp/Portable/CodeCleanup/CSharpCodeCleanupService.cs
浏览文件 @
5011213d
...
...
@@ -11,6 +11,7 @@
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.OrganizeImports
;
using
Microsoft.CodeAnalysis.PooledObjects
;
...
...
@@ -133,10 +134,12 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
}
progressTracker
.
Description
=
FeaturesResources
.
Formatting_document
;
var
result
=
await
Formatter
.
FormatAsync
(
document
).
ConfigureAwait
(
false
);
progressTracker
.
ItemCompleted
();
return
result
;
using
(
Logger
.
LogBlock
(
FunctionId
.
CodeCleanup_Format
,
cancellationToken
))
{
var
result
=
await
Formatter
.
FormatAsync
(
document
).
ConfigureAwait
(
false
);
progressTracker
.
ItemCompleted
();
return
result
;
}
}
private
async
Task
<
Document
>
RemoveSortUsingsAsync
(
...
...
@@ -147,13 +150,19 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
var
removeUsingsService
=
document
.
GetLanguageService
<
IRemoveUnnecessaryImportsService
>();
if
(
removeUsingsService
!=
null
)
{
document
=
await
removeUsingsService
.
RemoveUnnecessaryImportsAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
using
(
Logger
.
LogBlock
(
FunctionId
.
CodeCleanup_RemoveUnusedImports
,
cancellationToken
))
{
document
=
await
removeUsingsService
.
RemoveUnnecessaryImportsAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
}
if
(
docOptions
.
GetOption
(
CodeCleanupOptions
.
SortImports
))
{
document
=
await
OrganizeImportsService
.
OrganizeImportsAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
using
(
Logger
.
LogBlock
(
FunctionId
.
CodeCleanup_SortImports
,
cancellationToken
))
{
document
=
await
OrganizeImportsService
.
OrganizeImportsAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
return
document
;
...
...
@@ -188,8 +197,11 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
{
foreach
(
var
diagnosticId
in
diagnosticIds
)
{
document
=
await
ApplyCodeFixesForSpecificDiagnosticId
(
document
,
diagnosticId
,
cancellationToken
).
ConfigureAwait
(
false
);
using
(
Logger
.
LogBlock
(
FunctionId
.
CodeCleanup_ApplyCodeFixesAsync
,
diagnosticId
,
cancellationToken
))
{
document
=
await
ApplyCodeFixesForSpecificDiagnosticId
(
document
,
diagnosticId
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
return
document
;
...
...
src/Features/Core/Portable/CodeCleanup/CodeCleanupLogMessage.cs
0 → 100644
浏览文件 @
5011213d
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Options
;
namespace
Microsoft.CodeAnalysis.CodeCleanup
{
internal
static
class
CodeCleanupLogMessage
{
public
static
KeyValueLogMessage
Create
(
DocumentOptionSet
docOptions
)
{
return
KeyValueLogMessage
.
Create
(
LogType
.
UserAction
,
m
=>
{
foreach
(
var
option
in
CodeCleanupOptionsProvider
.
SingletonOptions
)
{
m
[
option
.
Name
]
=
docOptions
.
GetOption
((
PerLanguageOption
<
bool
>)
option
,
LanguageNames
.
CSharp
);
}
});
}
}
}
src/Features/Core/Portable/CodeCleanup/CodeCleanupOptions.cs
浏览文件 @
5011213d
...
...
@@ -81,7 +81,7 @@ internal static class CodeCleanupOptions
[
ExportOptionProvider
,
Shared
]
internal
class
CodeCleanupOptionsProvider
:
IOptionProvider
{
public
ImmutableArray
<
IOption
>
Options
{
get
;
}
=
ImmutableArray
.
Create
<
IOption
>(
public
static
ImmutableArray
<
IOption
>
Singleton
Options
{
get
;
}
=
ImmutableArray
.
Create
<
IOption
>(
CodeCleanupOptions
.
CodeCleanupInfoBarShown
,
CodeCleanupOptions
.
AddAccessibilityModifiers
,
CodeCleanupOptions
.
AddRemoveBracesForSingleLineControlStatements
,
...
...
@@ -92,11 +92,15 @@ internal class CodeCleanupOptionsProvider : IOptionProvider
CodeCleanupOptions
.
ApplyObjectCollectionInitializationPreferences
,
CodeCleanupOptions
.
ApplyThisQualificationPreferences
,
CodeCleanupOptions
.
MakePrivateFieldReadonlyWhenPossible
,
CodeCleanupOptions
.
NeverShowCodeCleanupInfoBarAgain
,
CodeCleanupOptions
.
PerformAdditionalCodeCleanupDuringFormatting
,
CodeCleanupOptions
.
RemoveUnnecessaryCasts
,
CodeCleanupOptions
.
RemoveUnusedImports
,
CodeCleanupOptions
.
RemoveUnusedVariables
,
CodeCleanupOptions
.
SortAccessibilityModifiers
,
CodeCleanupOptions
.
SortImports
);
public
ImmutableArray
<
IOption
>
Options
{
get
;
}
=
SingletonOptions
;
}
}
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReference.Snapshot.cs
浏览文件 @
5011213d
...
...
@@ -34,16 +34,20 @@ internal sealed class Snapshot : PortableExecutableReference, ISupportTemporaryS
private
readonly
VisualStudioMetadataReferenceManager
_provider
;
private
readonly
Lazy
<
DateTime
>
_timestamp
;
private
Exception
_error
;
private
FileChangeTracker
_fileChangeTrackerOpt
;
internal
Snapshot
(
VisualStudioMetadataReferenceManager
provider
,
MetadataReferenceProperties
properties
,
string
fullPath
)
internal
Snapshot
(
VisualStudioMetadataReferenceManager
provider
,
MetadataReferenceProperties
properties
,
string
fullPath
,
FileChangeTracker
fileChangeTrackerOpt
)
:
base
(
properties
,
fullPath
)
{
Contract
.
Requires
(
Properties
.
Kind
==
MetadataImageKind
.
Assembly
);
_provider
=
provider
;
_fileChangeTrackerOpt
=
fileChangeTrackerOpt
;
_timestamp
=
new
Lazy
<
DateTime
>(()
=>
{
try
{
_fileChangeTrackerOpt
?.
EnsureSubscription
();
return
FileUtilities
.
GetFileTimeStamp
(
this
.
FilePath
);
}
catch
(
IOException
e
)
...
...
@@ -98,7 +102,7 @@ protected override DocumentationProvider CreateDocumentationProvider()
protected
override
PortableExecutableReference
WithPropertiesImpl
(
MetadataReferenceProperties
properties
)
{
return
new
Snapshot
(
_provider
,
properties
,
this
.
FilePath
);
return
new
Snapshot
(
_provider
,
properties
,
this
.
FilePath
,
_fileChangeTrackerOpt
);
}
private
string
GetDebuggerDisplay
()
...
...
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReference.cs
浏览文件 @
5011213d
...
...
@@ -55,8 +55,6 @@ public PortableExecutableReference CurrentSnapshot
UpdateSnapshot
();
}
// make sure we have file notification subscribed
_fileChangeTracker
.
EnsureSubscription
();
return
_currentSnapshot
;
}
}
...
...
@@ -74,7 +72,7 @@ public void Dispose()
public
void
UpdateSnapshot
()
{
_currentSnapshot
=
new
Snapshot
(
_provider
,
Properties
,
this
.
FilePath
);
_currentSnapshot
=
new
Snapshot
(
_provider
,
Properties
,
this
.
FilePath
,
_fileChangeTracker
);
}
private
string
GetDebuggerDisplay
()
...
...
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MetadataReferences/VisualStudioMetadataReferenceManager.cs
浏览文件 @
5011213d
...
...
@@ -83,7 +83,7 @@ internal IEnumerable<ITemporaryStreamStorage> GetStorages(string fullPath, DateT
public
PortableExecutableReference
CreateMetadataReferenceSnapshot
(
string
filePath
,
MetadataReferenceProperties
properties
)
{
return
new
VisualStudioMetadataReference
.
Snapshot
(
this
,
properties
,
filePath
);
return
new
VisualStudioMetadataReference
.
Snapshot
(
this
,
properties
,
filePath
,
fileChangeTrackerOpt
:
null
);
}
public
VisualStudioMetadataReference
CreateMetadataReference
(
string
filePath
,
MetadataReferenceProperties
properties
)
...
...
src/Workspaces/Core/Portable/Log/FunctionId.cs
浏览文件 @
5011213d
...
...
@@ -418,5 +418,15 @@ internal enum FunctionId
SymbolFinder_Solution_Pattern_FindSourceDeclarationsAsync
,
SymbolFinder_Project_Pattern_FindSourceDeclarationsAsync
,
Intellisense_Completion_Commit
,
CodeCleanupInfobar_BarDisplayed
,
CodeCleanupInfobar_ConfigureNow
,
CodeCleanupInfobar_NeverShowCodeCleanupInfoBarAgain
,
FormatDocument
,
CodeCleanup_ApplyCodeFixesAsync
,
CodeCleanup_RemoveUnusedImports
,
CodeCleanup_SortImports
,
CodeCleanup_Format
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录