Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42e528b

Browse files
the proper way, finally
1 parent6d1b4bd commit42e528b

File tree

1 file changed

+14
-113
lines changed

1 file changed

+14
-113
lines changed

‎src/fsharp/vs/ServiceAnalysis.fs‎

Lines changed: 14 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -70,118 +70,19 @@ module UnusedOpens =
7070
|_-> None// for now
7171
)
7272

73-
letgetAutoOpenAccessPath(ent:FSharpEntity)=
74-
// Some.Namespace+AutoOpenedModule+Entity
75-
76-
// HACK: I can't see a way to get the EnclosingEntity of an Entity
77-
// Some.Namespace + Some.Namespace.AutoOpenedModule are both valid
78-
ent.TryFullName|> Option.bind(fun _->
79-
if(not ent.IsNamespace)&& ent.QualifiedName.Contains"+"then
80-
Some ent.QualifiedName.[0..ent.QualifiedName.IndexOf"+"-1]
81-
else
82-
None)
83-
84-
letentityNamespace(entOpt:FSharpEntity option)=
85-
match entOptwith
86-
| Some ent->
87-
if ent.IsFSharpModulethen
88-
[yield Some ent.QualifiedName
89-
yield Some ent.LogicalName
90-
yield Some ent.AccessPath
91-
yield Some ent.FullName
92-
yield Some ent.DisplayName
93-
yield ent.TryGetFullDisplayName()
94-
if ent.HasFSharpModuleSuffixthen
95-
yield Some(ent.AccessPath+"."+ ent.DisplayName)]
96-
else
97-
[yield ent.Namespace
98-
yield Some ent.AccessPath
99-
yield getAutoOpenAccessPath ent
100-
for pathin ent.AllCompilationPathsdo
101-
yield Some path
102-
]
103-
| None->[]
104-
105-
typeNamespaceUse=
106-
{ Ident:string
107-
ExtraNamespaces:string[]}
108-
109-
letgetNamespaceInUse(fullIsland:string)(fullName:string):NamespaceUse option=
110-
// given a full island such as `Text.ISegment` and a full name of `MonoDevelop.Core.Text.ISegment`, return `MonoDevelop.Core`
111-
letlengthDiff= fullName.Length- fullIsland.Length-2
112-
if lengthDiff<=0|| lengthDiff> fullName.Length-1then None
113-
else
114-
letrequiredOpenNamespace= fullName.[0..lengthDiff]
115-
letrest= fullName.[lengthDiff+1..]
116-
letextraNamespaces=
117-
match rest.Split'.'with
118-
|[||]|[|_|]->[||]
119-
| rest-> rest.[..rest.Length-2]
120-
Some{ Ident= requiredOpenNamespace; ExtraNamespaces= extraNamespaces}
121-
122-
letgetPossibleNamespaces(getSourceLineStr:int->string)(symbolUse:FSharpSymbolUse):NamespaceUse[]=
123-
letlineStr= getSourceLineStr symbolUse.RangeAlternate.StartLine
124-
letpartialName= QuickParse.GetPartialLongNameEx(lineStr, symbolUse.RangeAlternate.EndColumn-1)
125-
if partialName.PartialIdent=""then[||]
126-
else
127-
letqualifyingIsland= partialName.QualifyingIdents|> String.concat"."
128-
letfullIsland= qualifyingIsland+ partialName.PartialIdent
129-
letisQualified fullName= fullName= fullIsland
130-
131-
(match symbolUsewith
132-
| SymbolUse.Entity(ent, cleanFullNames)whennot(cleanFullNames|> List.exists isQualified)->
133-
Some(cleanFullNames, Some ent)
134-
| SymbolUse.Field fwhennot(isQualified f.FullName)->
135-
Some([f.FullName], Some f.DeclaringEntity)
136-
| SymbolUse.MemberFunctionOrValue mfvwhennot(isQualified mfv.FullName)->
137-
Some([mfv.FullName], mfv.EnclosingEntity)
138-
| SymbolUse.Operator opwhennot(isQualified op.FullName)->
139-
Some([op.FullName], op.EnclosingEntity)
140-
| SymbolUse.ActivePattern apwhennot(isQualified ap.FullName)->
141-
Some([ap.FullName], ap.EnclosingEntity)
142-
| SymbolUse.ActivePatternCase apcwhennot(isQualified apc.FullName)->
143-
Some([apc.FullName], apc.Group.EnclosingEntity)
144-
| SymbolUse.UnionCase ucwhennot(isQualified uc.FullName)->
145-
Some([uc.FullName], Some uc.ReturnType.TypeDefinition)
146-
| SymbolUse.Parameter pwhennot(isQualified p.FullName)&& p.Type.HasTypeDefinition->
147-
Some([p.FullName], Some p.Type.TypeDefinition)
148-
|_-> None)
149-
|> Option.map(fun(fullNames,declaringEntity)->
150-
[|for namein fullNamesdo
151-
letpartNamespace= getNamespaceInUse fullIsland name
152-
yield partNamespace
153-
yield!
154-
entityNamespace declaringEntity
155-
|> List.map(Option.bind(getNamespaceInUse qualifyingIsland))
156-
|])
157-
|> Option.toArray
158-
|> Array.concat
159-
|> Array.choose id
160-
|> Array.distinct
161-
162-
typeSymbolUseWithFullNames=
163-
{ SymbolUse:FSharpSymbolUse
164-
FullNames:string[][]}
165-
166-
typeSymbolUse=
167-
{ SymbolUse:FSharpSymbolUse
168-
PossibleNamespaces:NamespaceUse[]}
169-
170-
letgetSymbolUses(getSourceLineStr:int->string)(symbolUses:FSharpSymbolUse[]):SymbolUse[]=
73+
letfilterSymbolUses(getSourceLineStr:int->string)(symbolUses:FSharpSymbolUse[]):FSharpSymbolUse[]=
17174
symbolUses
172-
|> Array.filter(fun(symbolUse: FSharpSymbolUse)->
173-
not symbolUse.IsFromDefinition//&&
174-
//match symbolUse.Symbol with
175-
//| :? FSharpEntity as e -> not e.IsNamespace
176-
//| _ -> true
177-
)
178-
|> Array.map(fun su->
179-
{ SymbolUse= su
180-
PossibleNamespaces= getPossibleNamespaces getSourceLineStr su})
75+
|> Array.filter(fun su->not su.IsFromDefinition)
76+
|> Array.filter(fun su->
77+
match su.Symbolwith
78+
|:? FSharpMemberOrFunctionOrValueas fvwhen fv.IsExtensionMember->true
79+
|_->
80+
letpartialName= QuickParse.GetPartialLongNameEx(getSourceLineStr su.RangeAlternate.StartLine, su.RangeAlternate.EndColumn-1)
81+
partialName.PartialIdent<>""&& partialName.QualifyingIdents=[])
18182

