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

Merge Ionide changes upstream #110

Merged
merged 13 commits into from
Jun 20, 2016
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: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ nuget NUnit
nuget NUnit.Runners
nuget Octokit
nuget Suave
nuget FSharpLint.Core prerelease
nuget FSharpLint.Core prerelease
nuget FSharp.Core
53 changes: 28 additions & 25 deletions paket.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
REDIRECTS: ON
NUGET
remote: https://www.nuget.org/api/v2
specs:
FAKE (4.21.4)
FSharp.Compiler.Service (2.0.0.6)
FSharp.Compiler.Service.ProjectCracker (2.0.0.6)
FAKE (4.29)
FParsec (1.0.2)
FSharp.Compiler.Service (3.0)
FSharp.Compiler.Service.ProjectCracker (3.0)
FSharp.Core (4.0.0.1)
FSharpLint.Core (0.0.15-beta)
FSharp.Compiler.Service (>= 2.0.0.3)
Microsoft.Bcl (1.1.10)
FSharpLint.Core (0.3.0-beta)
FParsec
FSharp.Compiler.Service
FSharp.Compiler.Service.ProjectCracker
Microsoft.Bcl (1.1.10) - framework: net10, net11, net20, net30, net35, net40, net40-full
Microsoft.Bcl.Build (>= 1.0.14)
Microsoft.Bcl.Build (1.0.21) - import_targets: false
Microsoft.Net.Http (2.2.29)
Microsoft.Bcl.Build (1.0.21) - import_targets: false, framework: net10, net11, net20, net30, net35, net40, net40-full
Microsoft.Net.Http (2.2.29) - framework: net10, net11, net20, net30, net35, net40, net40-full
Microsoft.Bcl (>= 1.1.10)
Microsoft.Bcl.Build (>= 1.0.14)
Mono.Cecil (0.9.6.1)
NDesk.Options (0.2.1)
Newtonsoft.Json (8.0.2)
NUnit (3.2.0)
NUnit.ConsoleRunner (3.2.0)
NUnit.Extension.NUnitProjectLoader (3.2.0)
NUnit.Extension.NUnitV2Driver (3.2.0)
NUnit.Extension.NUnitV2ResultWriter (3.2.0)
NUnit.Extension.VSProjectLoader (3.2.0)
NUnit.Runners (3.2.0)
NUnit.ConsoleRunner (3.2.0)
NUnit.Extension.NUnitProjectLoader (3.2.0)
NUnit.Extension.NUnitV2Driver (3.2.0)
NUnit.Extension.NUnitV2ResultWriter (3.2.0)
NUnit.Extension.VSProjectLoader (3.2.0)
Octokit (0.18.0)
Microsoft.Net.Http
Suave (1.1.1)
Newtonsoft.Json (8.0.3)
NUnit (3.2.1)
NUnit.ConsoleRunner (3.2.1)
NUnit.Extension.NUnitProjectLoader (3.2.1)
NUnit.Extension.NUnitV2Driver (3.2.1)
NUnit.Extension.NUnitV2ResultWriter (3.2.1)
NUnit.Extension.VSProjectLoader (3.2.1)
NUnit.Runners (3.2.1)
NUnit.ConsoleRunner (3.2.1)
NUnit.Extension.NUnitProjectLoader (3.2.1)
NUnit.Extension.NUnitV2Driver (3.2.1)
NUnit.Extension.NUnitV2ResultWriter (3.2.1)
NUnit.Extension.VSProjectLoader (3.2.1)
Octokit (0.20)
Microsoft.Net.Http - framework: net10, net11, net20, net30, net35, net40, net40-full
Suave (1.1.2)
FSharp.Core (>= 3.1.2.5)
46 changes: 40 additions & 6 deletions src/FsAutoComplete.Core/CompilerServiceInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.SourceCodeServices
open Utils

type ParseAndCheckResults(parseResults: FSharpParseFileResults,
checkResults: FSharpCheckFileResults,
Expand Down Expand Up @@ -137,11 +138,35 @@ type FSharpCompilerServiceChecker() =
[| yield fsharpCoreRef
yield! Seq.filter (fun (s: string) -> not (s.EndsWith("FSharp.Core.dll"))) options |])
|> Option.getOrElse options

