Skip to content

Commit 8a9261a

Browse files
committed
Merge branch 'master' of https://github.com/fsharp/FSharp.Compiler.Service into fix-tpexpres
2 parents caf61f1 + a0cb744 commit 8a9261a

File tree

16 files changed

+396
-156
lines changed

16 files changed

+396
-156
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
language: csharp
22

3+
os:
4+
- linux
5+
- osx
6+
7+
mono:
8+
- latest
9+
- 4.0.5
10+
311
sudo: false
412

513
install:

docs/content/interactive.fsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ First, we need to reference the libraries that contain F# interactive service:
3131
*)
3232

3333
#r "FSharp.Compiler.Service.dll"
34+
open Microsoft.FSharp.Compiler.SourceCodeServices
3435
open Microsoft.FSharp.Compiler.Interactive.Shell
3536

3637
(**
@@ -81,7 +82,7 @@ and other top-level statements.
8182
let evalInteraction text =
8283
fsiSession.EvalInteraction(text)
8384
(**
84-
The two functions take string as an argument and evaluate (or execute) it as F# code. The code
85+
The two functions each take a string as an argument and evaluate (or execute) it as F# code. The code
8586
passed to them does not require `;;` at the end. Just enter the code that you want to execute:
8687
*)
8788
evalExpression "42+1"
@@ -97,6 +98,49 @@ let evalScript scriptPath =
9798
File.WriteAllText("sample.fsx", "let twenty = 10 + 10")
9899
evalScript "sample.fsx"
99100

101+
(**
102+
Catching errors
103+
------------------
104+
105+
``EvalExpression``, ``EvalInteraction`` and ``EvalScript`` are awkward if the
106+
code has type checking warnings or errors, or if evaluation fails with an exception.
107+
In these cases you can use ``EvalExpressionNonThrowing``, ``EvalInteractionNonThrowing``
108+
and ``EvalScriptNonThrowing``. These return a tuple of a result and an array of ``FSharpErrorInfo`` values.
109+
These represent the errors and warnings. The result part is a ``Choice<_,_>`` between an actual
110+
result and an exception.
111+
112+
The result part of ``EvalExpression`` and ``EvalExpressionNonThrowing`` is an optional ``FSharpValue``.
113+
If that value is not present then it just indicates that the expression didn't have a tangible
114+
result that could be represented as a .NET object. This siutation shouldn't actually
115+
occur for any normal input expressions, and only for primitives used in libraries.
116+
*)
117+
118+
File.WriteAllText("sample.fsx", "let twenty = 'a' + 10.0")
119+
let result, warnings = fsiSession.EvalScriptNonThrowing "sample.fsx"
120+
121+
// show the result
122+
match result with
123+
| Choice1Of2 () -> printfn "checked and executed ok"
124+
| Choice2Of2 exn -> printfn "execution exception: %s" exn.Message
125+
126+
(**
127+
Gives:
128+
129+
execution exception: Operation could not be completed due to earlier error
130+
*)
131+
132+
// show the errors and warnings
133+
for w in warnings do
134+
printfn "Warning %s at %d,%d" w.Message w.StartLineAlternate w.StartColumn
135+
136+
(**
137+
Gives:
138+
139+
Warning The type 'float' does not match the type 'char' at 1,19
140+
Warning The type 'float' does not match the type 'char' at 1,17
141+
*)
142+
143+
100144
(**
101145
Type checking in the evaluation context
102146
------------------
@@ -129,8 +173,8 @@ You can also request declaration list information, tooltip text and symbol resol
129173
*)
130174
open Microsoft.FSharp.Compiler
131175

132-
let identToken = Parser.tagOfToken(Parser.token.IDENT(""))
133-
checkResults.GetToolTipTextAlternate(1, 2, "xxx + xx", ["xxx"], identToken) // a tooltip
176+
// get a tooltip
177+
checkResults.GetToolTipTextAlternate(1, 2, "xxx + xx", ["xxx"], FSharpTokenTag.IDENT)
134178

135179
checkResults.GetSymbolUseAtLocation(1, 2, "xxx + xx", ["xxx"]) // symbol xxx
136180

docs/content/project.fsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ of `InteractiveChecker`:
2323
*)
2424
// Reference F# compiler API
2525
#r "FSharp.Compiler.Service.dll"
26+
#r "FSharp.Compiler.Service.ProjectCracker.dll"
2627

2728
open System
2829
open System.Collections.Generic
@@ -316,7 +317,7 @@ for any project that builds cleanly using the command line tools 'xbuild' or 'ms
316317