18283
letgetUnusedOpens(checkFileResults:FSharpCheckFileResults,getSourceLineStr:int->string):Async<rangelist>=
18384

184-
letfilter(openStatements:OpenStatement list)(symbolUses:SymbolUse[]):OpenStatement list=
85+
letfilter(openStatements:OpenStatement list)(symbolUses:FSharpSymbolUse[]):OpenStatement list=
18586
let recfilterInner acc(openStatements:OpenStatement list)(seenOpenStatements:OpenStatement list)=
18687

18788
letisUsed(openStatement:OpenStatement)=
@@ -190,13 +91,13 @@ module UnusedOpens =
19091
letusedSomewhere=
19192
symbolUses
19293
|> Array.exists(fun symbolUse->
193-
letinScope= rangeContainsRange openStatement.AppliedScope symbolUse.SymbolUse.RangeAlternate
94+
letinScope= rangeContainsRange openStatement.AppliedScope symbolUse.RangeAlternate
19495
ifnot inScopethenfalse
195-
elif openStatement.Idents|> Set.intersect symbolUse.PossibleNamespaces|> Set.isEmptythenfalse
96+
//elif openStatement.Idents |> Set.intersect symbolUse.PossibleNamespaces |> Set.isEmpty then false
19697
else
19798
letmoduleSymbols= openStatement.AllChildSymbols|> Seq.toList
19899
moduleSymbols
199-
|> List.exists(fun x-> x.IsEffectivelySameAs symbolUse.SymbolUse.Symbol))
100+
|> List.exists(fun x-> x.IsEffectivelySameAs symbolUse.Symbol))
200101

201102
ifnot usedSomewherethenfalse
202103
else
@@ -219,8 +120,8 @@ module UnusedOpens =
219120
filterInner[] openStatements[]
220121

221122
async{
222-
let!fsharpSymbolUses= checkFileResults.GetAllUsesOfAllSymbolsInFile()
223-
letsymbolUses=getSymbolUses getSourceLineStrfsharpSymbolUses
123+
let!symbolUses= checkFileResults.GetAllUsesOfAllSymbolsInFile()
124+
letsymbolUses=filterSymbolUses getSourceLineStrsymbolUses
224125
letopenStatements= getOpenStatements checkFileResults.OpenDeclarations
225126
return filter openStatements symbolUses|> List.map(fun os-> os.Range)
226127
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp