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

Format code in FSharp.Compiler.Server.Shared and FSharp.DependencyManager.Nuget #13161

Merged
merged 6 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ src/fsc/**/*.fs
src/fscAnyCpu/**/*.fs
src/FSharp.Build/**/*.fs
src/FSharp.Compiler.Interactive.Settings/**/*.fs
src/FSharp.Compiler.Server.Shared/**/*.fs
src/FSharp.DependencyManager.Nuget/**/*.fs
src/fsi/**/*.fs
src/fsiAnyCpu/**/*.fs
src/Microsoft.FSharp.Compiler/**/*.fs
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Service/ServiceLexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System
open System.Threading
open FSharp.Compiler
open FSharp.Compiler.Text

#nowarn "57"

/// Represents encoded information for the end-of-line continuation of lexing
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Compiler.Server.Shared/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Microsoft.FSharp
open System.Reflection
open System.Runtime.InteropServices

[<assembly:ComVisible(false)>]
do()
[<assembly: ComVisible(false)>]
do ()
32 changes: 17 additions & 15 deletions src/FSharp.Compiler.Server.Shared/FSharpInteractiveServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace FSharp.Compiler.Server.Shared
// e.g.
// - interrupt
// - intellisense completion
//
//
// This is done via remoting.
// Here we define the service class.
// This dll is required for both client (fsi-vs plugin) and server (spawned fsi).

//[<assembly: System.Security.SecurityTransparent>]
[<assembly: System.Runtime.InteropServices.ComVisible(false)>]
[<assembly: System.CLSCompliant(true)>]
do()
[<assembly: System.CLSCompliant(true)>]
do ()

open System
open System.Diagnostics
Expand All @@ -25,22 +25,24 @@ open System.Runtime.Remoting.Lifetime

[<AbstractClass>]
type internal FSharpInteractiveServer() =
inherit System.MarshalByRefObject()
abstract Interrupt : unit -> unit
inherit System.MarshalByRefObject()
abstract Interrupt: unit -> unit
default x.Interrupt() = ()