317318
let projectFile = __SOURCE_DIRECTORY__ + @"/../../src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj"
318319

319-
checker.GetProjectOptionsFromProjectFile(projectFile)
320+
ProjectCracker.GetProjectOptionsFromProjectFile(projectFile)
320321

321322

322323
(**
@@ -325,7 +326,7 @@ You can also request RELEASE mode and set other build configuration parameters:
325326
326327
*)
327328

328-
checker.GetProjectOptionsFromProjectFile(projectFile, [("Configuration", "Release")])
329+
ProjectCracker.GetProjectOptionsFromProjectFile(projectFile, [("Configuration", "Release")])
329330

330331
(**
331332

src/fsharp/ErrorLogger.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let rec findOriginalException err =
3838

3939

4040
/// Thrown when we stop processing the F# Interactive entry or #load.
41-
exception StopProcessing of string
41+
exception StopProcessing of exn option
4242

4343

4444
(* common error kinds *)

src/fsharp/FSharp.Compiler.Service.ProjectCracker.Exe/Program.fs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,23 @@ module Program =
378378
// C# referenced projects, as we don't look at them otherwise.
379379
let referencedProjectOutputs =
380380
if runningOnMono then
381-
[| yield! Array.map (fun (s,_) -> "-r:" + s) referencedProjectOptions
382-
for file in parsedProject.ProjectReferences do
383-
let ext = Path.GetExtension(file)
384-
if ext = ".csproj" || ext = ".vbproj" then
385-
let parsedProject = FSharpProjectFileInfo.Parse(file, properties=properties, enableLogging=false)
386-
match parsedProject.OutputFile with
387-
| None -> ()
388-
| Some f -> yield "-r:" + f |]
381+
[ yield! Array.map (fun (s,_) -> "-r:" + s) referencedProjectOptions
382+
for file in parsedProject.ProjectReferences do
383+
let ext = Path.GetExtension(file)
384+
if ext = ".csproj" || ext = ".vbproj" then
385+
let parsedProject = FSharpProjectFileInfo.Parse(file, properties=properties, enableLogging=false)
386+
match parsedProject.OutputFile with
387+
| None -> ()
388+
| Some f -> yield "-r:" + f ]
389389
else
390-
[||]
390+
[]
391+
392+
// On some versions of Mono the referenced projects are already
393+
// correctly included, so we make sure not to introduce duplicates
394+
|> List.filter (fun r -> not (Set.contains r (set parsedProject.Options)))
391395

392396
let options = { ProjectFile = file
393-
Options = Array.append (Array.ofList (parsedProject.Options))
394-
referencedProjectOutputs
397+
Options = Array.ofSeq (parsedProject.Options @ referencedProjectOutputs)
395398
ReferencedProjectOptions = referencedProjectOptions
396399
LogOutput = parsedProject.LogOutput }
397400

src/fsharp/FSharp.Compiler.Service.ProjectCracker/ProjectCracker.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ProjectCracker =
1313
static member GetProjectOptionsFromProjectFileLogged(projectFileName : string, ?properties : (string * string) list, ?loadedTimeStamp, ?enableLogging) =
1414
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
1515
let properties = defaultArg properties []
16-
let enableLogging = defaultArg enableLogging false
16+
let enableLogging = defaultArg enableLogging true
1717
let logMap = ref Map.empty
1818

1919
let rec convert (opts: FSharp.Compiler.Service.ProjectCracker.Exe.ProjectOptions) : FSharpProjectOptions =
@@ -50,4 +50,8 @@ type ProjectCracker =
5050
convert opts, !logMap
5151

5252
static member GetProjectOptionsFromProjectFile(projectFileName : string, ?properties : (string * string) list, ?loadedTimeStamp) =
53-
fst (ProjectCracker.GetProjectOptionsFromProjectFileLogged(projectFileName, ?properties=properties, ?loadedTimeStamp=loadedTimeStamp))
53+
fst (ProjectCracker.GetProjectOptionsFromProjectFileLogged(
54+
projectFileName,
55+
?properties=properties,
56+
?loadedTimeStamp=loadedTimeStamp,
57+
enableLogging=false))

src/fsharp/fsc.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ type InProcCompiler() =
20992099
let exitCode = ref 0
21002100
let exiter =
21012101
{ new Exiter with
2102-
member this.Exit n = exitCode := n; raise (StopProcessing "") }
2102+
member this.Exit n = exitCode := n; raise (StopProcessing None) }
21032103
try
21042104
typecheckAndCompile(argv, false, true, exiter, loggerProvider, None, None)
21052105
with

0 commit comments

Comments
 (0)