Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
0c2f90f8
F
fsharp
项目概览
dotNET Platform
/
fsharp
12 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0c2f90f8
编写于
11月 23, 2020
作者:
P
Phillip Carter
提交者:
GitHub
11月 23, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use MEF instead of GetService calls in diagnostic analyzers (#10531)
上级
d21e15e3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
42 deletion
+32
-42
vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs
...c/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs
+8
-14
vsintegration/src/FSharp.Editor/Diagnostics/SimplifyNameDiagnosticAnalyzer.fs
...harp.Editor/Diagnostics/SimplifyNameDiagnosticAnalyzer.fs
+8
-6
vsintegration/src/FSharp.Editor/Diagnostics/UnusedDeclarationsAnalyzer.fs
...c/FSharp.Editor/Diagnostics/UnusedDeclarationsAnalyzer.fs
+8
-10
vsintegration/src/FSharp.Editor/Diagnostics/UnusedOpensDiagnosticAnalyzer.fs
...Sharp.Editor/Diagnostics/UnusedOpensDiagnosticAnalyzer.fs
+8
-12
未找到文件。
vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs
浏览文件 @
0c2f90f8
...
...
@@ -10,29 +10,25 @@ open System.Threading
open
System
.
Threading
.
Tasks
open
Microsoft
.
CodeAnalysis
open
Microsoft
.
CodeAnalysis
.
Diagnostics
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
Host
.
Mef
open
Microsoft
.
CodeAnalysis
.
ExternalAccess
.
FSharp
.
Diagnostics
open
FSharp
.
Compiler
open
FSharp
.
Compiler
.
SourceCodeServices
[<
RequireQualifiedAccess
>]
type
internal
DiagnosticsType
=
|
Syntax
|
Semantic
[<
Export
(
typeof
<
IFSharpDocumentDiagnosticAnalyzer
>)>]
type
internal
FSharpDocumentDiagnosticAnalyzer
[<
ImportingConstructor
>]
()
=
type
internal
FSharpDocumentDiagnosticAnalyzer
[<
ImportingConstructor
>]
(
checkerProvider
:
FSharpCheckerProvider
,
projectInfoManager
:
FSharpProjectOptionsManager
)
=
static
let
userOpName
=
"DocumentDiagnosticAnalyzer"
let
getChecker
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
Checker
let
getProjectInfoManager
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
FSharpProjectOptionsManager
static
let
errorInfoEqualityComparer
=
{
new
IEqualityComparer
<
FSharpErrorInfo
>
with
...
...
@@ -110,27 +106,25 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
interface
IFSharpDocumentDiagnosticAnalyzer
with
member
this
.
AnalyzeSyntaxAsync
(
document
:
Document
,
cancellationToken
:
CancellationToken
):
Task
<
ImmutableArray
<
Diagnostic
>>
=
let
projectInfoManager
=
getProjectInfoManager
document
asyncMaybe
{
let
!
parsingOptions
,
projectOptions
=
projectInfoManager
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
sourceText
=
document
.
GetTextAsync
(
cancellationToken
)
let
!
textVersion
=
document
.
GetTextVersionAsync
(
cancellationToken
)
return
!
FSharpDocumentDiagnosticAnalyzer
.
GetDiagnostics
(
getChecker
document
,
document
.
FilePath
,
sourceText
,
textVersion
.
GetHashCode
()
,
parsingOptions
,
projectOptions
,
DiagnosticsType
.
Syntax
)
FSharpDocumentDiagnosticAnalyzer
.
GetDiagnostics
(
checkerProvider
.
Checker
,
document
.
FilePath
,
sourceText
,
textVersion
.
GetHashCode
()
,
parsingOptions
,
projectOptions
,
DiagnosticsType
.
Syntax
)
|>
liftAsync
}
|>
Async
.
map
(
Option
.
defaultValue
ImmutableArray
<
Diagnostic
>.
Empty
)
|>
RoslynHelpers
.
StartAsyncAsTask
cancellationToken
member
this
.
AnalyzeSemanticsAsync
(
document
:
Document
,
cancellationToken
:
CancellationToken
):
Task
<
ImmutableArray
<
Diagnostic
>>
=
let
projectInfoManager
=
getProjectInfoManager
document
asyncMaybe
{
let
!
parsingOptions
,
_,
projectOptions
=
projectInfoManager
.
TryGetOptionsForDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
sourceText
=
document
.
GetTextAsync
(
cancellationToken
)
let
!
textVersion
=
document
.
GetTextVersionAsync
(
cancellationToken
)
if
document
.
Project
.
Name
<>
FSharpConstants
.
FSharpMiscellaneousFilesName
||
isScriptFile
document
.
FilePath
then
return
!
FSharpDocumentDiagnosticAnalyzer
.
GetDiagnostics
(
getChecker
document
,
document
.
FilePath
,
sourceText
,
textVersion
.
GetHashCode
()
,
parsingOptions
,
projectOptions
,
DiagnosticsType
.
Semantic
)
FSharpDocumentDiagnosticAnalyzer
.
GetDiagnostics
(
checkerProvider
.
Checker
,
document
.
FilePath
,
sourceText
,
textVersion
.
GetHashCode
()
,
parsingOptions
,
projectOptions
,
DiagnosticsType
.
Semantic
)
|>
liftAsync
else
return
ImmutableArray
<
Diagnostic
>.
Empty
...
...
vsintegration/src/FSharp.Editor/Diagnostics/SimplifyNameDiagnosticAnalyzer.fs
浏览文件 @
0c2f90f8
...
...
@@ -17,12 +17,14 @@ open FSharp.Compiler.SourceCodeServices
type
private
PerDocumentSavedData
=
{
Hash
:
int
;
Diagnostics
:
ImmutableArray
<
Diagnostic
>
}
[<
Export
(
typeof
<
IFSharpSimplifyNameDiagnosticAnalyzer
>)>]
type
internal
SimplifyNameDiagnosticAnalyzer
[<
ImportingConstructor
>]
()
=
type
internal
SimplifyNameDiagnosticAnalyzer
[<
ImportingConstructor
>]
(
checkerProvider
:
FSharpCheckerProvider
,
projectInfoManager
:
FSharpProjectOptionsManager
)
=
static
let
userOpName
=
"SimplifyNameDiagnosticAnalyzer"
let
getProjectInfoManager
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
FSharpProjectOptionsManager
let
getChecker
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
Checker
static
let
cache
=
new
MemoryCache
(
"FSharp.Editor."
+
userOpName
)
// Make sure only one document is being analyzed at a time, to be nice
static
let
guard
=
new
SemaphoreSlim
(
1
)
...
...
@@ -36,7 +38,7 @@ type internal SimplifyNameDiagnosticAnalyzer [<ImportingConstructor>] () =
do
!
Option
.
guard
document
.
FSharpOptions
.
CodeFixes
.
SimplifyName
do
Trace
.
TraceInformation
(
"{0:n3} (start) SimplifyName"
,
DateTime
.
Now
.
TimeOfDay
.
TotalSeconds
)
do
!
Async
.
Sleep
DefaultTuning
.
SimplifyNameInitialDelay
|>
liftAsync
let
!
_
parsingOptions
,
projectOptions
=
getProjectInfoManager
(
document
)
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
_
parsingOptions
,
projectOptions
=
projectInfoManager
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
textVersion
=
document
.
GetTextVersionAsync
(
cancellationToken
)
let
textVersionHash
=
textVersion
.
GetHashCode
()
let
!
_
=
guard
.
WaitAsync
(
cancellationToken
)
|>
Async
.
AwaitTask
|>
liftAsync
...
...
@@ -46,7 +48,7 @@ type internal SimplifyNameDiagnosticAnalyzer [<ImportingConstructor>] () =
|
:?
PerDocumentSavedData
as
data
when
data
.
Hash
=
textVersionHash
->
return
data
.
Diagnostics
|
_
->
let
!
sourceText
=
document
.
GetTextAsync
()
let
checker
=
getChecker
document
let
checker
=
checkerProvider
.
Checker
let
!
_,
_,
checkResults
=
checker
.
ParseAndCheckDocument
(
document
,
projectOptions
,
sourceText
=
sourceText
,
userOpName
=
userOpName
)
let
!
result
=
SimplifyNames
.
getSimplifiableNames
(
checkResults
,
fun
lineNumber
->
sourceText
.
Lines
.[
Line
.
toZ
lineNumber
].
ToString
()
)
|>
liftAsync
let
mutable
diag
=
ResizeArray
()
...
...
vsintegration/src/FSharp.Editor/Diagnostics/UnusedDeclarationsAnalyzer.fs
浏览文件 @
0c2f90f8
...
...
@@ -4,24 +4,22 @@ namespace rec Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Collections
.
Generic
open
System
.
Collections
.
Immutable
open
System
.
Diagnostics
open
System
.
Threading
.
Tasks
open
Microsoft
.
CodeAnalysis
open
Microsoft
.
CodeAnalysis
.
Diagnostics
open
Microsoft
.
CodeAnalysis
.
Host
.
Mef
open
FSharp
.
Compiler
.
SourceCodeServices
open
Microsoft
.
CodeAnalysis
.
ExternalAccess
.
FSharp
.
Diagnostics
[<
Export
(
typeof
<
IFSharpUnusedDeclarationsDiagnosticAnalyzer
>)>]
type
internal
UnusedDeclarationsAnalyzer
[<
ImportingConstructor
>]
()
=
type
internal
UnusedDeclarationsAnalyzer
[<
ImportingConstructor
>]
(
checkerProvider
:
FSharpCheckerProvider
,
projectInfoManager
:
FSharpProjectOptionsManager
)
=
static
let
userOpName
=
"UnusedDeclarationsAnalyzer"
let
getProjectInfoManager
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
FSharpProjectOptionsManager
let
getChecker
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
Checker
interface
IFSharpUnusedDeclarationsDiagnosticAnalyzer
with
...
...
@@ -31,10 +29,10 @@ type internal UnusedDeclarationsAnalyzer [<ImportingConstructor>] () =
do
Trace
.
TraceInformation
(
"{0:n3} (start) UnusedDeclarationsAnalyzer"
,
DateTime
.
Now
.
TimeOfDay
.
TotalSeconds
)
do
!
Async
.
Sleep
DefaultTuning
.
UnusedDeclarationsAnalyzerInitialDelay
|>
liftAsync
// be less intrusive, give other work priority most of the time
match
!
getProjectInfoManager
(
document
)
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
with
match
!
projectInfoManager
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
with
|
(_
parsingOptions
,
projectOptions
)
->
let
!
sourceText
=
document
.
GetTextAsync
()
let
checker
=
getChecker
document
let
checker
=
checkerProvider
.
Checker
let
!
_,
_,
checkResults
=
checker
.
ParseAndCheckDocument
(
document
,
projectOptions
,
sourceText
=
sourceText
,
userOpName
=
userOpName
)
let
!
unusedRanges
=
UnusedDeclarations
.
getUnusedDeclarations
(
checkResults
,
(
isScriptFile
document
.
FilePath
))
|>
liftAsync
return
...
...
vsintegration/src/FSharp.Editor/Diagnostics/UnusedOpensDiagnosticAnalyzer.fs
浏览文件 @
0c2f90f8
...
...
@@ -16,10 +16,12 @@ open FSharp.Compiler.SourceCodeServices
open
Microsoft
.
CodeAnalysis
.
ExternalAccess
.
FSharp
.
Diagnostics
[<
Export
(
typeof
<
IFSharpUnusedOpensDiagnosticAnalyzer
>)>]
type
internal
UnusedOpensDiagnosticAnalyzer
[<
ImportingConstructor
>]
()
=
let
getProjectInfoManager
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
FSharpProjectOptionsManager
let
getChecker
(
document
:
Document
)
=
document
.
Project
.
Solution
.
Workspace
.
Services
.
GetService
<
FSharpCheckerWorkspaceService
>().
Checker
type
internal
UnusedOpensDiagnosticAnalyzer
[<
ImportingConstructor
>]
(
checkerProvider
:
FSharpCheckerProvider
,
projectInfoManager
:
FSharpProjectOptionsManager
)
=
static
let
userOpName
=
"UnusedOpensAnalyzer"
...
...
@@ -28,13 +30,7 @@ type internal UnusedOpensDiagnosticAnalyzer [<ImportingConstructor>] () =
do
!
Option
.
guard
document
.
FSharpOptions
.
CodeFixes
.
UnusedOpens
let
!
sourceText
=
document
.
GetTextAsync
()
let
!
_,
_,
checkResults
=
checker
.
ParseAndCheckDocument
(
document
,
options
,
sourceText
=
sourceText
,
userOpName
=
userOpName
)
#
if
DEBUG
let
sw
=
Stopwatch
.
StartNew
()
#
endif
let
!
unusedOpens
=
UnusedOpens
.
getUnusedOpens
(
checkResults
,
fun
lineNumber
->
sourceText
.
Lines
.[
Line
.
toZ
lineNumber
].
ToString
()
)
|>
liftAsync
#
if
DEBUG
Logging
.
Logging
.
logInfof
"*** Got %d unused opens in %O"
unusedOpens
.
Length
sw
.
Elapsed
#
endif
return
unusedOpens
}
...
...
@@ -44,9 +40,9 @@ type internal UnusedOpensDiagnosticAnalyzer [<ImportingConstructor>] () =
asyncMaybe
{
do
Trace
.
TraceInformation
(
"{0:n3} (start) UnusedOpensAnalyzer"
,
DateTime
.
Now
.
TimeOfDay
.
TotalSeconds
)
do
!
Async
.
Sleep
DefaultTuning
.
UnusedOpensAnalyzerInitialDelay
|>
liftAsync
// be less intrusive, give other work priority most of the time
let
!
_
parsingOptions
,
projectOptions
=
getProjectInfoManager
(
document
)
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
_
parsingOptions
,
projectOptions
=
projectInfoManager
.
TryGetOptionsForEditingDocumentOrProject
(
document
,
cancellationToken
,
userOpName
)
let
!
sourceText
=
document
.
GetTextAsync
()
let
checker
=
getChecker
document
let
checker
=
checkerProvider
.
Checker
let
!
unusedOpens
=
UnusedOpensDiagnosticAnalyzer
.
GetUnusedOpenRanges
(
document
,
projectOptions
,
checker
)
return
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录