未验证 提交 984badb7 编写于 作者: S Steffen Forkmann 提交者: GitHub

Use dict instead if mutable Map (#9113)

* Use dict instead if mutable Map

* open namespace

* cleanup

* Further cleanup

* small cleanup
上级 43572a1e
......@@ -7,6 +7,7 @@
namespace FSharp.Compiler.SourceCodeServices
open System.Collections.Generic
open FSharp.Compiler.Range
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.SyntaxTreeOps
......@@ -78,9 +79,9 @@ module NavigationImpl =
else unionRanges r1 r2
let rangeOfDecls2 f decls =
match (decls |> List.map (f >> (fun (d:FSharpNavigationDeclarationItem) -> d.bodyRange))) with
| hd :: tl -> tl |> List.fold unionRangesChecked hd
| [] -> range.Zero
match decls |> List.map (f >> (fun (d:FSharpNavigationDeclarationItem) -> d.bodyRange)) with
| hd :: tl -> tl |> List.fold unionRangesChecked hd
| [] -> range.Zero
let rangeOfDecls = rangeOfDecls2 fst
......@@ -98,15 +99,18 @@ module NavigationImpl =
/// Get information for implementation file
let getNavigationFromImplFile (modules: SynModuleOrNamespace list) =
// Map for dealing with name conflicts
let mutable nameMap = Map.empty
let names = Dictionary()
let addItemName name =
let count = defaultArg (nameMap |> Map.tryFind name) 0
nameMap <- (Map.add name (count + 1) (nameMap))
(count + 1)
let count =
match names.TryGetValue name with
| true, count -> count + 1
| _ -> 1
names.[name] <- count
count
let uniqueName name idx =
let total = Map.find name nameMap
let total = names.[name]
sprintf "%s_%d_of_%d" name idx total
// Create declaration (for the left dropdown)
......@@ -195,8 +199,11 @@ module NavigationImpl =
| SynTypeDefnSimpleRepr.Record(_, fields, mb) ->
let fields =
[ for (Field(_, _, id, _, _, _, _, m)) in fields do
if (id.IsSome) then
yield createMember(id.Value, FieldDecl, FSharpGlyph.Field, m, FSharpEnclosingEntityKind.Record, false, access) ]
match id with
| Some ident ->
yield createMember(ident, FieldDecl, FSharpGlyph.Field, m, FSharpEnclosingEntityKind.Record, false, access)
| _ ->
() ]
let nested = fields@topMembers
[ createDeclLid(baseName, lid, TypeDecl, FSharpGlyph.Type, m, bodyRange mb nested, nested, FSharpEnclosingEntityKind.Record, false, access) ]
| SynTypeDefnSimpleRepr.TypeAbbrev(_, _, mb) ->
......@@ -244,7 +251,7 @@ module NavigationImpl =
| _ -> []))
(members |> Seq.map fst |> Seq.fold unionRangesChecked range.Zero),
(members |> List.map snd |> List.concat)
(members |> List.collect snd)
// Process declarations in a module that belong to the right drop-down (let bindings)
let processNestedDeclarations decls = decls |> List.collect (function
......@@ -364,8 +371,11 @@ module NavigationImpl =
| SynTypeDefnSimpleRepr.Record(_, fields, mb) ->
let fields =
[ for (Field(_, _, id, _, _, _, _, m)) in fields do
if (id.IsSome) then
yield createMember(id.Value, FieldDecl, FSharpGlyph.Field, m, FSharpEnclosingEntityKind.Record, false, access) ]
match id with
| Some ident ->
yield createMember(ident, FieldDecl, FSharpGlyph.Field, m, FSharpEnclosingEntityKind.Record, false, access)
| _ ->
() ]
let nested = fields@topMembers
[ createDeclLid(baseName, lid, TypeDecl, FSharpGlyph.Type, m, bodyRange mb nested, nested, FSharpEnclosingEntityKind.Record, false, access) ]
| SynTypeDefnSimpleRepr.TypeAbbrev(_, _, mb) ->
......@@ -393,14 +403,16 @@ module NavigationImpl =
// Process declarations nested in a module that should be displayed in the left dropdown
// (such as type declarations, nested modules etc.)
let rec processFSharpNavigationTopLevelSigDeclarations(baseName, decls) = decls |> List.collect (function
let rec processFSharpNavigationTopLevelSigDeclarations(baseName, decls) =
decls
|> List.collect (function
| SynModuleSigDecl.ModuleAbbrev(id, lid, m) ->
[ createDecl(baseName, id, ModuleDecl, FSharpGlyph.Module, m, rangeOfLid lid, [], FSharpEnclosingEntityKind.Module, false, None) ]
| SynModuleSigDecl.NestedModule(ComponentInfo(_, _, _, lid, _, _, access, _), _, decls, m) ->
// Find let bindings (for the right dropdown)
let nested = processNestedSigDeclarations(decls)
let newBaseName = (if (baseName = "") then "" else baseName+".") + (textOfLid lid)
let newBaseName = (if baseName = "" then "" else baseName + ".") + (textOfLid lid)
// Get nested modules and types (for the left dropdown)
let other = processFSharpNavigationTopLevelSigDeclarations(newBaseName, decls)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册