let ensureCorrectVersions (options: string[]) =
if Utils.runningOnMono then options
else
let version = Environment.dotNetVersions () |> Seq.head
let oldRef = Environment.referenceAssembliesPath @@ "v4.0"
let newRef = Environment.referenceAssembliesPath @@ version

let fsharpCoreRef = options |> Seq.find (fun s -> s.EndsWith "FSharp.Core.dll")

let newOptions =
options
|> Seq.filter (fun s -> not (s.EndsWith "FSharp.Core.dll"))
|> Seq.map (fun (s : string) -> s.Replace(oldRef, newRef) )
[| yield fsharpCoreRef
yield! newOptions |]

let chooseByPrefix prefix (s: string) =
if s.StartsWith(prefix) then Some (s.Substring(prefix.Length))
else None

member x.GetProjectOptionsFromScript(file, source) = async {
let! rawOptions = checker.GetProjectOptionsFromScript(file, source)
let opts =
rawOptions.OtherOptions
|> ensureCorrectFSharpCore
|> ensureCorrectVersions

return { rawOptions with OtherOptions = ensureCorrectFSharpCore rawOptions.OtherOptions }
return { rawOptions with OtherOptions = opts }
}

member x.GetProjectChecker(options) =
Expand Down Expand Up @@ -175,16 +200,25 @@ type FSharpCompilerServiceChecker() =
p.OtherOptions
{ p with OtherOptions = opts }, logMap

let chooseByPrefix prefix (s: string) =
if s.StartsWith(prefix) then Some (s.Substring(prefix.Length))
else None

let compileFiles = Seq.filter (fun (s:string) -> s.EndsWith(".fs")) po.OtherOptions
let outputFile = Seq.tryPick (chooseByPrefix "--out:") po.OtherOptions
let references = Seq.choose (chooseByPrefix "-r:") po.OtherOptions

Success (po, Seq.toList compileFiles, outputFile, Seq.toList references, logMap)
with e ->
with e ->
Failure e.Message

member x.TryGetCoreProjectOptions (file : string) : Result<_> =
if not (File.Exists file) then
Failure (sprintf "File '%s' does not exist" file)
else
try
let po = ProjectCoreCracker.GetProjectOptionsFromProjectFile file
let compileFiles = Seq.filter (fun (s:string) -> s.EndsWith(".fs")) po.OtherOptions
let outputFile = Seq.tryPick (chooseByPrefix "--out:") po.OtherOptions
let references = Seq.choose (chooseByPrefix "-r:") po.OtherOptions
Success (po, Seq.toList compileFiles, outputFile, Seq.toList references, Map<string,string>([||]))
with e ->
Failure e.Message


Expand Down
20 changes: 13 additions & 7 deletions src/FsAutoComplete.Core/Environment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace FsAutoComplete

open System
open System.IO
open Utils

module Environment =
let private environVar v = Environment.GetEnvironmentVariable v
Expand All @@ -17,11 +18,7 @@ module Environment =
|> fun detected -> if detected = null then @"C:\Program Files (x86)\" else detected

// Below code slightly modified from FAKE MSBuildHelper.fs

let inline private combinePaths path1 (path2 : string) = Path.Combine(path1, path2.TrimStart [| '\\'; '/' |])

let inline private (@@) path1 path2 = combinePaths path1 path2


let private tryFindFile dirs file =
let files =
dirs
Expand All @@ -41,7 +38,7 @@ module Environment =
| _ -> "")
|> Seq.filter ((<>) "")
|> Seq.cache
if not (Seq.isEmpty files) then Some(Seq.head files)
if not (Seq.isEmpty files) then Some(Seq.head files)
else None

let private tryFindPath backupPaths tool =
Expand All @@ -57,7 +54,7 @@ module Environment =
let msbuild =
if Utils.runningOnMono then "xbuild"
else
let MSBuildPath =
let MSBuildPath =
(programFilesX86 @@ @"\MSBuild\14.0\Bin") + ";" +
(programFilesX86 @@ @"\MSBuild\12.0\Bin") + ";" +
(programFilesX86 @@ @"\MSBuild\12.0\Bin\amd64") + ";" +
Expand Down Expand Up @@ -95,4 +92,13 @@ module Environment =
programFilesX86 @@ @"Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\"
let fsharpCoreVersions = ["4.4.0.0"; "4.3.1.0"; "4.3.0.0"]
tryFindFile (List.map (combinePaths referenceAssembliesPath) fsharpCoreVersions) "FSharp.Core.dll"