[<CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")>]
static member StartServer(channelName:string,server:FSharpInteractiveServer) =
let chan = new Ipc.IpcChannel(channelName)
LifetimeServices.LeaseTime <- TimeSpan(7,0,0,0); // days,hours,mins,secs
LifetimeServices.LeaseManagerPollTime <- TimeSpan(7,0,0,0);
LifetimeServices.RenewOnCallTime <- TimeSpan(7,0,0,0);
LifetimeServices.SponsorshipTimeout <- TimeSpan(7,0,0,0);
ChannelServices.RegisterChannel(chan,false);
let objRef = RemotingServices.Marshal(server,"FSIServer")
static member StartServer(channelName: string, server: FSharpInteractiveServer) =
let chan = new Ipc.IpcChannel(channelName)
LifetimeServices.LeaseTime <- TimeSpan(7, 0, 0, 0) // days,hours,mins,secs
LifetimeServices.LeaseManagerPollTime <- TimeSpan(7, 0, 0, 0)
LifetimeServices.RenewOnCallTime <- TimeSpan(7, 0, 0, 0)
LifetimeServices.SponsorshipTimeout <- TimeSpan(7, 0, 0, 0)
ChannelServices.RegisterChannel(chan, false)
let objRef = RemotingServices.Marshal(server, "FSIServer")
()

static member StartClient(channelName) =
let T = Activator.GetObject(typeof<FSharpInteractiveServer>,"ipc://" + channelName + "/FSIServer")
let x = T :?> FSharpInteractiveServer
let T =
Activator.GetObject(typeof<FSharpInteractiveServer>, "ipc://" + channelName + "/FSIServer")

let x = T :?> FSharpInteractiveServer
x
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,119 @@ open System.IO

// Package reference information
type PackageReference =
{ Include:string
Version:string
RestoreSources:string
Script:string
{
Include: string
Version: string
RestoreSources: string
Script: string
}

// Resolved assembly information
type internal Resolution =
{ NugetPackageId : string
NugetPackageVersion : string
PackageRoot : string
FullPath : string
AssetType: string
IsNotImplementationReference: string
InitializeSourcePath : string
NativePath : string
{
NugetPackageId: string
NugetPackageVersion: string
PackageRoot: string
FullPath: string
AssetType: string
IsNotImplementationReference: string
InitializeSourcePath: string
NativePath: string
}


module internal ProjectFile =

let fsxExt = ".fsx"

let csxExt = ".csx"

let findLoadsFromResolutions (resolutions:Resolution[]) =
let findLoadsFromResolutions (resolutions: Resolution[]) =
resolutions
|> Array.filter(fun r ->
not(String.IsNullOrEmpty(r.NugetPackageId) ||
String.IsNullOrEmpty(r.InitializeSourcePath)) &&
File.Exists(r.InitializeSourcePath))
|> Array.map(fun r -> r.InitializeSourcePath)
|> Array.filter (fun r ->
not (
String.IsNullOrEmpty(r.NugetPackageId)
|| String.IsNullOrEmpty(r.InitializeSourcePath)
)
&& File.Exists(r.InitializeSourcePath))
|> Array.map (fun r -> r.InitializeSourcePath)
|> Array.distinct

let findReferencesFromResolutions (resolutions:Resolution array) =
let findReferencesFromResolutions (resolutions: Resolution array) =

let equals (s1:string) (s2:string) =
let equals (s1: string) (s2: string) =
String.Compare(s1, s2, StringComparison.InvariantCultureIgnoreCase) = 0

resolutions
|> Array.filter(fun r -> not(String.IsNullOrEmpty(r.NugetPackageId) ||
String.IsNullOrEmpty(r.FullPath)) &&
not (equals r.IsNotImplementationReference "true") &&
File.Exists(r.FullPath) &&
equals r.AssetType "runtime")
|> Array.map(fun r -> r.FullPath)
|> Array.filter (fun r ->
not (String.IsNullOrEmpty(r.NugetPackageId) || String.IsNullOrEmpty(r.FullPath))
&& not (equals r.IsNotImplementationReference "true")
&& File.Exists(r.FullPath)
&& equals r.AssetType "runtime")
|> Array.map (fun r -> r.FullPath)
|> Array.distinct


let findIncludesFromResolutions (resolutions:Resolution[]) =
let findIncludesFromResolutions (resolutions: Resolution[]) =
let managedRoots =
resolutions
|> Array.filter(fun r ->
not(String.IsNullOrEmpty(r.NugetPackageId) ||
String.IsNullOrEmpty(r.PackageRoot)) &&
Directory.Exists(r.PackageRoot))
|> Array.map(fun r -> r.PackageRoot)
|> Array.filter (fun r ->
not (String.IsNullOrEmpty(r.NugetPackageId) || String.IsNullOrEmpty(r.PackageRoot))
&& Directory.Exists(r.PackageRoot))
|> Array.map (fun r -> r.PackageRoot)

let nativeRoots =
resolutions
|> Array.filter(fun r ->
not(String.IsNullOrEmpty(r.NugetPackageId) ||
String.IsNullOrEmpty(r.NativePath)))
|> Array.map(fun r ->
if Directory.Exists(r.NativePath) then Some r.NativePath
elif File.Exists(r.NativePath) then Some (Path.GetDirectoryName(r.NativePath).Replace('\\', '/'))
else None)
|> Array.filter(fun r -> r.IsSome)
|> Array.map(fun r -> r.Value)

Array.concat [|managedRoots; nativeRoots|] |> Array.distinct

|> Array.filter (fun r -> not (String.IsNullOrEmpty(r.NugetPackageId) || String.IsNullOrEmpty(r.NativePath)))
|> Array.map (fun r ->
if Directory.Exists(r.NativePath) then
Some r.NativePath
elif File.Exists(r.NativePath) then
Some(Path.GetDirectoryName(r.NativePath).Replace('\\', '/'))
else
None)
|> Array.filter (fun r -> r.IsSome)
|> Array.map (fun r -> r.Value)

Array.concat [| managedRoots; nativeRoots |] |> Array.distinct

let getResolutionsFromFile resolutionsFile =

let lines =
try
File.ReadAllText(resolutionsFile).Split([| '\r'; '\n'|], StringSplitOptions.None)
|> Array.filter(fun line -> not(String.IsNullOrEmpty(line)))
File
.ReadAllText(resolutionsFile)
.Split([| '\r'; '\n' |], StringSplitOptions.None)
Comment on lines +87 to +89
Copy link
Member

@vzarytovskii vzarytovskii May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, File on its own line looks weird.

|> Array.filter (fun line -> not (String.IsNullOrEmpty(line)))
with
| _ -> [||]

[| for line in lines do
let fields = line.Split(',')
if fields.Length < 8 then raise (InvalidOperationException(sprintf "Internal error - Invalid resolutions file format '%s'" line))
else
{ NugetPackageId = fields[0]
NugetPackageVersion = fields[1]
PackageRoot = fields[2]
FullPath = fields[3]
AssetType = fields[4]
IsNotImplementationReference = fields[5]
InitializeSourcePath = fields[6]
NativePath = fields[7]
}
[|
for line in lines do
let fields = line.Split(',')

if fields.Length < 8 then
raise (
InvalidOperationException(sprintf "Internal error - Invalid resolutions file format '%s'" line)
)
else
{
NugetPackageId = fields[0]
NugetPackageVersion = fields[1]
PackageRoot = fields[2]
FullPath = fields[3]
AssetType = fields[4]
IsNotImplementationReference = fields[5]
InitializeSourcePath = fields[6]
NativePath = fields[7]
}
|]

let makeScriptFromReferences (references:string seq) poundRprefix =
let makeScriptFromReferences (references: string seq) poundRprefix =
let expandReferences =
references
|> Seq.fold(fun acc r -> acc + poundRprefix + r + "\"" + Environment.NewLine) ""
|> Seq.fold (fun acc r -> acc + poundRprefix + r + "\"" + Environment.NewLine) ""

let projectTemplate ="""
let projectTemplate =
"""
// Generated from #r "nuget:Package References"
// ============================================
//
Expand All @@ -121,9 +131,11 @@ module internal ProjectFile =
$(POUND_R)

"""

projectTemplate.Replace("$(POUND_R)", expandReferences)

let generateProjectBody = """
let generateProjectBody =
"""
<Project Sdk='Microsoft.NET.Sdk'>

<PropertyGroup>
Expand Down
Loading