Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
21bfe0bc
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
21bfe0bc
编写于
12月 07, 2016
作者:
J
Jonathon Marolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
responding to Jason's PR feedback
上级
26b5fd67
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
166 addition
and
68 deletion
+166
-68
src/EditorFeatures/Next/EditorFeatures.Next.csproj
src/EditorFeatures/Next/EditorFeatures.Next.csproj
+2
-0
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.DocumentOptions.cs
...ns/EditorConfigDocumentOptionsProvider.DocumentOptions.cs
+49
-0
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.EmptyCodingConventionContext.cs
...igDocumentOptionsProvider.EmptyCodingConventionContext.cs
+93
-0
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.cs
...tures/Next/Options/EditorConfigDocumentOptionsProvider.cs
+8
-68
src/Workspaces/Core/Portable/Shared/Utilities/IOUtilities.cs
src/Workspaces/Core/Portable/Shared/Utilities/IOUtilities.cs
+14
-0
未找到文件。
src/EditorFeatures/Next/EditorFeatures.Next.csproj
浏览文件 @
21bfe0bc
...
...
@@ -63,6 +63,8 @@
<Compile
Include=
"IntelliSense\Completion\Presentation\Roslyn15CompletionSet.cs"
/>
<Compile
Include=
"IntelliSense\Completion\Presentation\VisualStudio15CompletionSetFactory.cs"
/>
<Compile
Include=
"IntelliSense\Completion\Presentation\VisualStudio15CompletionSet.cs"
/>
<Compile
Include=
"Options\EditorConfigDocumentOptionsProvider.DocumentOptions.cs"
/>
<Compile
Include=
"Options\EditorConfigDocumentOptionsProvider.EmptyCodingConventionContext.cs"
/>
<Compile
Include=
"Structure\BlockContextProvider.cs"
/>
<Compile
Include=
"Structure\VisualStudio15StructureTaggerProvider.cs"
/>
<Compile
Include=
"Options\EditorConfigDocumentOptionsProviderFactory.cs"
/>
...
...
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.DocumentOptions.cs
0 → 100644
浏览文件 @
21bfe0bc
using
System
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.VisualStudio.CodingConventions
;
namespace
Microsoft.CodeAnalysis.Editor.Options
{
internal
sealed
partial
class
EditorConfigDocumentOptionsProvider
:
IDocumentOptionsProvider
{
private
class
DocumentOptions
:
IDocumentOptions
{
private
ICodingConventionsSnapshot
_codingConventionSnapshot
;
public
DocumentOptions
(
ICodingConventionsSnapshot
codingConventionSnapshot
)
{
_codingConventionSnapshot
=
codingConventionSnapshot
;
}
public
bool
TryGetDocumentOption
(
Document
document
,
OptionKey
option
,
out
object
value
)
{
var
editorConfigPersistence
=
option
.
Option
.
StorageLocations
.
OfType
<
EditorConfigStorageLocation
>().
SingleOrDefault
();
if
(
editorConfigPersistence
==
null
)
{
value
=
null
;
return
false
;
}
if
(
_codingConventionSnapshot
.
TryGetConventionValue
(
editorConfigPersistence
.
KeyName
,
out
value
))
{
try
{
value
=
editorConfigPersistence
.
ParseValue
(
value
.
ToString
(),
option
.
Option
.
Type
);
return
true
;
}
catch
(
Exception
)
{
// TODO: report this somewhere?
return
false
;
}
}
else
{
return
false
;
}
}
}
}
}
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.EmptyCodingConventionContext.cs
0 → 100644
浏览文件 @
21bfe0bc
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.VisualStudio.CodingConventions
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.Options
{
internal
sealed
partial
class
EditorConfigDocumentOptionsProvider
{
private
class
EmptyCodingConventionContext
:
ICodingConventionContext
{
public
static
ICodingConventionContext
Instance
{
get
;
}
=
new
EmptyCodingConventionContext
();
public
ICodingConventionsSnapshot
CurrentConventions
{
get
;
}
=
EmptyCodingConventionsSnapshot
.
Instance
;
#pragma warning disable CS0067
public
event
CodingConventionsChangedAsyncEventHandler
CodingConventionsChangedAsync
;
#pragma warning restore CS0067
public
void
Dispose
()
{
}
public
Task
WriteConventionValueAsync
(
string
conventionName
,
string
conventionValue
,
CancellationToken
cancellationToken
)
=>
Task
.
CompletedTask
;
private
class
EmptyCodingConventionsSnapshot
:
ICodingConventionsSnapshot
{
public
static
EmptyCodingConventionsSnapshot
Instance
{
get
;
}
=
new
EmptyCodingConventionsSnapshot
();
public
IReadOnlyDictionary
<
string
,
object
>
AllRawConventions
{
get
;
}
=
(
IReadOnlyDictionary
<
string
,
object
>)
SpecializedCollections
.
EmptyDictionary
<
string
,
object
>();
public
IUniversalCodingConventions
UniversalConventions
{
get
;
}
=
EmptyUniversalCodingConventions
.
Instance
;
public
int
Version
=>
0
;
public
bool
TryGetConventionValue
<
T
>(
string
conventionName
,
out
T
conventionValue
)
{
conventionValue
=
default
(
T
);
return
false
;
}
private
class
EmptyUniversalCodingConventions
:
IUniversalCodingConventions
{
public
static
EmptyUniversalCodingConventions
Instance
{
get
;
}
=
new
EmptyUniversalCodingConventions
();
public
bool
TryGetAllowTrailingWhitespace
(
out
bool
allowTrailingWhitespace
)
{
allowTrailingWhitespace
=
false
;
return
false
;
}
public
bool
TryGetEncoding
(
out
Encoding
encoding
)
{
encoding
=
null
;
return
false
;
}
public
bool
TryGetIndentSize
(
out
int
indentSize
)
{
indentSize
=
default
(
int
);
return
false
;
}
public
bool
TryGetIndentStyle
(
out
IndentStyle
indentStyle
)
{
indentStyle
=
default
(
IndentStyle
);
return
false
;
}
public
bool
TryGetLineEnding
(
out
string
lineEnding
)
{
lineEnding
=
null
;
return
false
;
}
public
bool
TryGetRequireFinalNewline
(
out
bool
requireFinalNewline
)
{
requireFinalNewline
=
false
;
return
false
;
}
public
bool
TryGetTabWidth
(
out
int
tabWidth
)
{
tabWidth
=
default
(
int
);
return
false
;
}
}
}
}
}
}
src/EditorFeatures/Next/Options/EditorConfigDocumentOptionsProvider.cs
浏览文件 @
21bfe0bc
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.VisualStudio.CodingConventions
;
using
System
;
namespace
Microsoft.CodeAnalysis.Editor.Options
{
// NOTE: this type depends on Dev15 assemblies, which is why the type is in EditorFeatures.Next. But, that library
// is rehostable and once we move .editorconfig support fully through the system, it should be moved to Workspaces
// or perhaps even lower.
internal
sealed
class
EditorConfigDocumentOptionsProvider
:
IDocumentOptionsProvider
internal
sealed
partial
class
EditorConfigDocumentOptionsProvider
:
IDocumentOptionsProvider
{
private
readonly
object
_gate
=
new
object
();
...
...
@@ -36,9 +35,7 @@ private void Workspace_DocumentClosed(object sender, DocumentEventArgs e)
{
lock
(
_gate
)
{
Task
<
ICodingConventionContext
>
contextTask
;
if
(
_openDocumentContexts
.
TryGetValue
(
e
.
Document
.
Id
,
out
contextTask
))
if
(
_openDocumentContexts
.
TryGetValue
(
e
.
Document
.
Id
,
out
var
contextTask
))
{
_openDocumentContexts
.
Remove
(
e
.
Document
.
Id
);
...
...
@@ -81,12 +78,6 @@ public async Task<IDocumentOptions> GetOptionsForDocumentAsync(Document document
TaskScheduler
.
Default
);
var
context
=
await
cancellableContextTask
.
ConfigureAwait
(
false
);
if
(
context
==
null
)
{
// exception thrown while trying to read the editorconfig file
return
null
;
}
return
new
DocumentOptions
(
context
.
CurrentConventions
);
}
else
...
...
@@ -111,70 +102,19 @@ public async Task<IDocumentOptions> GetOptionsForDocumentAsync(Document document
// that we maintain snapshot rules for the document options. We'll also run it on the thread pool
// as in some builds the ICodingConventionsManager captures the thread pool.
var
conventionsAsync
=
Task
.
Run
(()
=>
GetConventionContextAsync
(
path
,
cancellationToken
));
var
context
=
await
conventionsAsync
.
ConfigureAwait
(
false
);
if
(
context
==
null
)
{
// exception thrown while trying to read the editorconfig file
return
null
;
}
using
(
context
)
using
(
var
context
=
await
conventionsAsync
.
ConfigureAwait
(
false
)
)
{
return
new
DocumentOptions
(
context
.
CurrentConventions
);
}
}
}
private
async
Task
<
ICodingConventionContext
>
GetConventionContextAsync
(
string
path
,
CancellationToken
cancellationToken
)
{
try
{
return
await
_codingConventionsManager
.
GetConventionContextAsync
(
path
,
cancellationToken
).
ConfigureAwait
(
false
);
}
catch
(
Exception
)
{
// exception may be thrown while attempting to read editor config file
return
null
;
}
}
private
class
DocumentOptions
:
IDocumentOptions
{
private
ICodingConventionsSnapshot
_codingConventionSnapshot
;
public
DocumentOptions
(
ICodingConventionsSnapshot
codingConventionSnapshot
)
{
_codingConventionSnapshot
=
codingConventionSnapshot
;
}
public
bool
TryGetDocumentOption
(
Document
document
,
OptionKey
option
,
out
object
value
)
{
var
editorConfigPersistence
=
option
.
Option
.
StorageLocations
.
OfType
<
EditorConfigStorageLocation
>().
SingleOrDefault
();
if
(
editorConfigPersistence
==
null
)
{
value
=
null
;
return
false
;
}
if
(
_codingConventionSnapshot
.
TryGetConventionValue
(
editorConfigPersistence
.
KeyName
,
out
value
))
private
Task
<
ICodingConventionContext
>
GetConventionContextAsync
(
string
path
,
CancellationToken
cancellationToken
)
{
try
{
value
=
editorConfigPersistence
.
ParseValue
(
value
.
ToString
(),
option
.
Option
.
Type
);
return
true
;
}
catch
(
Exception
)
{
// TODO: report this somewhere?
return
false
;
}
}
else
{
return
false
;
}
}
return
IOUtilities
.
PerformIOAsync
(
()
=>
_codingConventionsManager
.
GetConventionContextAsync
(
path
,
cancellationToken
),
defaultValue
:
EmptyCodingConventionContext
.
Instance
);
}
}
}
src/Workspaces/Core/Portable/Shared/Utilities/IOUtilities.cs
浏览文件 @
21bfe0bc
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.IO
;
using
System.Security
;
using
System.Threading.Tasks
;
namespace
Microsoft.CodeAnalysis.Shared.Utilities
{
...
...
@@ -30,6 +31,19 @@ public static T PerformIO<T>(Func<T> function, T defaultValue = default(T))
return
defaultValue
;
}
public
static
async
Task
<
T
>
PerformIOAsync
<
T
>(
Func
<
Task
<
T
>>
function
,
T
defaultValue
=
default
(
T
))
{
try
{
return
await
function
().
ConfigureAwait
(
false
);
}
catch
(
Exception
e
)
when
(
IsNormalIOException
(
e
))
{
}
return
defaultValue
;
}
public
static
bool
IsNormalIOException
(
Exception
e
)
{
return
e
is
IOException
||
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录