let referenceAssembliesPath =
programFilesX86 @@ @"Reference Assemblies\Microsoft\Framework\.NETFramework"

let dotNetVersions () =
Directory.EnumerateDirectories referenceAssembliesPath
|> Seq.sort
|> Seq.toArray
|> Array.rev

18 changes: 10 additions & 8 deletions src/FsAutoComplete.Core/FileSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ open System.IO

type FileSystem (actualFs: IFileSystem, getFiles: unit -> Map<string, VolatileFile>) =
let getFile (filename: string) =
let filename = Utils.normalizePath filename
let files = getFiles ()
Map.tryFind filename files

let getContent (filename: string) =
let filename = Utils.normalizePath filename
match getFile filename with
| Some d ->
let bytes = System.Text.Encoding.UTF8.GetBytes (String.Join ("\n", d.Lines))
Expand Down Expand Up @@ -46,12 +48,12 @@ type FileSystem (actualFs: IFileSystem, getFiles: unit -> Map<string, VolatileFi
| _ -> actualFs.GetLastWriteTimeShim fileName

member x.GetTempPathShim() = actualFs.GetTempPathShim()
member x.FileStreamCreateShim fileName = actualFs.FileStreamCreateShim fileName
member x.FileStreamWriteExistingShim fileName = actualFs.FileStreamWriteExistingShim fileName
member x.GetFullPathShim fileName = actualFs.GetFullPathShim fileName
member x.IsInvalidPathShim fileName = actualFs.IsInvalidPathShim fileName
member x.IsPathRootedShim fileName = actualFs.IsPathRootedShim fileName
member x.SafeExists fileName = actualFs.SafeExists fileName
member x.FileDelete fileName = actualFs.FileDelete fileName
member x.AssemblyLoadFrom fileName = actualFs.AssemblyLoadFrom fileName
member x.FileStreamCreateShim fileName = actualFs.FileStreamCreateShim (Utils.normalizePath fileName)
member x.FileStreamWriteExistingShim fileName = actualFs.FileStreamWriteExistingShim (Utils.normalizePath fileName)
member x.GetFullPathShim fileName = actualFs.GetFullPathShim (Utils.normalizePath fileName)
member x.IsInvalidPathShim fileName = actualFs.IsInvalidPathShim (Utils.normalizePath fileName)
member x.IsPathRootedShim fileName = actualFs.IsPathRootedShim (Utils.normalizePath fileName)
member x.SafeExists fileName = actualFs.SafeExists (Utils.normalizePath fileName)
member x.FileDelete fileName = actualFs.FileDelete (Utils.normalizePath fileName)
member x.AssemblyLoadFrom fileName = actualFs.AssemblyLoadFrom (Utils.normalizePath fileName)
member x.AssemblyLoad(assemblyName) = actualFs.AssemblyLoad assemblyName
9 changes: 7 additions & 2 deletions src/FsAutoComplete.Core/FsAutoComplete.Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ module Commands =
return match state.ProjectLoadTimes.TryFind file with
| Some oldtime when time - oldtime < TimeSpan.FromSeconds(1.0) -> [],state
| _ ->
let options =
if file.EndsWith "fsproj" then
checker.TryGetProjectOptions(file, verbose)
else
checker.TryGetCoreProjectOptions file

match checker.TryGetProjectOptions(file, verbose) with
match options with
| Result.Failure s -> [Response.error serialize s],state
| Result.Success(po, projectFiles, outFileOpt, references, logMap) ->
let pf = projectFiles |> List.map Path.GetFullPath
let pf = projectFiles |> List.map Path.GetFullPath |> List.map Utils.normalizePath
let res = Response.project serialize (file, pf, outFileOpt, references, logMap)
let checkOptions = pf |> List.fold (fun s f -> Map.add f po s) state.FileCheckOptions
let loadTimes = Map.add file time state.ProjectLoadTimes
Expand Down
Loading