未验证 提交 3b92fd2d 编写于 作者: D Don Syme 提交者: GitHub

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

* update formatting instructions

* format code
上级 872c2ef7
......@@ -28,8 +28,6 @@ src/Compiler/Symbols/**/*.fs
src/Compiler/SyntaxTree/**/*.fs
src/Compiler/TypedTree/**/*.fs
src/Compiler/Utilities/**/*.fs
src/FSharp.Compiler.Server.Shared/**/*.fs
src/FSharp.DependencyManager.Nuget/**/*.fs
src/Microsoft.FSharp.Compiler/**/*.fs
# Fantomas limitations on signature files (to investigate)
......
......@@ -5,5 +5,5 @@ namespace Microsoft.FSharp
open System.Reflection
open System.Runtime.InteropServices
[<assembly:ComVisible(false)>]
do()
[<assembly: ComVisible(false)>]
do ()
......@@ -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
......@@ -25,21 +25,23 @@ 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() = ()
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
......@@ -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)
|> 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"
// ============================================
//
......@@ -121,9 +131,11 @@ module internal ProjectFile =
$(POUND_R)
"""
projectTemplate.Replace("$(POUND_R)", expandReferences)
let generateProjectBody = """
let generateProjectBody =
"""
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
......
......@@ -8,16 +8,19 @@ open System.Reflection
open FSDependencyManager
open Internal.Utilities.FSharpEnvironment
[<AttributeUsage(AttributeTargets.Assembly ||| AttributeTargets.Class , AllowMultiple = false)>]
type DependencyManagerAttribute() = inherit Attribute()
[<AttributeUsage(AttributeTargets.Assembly ||| AttributeTargets.Class, AllowMultiple = false)>]
type DependencyManagerAttribute() =
inherit Attribute()
/// The result of building the package resolution files.
type PackageBuildResolutionResult =
{ success: bool
projectPath: string
stdOut: string array
stdErr: string array
resolutionsFile: string option }
{
success: bool
projectPath: string
stdOut: string array
stdErr: string array
resolutionsFile: string option
}
module internal Utilities =
......@@ -25,48 +28,57 @@ module internal Utilities =
/// Note that a quoted string is not going to be mangled into pieces.
let trimChars = [| ' '; '\t'; '\''; '\"' |]
let inline private isNotQuotedQuotation (text: string) n = n > 0 && text[n-1] <> '\\'
let inline private isNotQuotedQuotation (text: string) n = n > 0 && text[n - 1] <> '\\'
let getOptions text =
let split (option:string) =
let split (option: string) =
let pos = option.IndexOf('=')
let stringAsOpt text =
if String.IsNullOrEmpty(text) then None
else Some text
if String.IsNullOrEmpty(text) then
None
else
Some text
let nameOpt =
if pos <= 0 then None
else stringAsOpt (option.Substring(0, pos).Trim(trimChars).ToLowerInvariant())
if pos <= 0 then
None
else
stringAsOpt (option.Substring(0, pos).Trim(trimChars).ToLowerInvariant())
let valueOpt =
let valueText =
if pos < 0 then option
if pos < 0 then
option
else if pos < option.Length then
option.Substring(pos + 1)
else ""
else
""
stringAsOpt (valueText.Trim(trimChars))
nameOpt,valueOpt
nameOpt, valueOpt
let last = String.length text - 1
let result = ResizeArray()
let mutable insideSQ = false
let mutable start = 0
let isSeperator c = c = ','
for i = 0 to last do
match text[i], insideSQ with
| c, false when isSeperator c -> // split when seeing a separator
| c, false when isSeperator c -> // split when seeing a separator
result.Add(text.Substring(start, i - start))
insideSQ <- false
start <- i + 1
| _, _ when i = last ->
result.Add(text.Substring(start, i - start + 1))
| c, true when isSeperator c -> // keep reading if a separator is inside quotation
| _, _ when i = last -> result.Add(text.Substring(start, i - start + 1))
| c, true when isSeperator c -> // keep reading if a separator is inside quotation
insideSQ <- true
| '\'', _ when isNotQuotedQuotation text i -> // open or close quotation
insideSQ <- not insideSQ // keep reading
| '\'', _ when isNotQuotedQuotation text i -> // open or close quotation
insideSQ <- not insideSQ // keep reading
| _ -> ()
result
|> List.ofSeq
|> List.map (fun option -> split option)
result |> List.ofSeq |> List.map (fun option -> split option)
let executeTool pathToExe arguments workingDir timeout =
match pathToExe with
......@@ -75,6 +87,7 @@ module internal Utilities =
let outputList = ResizeArray()
let mutable errorslock = obj
let mutable outputlock = obj
let outputDataReceived (message: string) =
if not (isNull message) then
lock outputlock (fun () -> outputList.Add(message))
......@@ -90,23 +103,25 @@ module internal Utilities =
psi.RedirectStandardError <- true
psi.Arguments <- arguments
psi.CreateNoWindow <- true
psi.EnvironmentVariables.Remove("MSBuildSDKsPath") // Host can sometimes add this, and it can break things
psi.EnvironmentVariables.Remove("MSBuildSDKsPath") // Host can sometimes add this, and it can break things
psi.UseShellExecute <- false
use p = new Process()
p.StartInfo <- psi
p.OutputDataReceived.Add(fun a -> outputDataReceived a.Data)
p.ErrorDataReceived.Add(fun a -> errorDataReceived a.Data)
p.ErrorDataReceived.Add(fun a -> errorDataReceived a.Data)
if p.Start() then
p.BeginOutputReadLine()
p.BeginErrorReadLine()
if not(p.WaitForExit(timeout)) then
if not (p.WaitForExit(timeout)) then
// Timed out resolving throw a diagnostic.
raise (TimeoutException(SR.timedoutResolvingPackages(psi.FileName, psi.Arguments)))
raise (TimeoutException(SR.timedoutResolvingPackages (psi.FileName, psi.Arguments)))
else
p.WaitForExit()
p.ExitCode = 0, outputList.ToArray(), errorsList.ToArray()
| None -> false, Array.empty, Array.empty
......@@ -114,26 +129,33 @@ module internal Utilities =
let buildProject projectPath binLogPath timeout =
let binLoggingArguments =
match binLogPath with
| Some(path) ->
let path = match path with
| Some path -> path // specific file
| None -> Path.Combine(Path.GetDirectoryName(projectPath), "msbuild.binlog") // auto-generated file
| Some (path) ->
let path =
match path with
| Some path -> path // specific file
| None -> Path.Combine(Path.GetDirectoryName(projectPath), "msbuild.binlog") // auto-generated file
sprintf "/bl:\"%s\"" path
| None -> ""
let timeout =
match timeout with
| Some(timeout) -> timeout
| Some (timeout) -> timeout
| None -> -1
let arguments prefix =
sprintf "%s -restore %s %c%s%c /nologo /t:InteractivePackageManagement" prefix binLoggingArguments '\"' projectPath '\"'
sprintf
"%s -restore %s %c%s%c /nologo /t:InteractivePackageManagement"
prefix
binLoggingArguments
'\"'
projectPath
'\"'
let workingDir = Path.GetDirectoryName projectPath
let dotnetHostPath = getDotnetHostPath()
let dotnetHostPath = getDotnetHostPath ()
let args = arguments "msbuild -v:quiet"
let success, stdOut, stdErr =
executeTool dotnetHostPath args workingDir timeout
let success, stdOut, stdErr = executeTool dotnetHostPath args workingDir timeout
#if DEBUG
let diagnostics =
......@@ -142,13 +164,20 @@ module internal Utilities =
$"dotnetHostPath: {dotnetHostPath}"
$"arguments: {args}"
|]
File.WriteAllLines(Path.Combine(workingDir, "build_CommandLine.txt"), diagnostics)
File.WriteAllLines(Path.Combine(workingDir, "build_StandardOutput.txt"), stdOut)
File.WriteAllLines(Path.Combine(workingDir, "build_StandardError.txt"), stdErr)
#endif
let outputFile = projectPath + ".resolvedReferences.paths"
let resolutionsFile = if success && File.Exists(outputFile) then Some outputFile else None
let resolutionsFile =
if success && File.Exists(outputFile) then
Some outputFile
else
None
{
success = success
projectPath = projectPath
......@@ -158,8 +187,9 @@ module internal Utilities =
}
let generateSourcesFromNugetConfigs scriptDirectory workingDir timeout =
let dotnetHostPath = getDotnetHostPath()
let dotnetHostPath = getDotnetHostPath ()
let args = "nuget list source --format short"
let success, stdOut, stdErr =
executeTool dotnetHostPath args scriptDirectory timeout
#if DEBUG
......@@ -169,6 +199,7 @@ module internal Utilities =
$"dotnetHostPath: {dotnetHostPath}"
$"arguments: {args}"
|]
File.WriteAllLines(Path.Combine(workingDir, "nuget_CommandLine.txt"), diagnostics)
File.WriteAllLines(Path.Combine(workingDir, "nuget_StandardOutput.txt"), stdOut)
File.WriteAllLines(Path.Combine(workingDir, "nuget_StandardError.txt"), stdErr)
......@@ -184,5 +215,7 @@ module internal Utilities =
// E https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
// So strip off the flags
let pos = source.IndexOf(" ")
if pos >= 0 then yield ("i", source.Substring(pos).Trim())
if pos >= 0 then
yield ("i", source.Substring(pos).Trim())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册