Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Seq Optimizations #1308

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/FsAutoComplete.Core/CodeGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ module CodeGenerationUtils =
let duplicatedMembers =
missingMembers
|> Seq.countBy (fun (m, insts) -> m.DisplayName, insts |> Seq.length)
|> Seq.filter (snd >> (<) 1)
|> Seq.map (fst >> fst)
|> Seq.choose (fun (m, insts) -> if insts > 1 then fst m |> Some else None)
|> Set.ofSeq

let getReturnType v = snd (getArgTypes ctx v)
Expand Down
12 changes: 7 additions & 5 deletions src/FsAutoComplete.Core/DocumentationFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,18 @@ module DocumentationFormatter =

let types =
fse.NestedEntities
|> Seq.filter (fun ne ->
|> Seq.choose (fun ne ->
let isCompilerGenerated =
ne.Attributes
|> Seq.tryFind (fun attribute -> attribute.AttributeType.CompiledName = "CompilerGeneratedAttribute")
|> Option.isSome

not ne.IsNamespace && not isCompilerGenerated)
|> Seq.map (fun ne ->
(typeName ne)
++ fst (formatShowDocumentationLink ne.DisplayName ne.XmlDocSig ne.Assembly.SimpleName))
if not ne.IsNamespace && not isCompilerGenerated then
(typeName ne)
++ fst (formatShowDocumentationLink ne.DisplayName ne.XmlDocSig ne.Assembly.SimpleName)
|> Some
else
None)
|> Seq.toArray

{ Constructors = constructors
Expand Down
6 changes: 2 additions & 4 deletions src/FsAutoComplete.Core/InlayHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -954,14 +954,12 @@ let provideHints

let parms =
appliedArgRanges
|> Array.ofList
|> Array.mapi (fun i v ->
|> List.indexed
|> List.choose (fun (i, v) ->
if i < definitionArgs.Length then
Some(definitionArgs.[i], v)
else
None)
|> Array.filter Option.isSome
|> Array.map Option.get

for (definitionArg, appliedArgRange) in parms do
let! appliedArgText = text[appliedArgRange]
Expand Down
12 changes: 7 additions & 5 deletions src/FsAutoComplete.Core/SignatureFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,13 @@ module SignatureFormatter =
let enumTip () =
$" ={nl} |"
++ (fse.FSharpFields
|> Seq.filter (fun f -> not f.IsCompilerGenerated)
|> Seq.map (fun field ->
match field.LiteralValue with
| Some lv -> field.Name + " = " + (string lv)
| None -> field.Name)
|> Seq.choose (fun field ->
if field.IsCompilerGenerated then
None
else
match field.LiteralValue with
| Some lv -> field.Name + " = " + (string lv) |> Some
| None -> Some field.Name)
|> String.concat $"{nl} | ")

let unionTip () =
Expand Down
21 changes: 11 additions & 10 deletions src/FsAutoComplete/CodeFixes/AddMissingXmlDocumentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix =
| parameters ->
parameters
|> List.concat
|> List.filter (fun (parameter, _) ->
docLines
|> List.exists (fun c -> c.Contains($"<param name=\"%s{parameter}\">"))
|> not)
|> List.mapi (fun _index parameter -> parameterSection parameter)
|> List.choose (fun (p, o) ->
let hasParam =
docLines |> List.exists (fun c -> c.Contains($"<param name=\"%s{p}\">"))

if hasParam then None else parameterSection (p, o) |> Some)

match indexForParams with
| None -> List.append docLines missingParams
Expand All @@ -117,11 +117,12 @@ let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix =
| [] -> []
| generics ->
generics
|> List.filter (fun generic ->
docLines
|> List.exists (fun c -> c.Contains($"<typeparam name=\"'%s{generic}\">"))
|> not)
|> List.mapi (fun _index generic -> genericArg generic)
|> List.choose (fun generic ->
let hasTypeParams =
docLines
|> List.exists (fun c -> c.Contains($"<typeparam name=\"'%s{generic}\">"))

if hasTypeParams then None else genericArg generic |> Some)

match indexForTypeParams with
| None -> List.append withAdded missingTypeParams
Expand Down
7 changes: 5 additions & 2 deletions src/FsAutoComplete/CodeFixes/AdjustConstant.fs
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,11 @@ module CommonFixes =

let ty =
assemblies
|> Seq.filter (isSystemAssembly)
|> Seq.tryPick (fun system -> system.Contents.FindEntityByPath [ "System"; name ])
|> Seq.tryPick (fun system ->
if isSystemAssembly system then
system.Contents.FindEntityByPath [ "System"; name ]
else
None)
|> Option.map (fun ent -> ent.AsType())

// Note: `ty` should never be `None`: we're only looking up standard dotnet types -- which should always be available.
Expand Down
7 changes: 5 additions & 2 deletions src/FsAutoComplete/LspServers/AdaptiveServerState.fs
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,11 @@ type AdaptiveState
| MSBuildAllProjects v ->
yield!
v
|> Array.filter (fun x -> x.EndsWith(".props", StringComparison.Ordinal) && isWithinObjFolder x)
|> Array.map (Utils.normalizePath >> projectFileChanges)
|> Array.choose (fun x ->
if x.EndsWith(".props", StringComparison.Ordinal) && isWithinObjFolder x then
Utils.normalizePath x |> projectFileChanges |> Some
else
None)
| _ -> () ]

HashMap.ofList
Expand Down
19 changes: 12 additions & 7 deletions src/FsAutoComplete/LspServers/ProjectWorkspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ module Snapshots =
)

loadedProjectsA
|> AMap.filter (fun k _ ->
project.ReferencedProjects
|> List.exists (fun x -> normalizePath x.ProjectFileName = k))
|> AMap.map (fun _ proj ->
if proj.ProjectFileName.EndsWith ".fsproj" then
|> AMap.choose (fun localPath proj ->
let loadedProjectNotReferenced =
project.ReferencedProjects
|> List.exists (fun x -> normalizePath x.ProjectFileName = localPath)
|> not

if loadedProjectNotReferenced then
None
else if proj.ProjectFileName.EndsWith ".fsproj" then

let resolvedTargetPath =
aval {
Expand All @@ -205,10 +209,11 @@ module Snapshots =
sourceTextFactory
(createReferences cachedSnapshots inMemorySourceFiles sourceTextFactory loadedProjectsA)
|> createReferencedProjectsFSharpReference resolvedTargetPath
|> Some

else
// TODO: Find if this needs to be adaptive or if `getStamp` in a PEReference will be enough to break thru the caching in FCS
loadFromDotnetDll proj |> AVal.constant)
loadFromDotnetDll proj |> AVal.constant |> Some)
|> AMap.toASetValues

/// <summary>Creates a snapshot from a Project, using the already created snapshots it possible.</summary>
Expand Down Expand Up @@ -246,8 +251,8 @@ module Snapshots =
let sourceFiles = // alist because order matters for the F# Compiler
project.SourceFiles
|> AList.ofList
|> AList.map Utils.normalizePath
|> AList.map (fun sourcePath ->
let sourcePath = Utils.normalizePath sourcePath

aval {
// prefer in-memory files over on-disk files
Expand Down
Loading