Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 14 additions & 14 deletions src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type OptionSpec =
| OptionStringList of (string -> unit)
| OptionStringListSwitch of (string -> OptionSwitch -> unit)
| OptionUnit of (unit -> unit)
| OptionHelp of (CompilerOptionBlock list -> unit) // like OptionUnit, but given the "options"
| OptionConsoleOnly of (CompilerOptionBlock list -> unit)
| OptionGeneral of (string list -> bool) * (string list -> string list) // Applies? * (ApplyReturningResidualArgs)

and CompilerOption =
Expand Down Expand Up @@ -95,7 +95,7 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
| OptionUnit _
| OptionSet _
| OptionClear _
| OptionHelp _ -> sprintf "--%s" s
| OptionConsoleOnly _ -> sprintf "--%s" s
| OptionStringList _ -> sprintf "--%s:%s" s tag
| OptionIntList _ -> sprintf "--%s:%s" s tag
| OptionSwitch _ -> sprintf "--%s[+|-]" s
Expand Down Expand Up @@ -186,7 +186,7 @@ let dumpCompilerOption prefix (CompilerOption (str, _, spec, _, _)) =
| OptionUnit _ -> printf "OptionUnit"
| OptionSet _ -> printf "OptionSet"
| OptionClear _ -> printf "OptionClear"
| OptionHelp _ -> printf "OptionHelp"
| OptionConsoleOnly _ -> printf "OptionConsoleOnly"
| OptionStringList _ -> printf "OptionStringList"
| OptionIntList _ -> printf "OptionIntList"
| OptionSwitch _ -> printf "OptionSwitch"
Expand Down Expand Up @@ -347,7 +347,7 @@ let ParseCompilerOptions (collectOtherArgument: string -> unit, blocks: Compiler

let rec attempt l =
match l with
| CompilerOption (s, _, OptionHelp f, d, _) :: _ when optToken = s && argString = "" ->
| CompilerOption (s, _, OptionConsoleOnly f, d, _) :: _ when optToken = s && argString = "" ->
reportDeprecatedOption d
f blocks
t
Expand Down Expand Up @@ -1983,13 +1983,13 @@ let displayVersion tcConfigB =
let miscFlagsBoth tcConfigB =
[
CompilerOption("nologo", tagNone, OptionUnit(fun () -> tcConfigB.showBanner <- false), None, Some(FSComp.SR.optsNologo ()))
CompilerOption("version", tagNone, OptionUnit(fun () -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ()))
CompilerOption("version", tagNone, OptionConsoleOnly(fun _ -> displayVersion tcConfigB), None, Some(FSComp.SR.optsVersion ()))
]

let miscFlagsFsc tcConfigB =
miscFlagsBoth tcConfigB
@ [
CompilerOption("help", tagNone, OptionHelp(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ()))
CompilerOption("help", tagNone, OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks), None, Some(FSComp.SR.optsHelp ()))
CompilerOption("@<file>", tagNone, OptionUnit ignore, None, Some(FSComp.SR.optsResponseFile ()))
]

Expand Down Expand Up @@ -2045,23 +2045,23 @@ let abbreviatedFlagsFsc tcConfigB =
CompilerOption(
"?",
tagNone,
OptionHelp(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)

CompilerOption(
"help",
tagNone,
OptionHelp(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)

CompilerOption(
"full-help",
tagNone,
OptionHelp(fun blocks -> displayHelpFsc tcConfigB blocks),
OptionConsoleOnly(fun blocks -> displayHelpFsc tcConfigB blocks),
None,
Some(FSComp.SR.optsShortFormOf ("--help"))
)
Expand Down Expand Up @@ -2103,7 +2103,7 @@ let PostProcessCompilerArgs (abbrevArgs: string Set) (args: string[]) =

let testingAndQAFlags _tcConfigB =
[
CompilerOption("dumpAllCommandLineOptions", tagNone, OptionHelp(fun blocks -> DumpCompilerOptionBlocks blocks), None, None) // "Command line options")
CompilerOption("dumpAllCommandLineOptions", tagNone, OptionConsoleOnly(fun blocks -> DumpCompilerOptionBlocks blocks), None, None) // "Command line options")
]

// Core compiler options, overview
Expand Down Expand Up @@ -2161,14 +2161,14 @@ let GetCoreFscCompilerOptions (tcConfigB: TcConfigBuilder) =
]

/// The core/common options used by the F# VS Language Service.
/// Filter out OptionHelp which does printing then exit. This is not wanted in the context of VS!!
/// Filter out OptionConsoleOnly which do printing then exit (e.g --help or --version). This is not wanted in the context of VS!
let GetCoreServiceCompilerOptions (tcConfigB: TcConfigBuilder) =
let isHelpOption =
let isConsoleOnlyOption =
function
| CompilerOption (_, _, OptionHelp _, _, _) -> true
| CompilerOption (_, _, OptionConsoleOnly _, _, _) -> true
| _ -> false

List.map (FilterCompilerOptionBlock(isHelpOption >> not)) (GetCoreFscCompilerOptions tcConfigB)
List.map (FilterCompilerOptionBlock(isConsoleOnlyOption >> not)) (GetCoreFscCompilerOptions tcConfigB)

/// The core/common options used by fsi.exe. [note, some additional options are added in fsi.fs].
let GetCoreFsiCompilerOptions (tcConfigB: TcConfigBuilder) =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerOptions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OptionSpec =
| OptionStringList of (string -> unit)
| OptionStringListSwitch of (string -> OptionSwitch -> unit)
| OptionUnit of (unit -> unit)
| OptionHelp of (CompilerOptionBlock list -> unit) // like OptionUnit, but given the "options"
| OptionConsoleOnly of (CompilerOptionBlock list -> unit)
| OptionGeneral of (string list -> bool) * (string list -> string list) // Applies? * (ApplyReturningResidualArgs)

and CompilerOption =
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,12 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig,
]);
PublicOptions(FSComp.SR.optsHelpBannerMisc(),
[ CompilerOption("help", tagNone,
OptionHelp (displayHelpFsi tcConfigB), None, Some (FSIstrings.SR.fsiHelp()))
OptionConsoleOnly (displayHelpFsi tcConfigB), None, Some (FSIstrings.SR.fsiHelp()))
]);
PrivateOptions(
[ CompilerOption("?", tagNone, OptionHelp (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
CompilerOption("help", tagNone, OptionHelp (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
CompilerOption("full-help", tagNone, OptionHelp (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
[ CompilerOption("?", tagNone, OptionConsoleOnly (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
CompilerOption("help", tagNone, OptionConsoleOnly (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
CompilerOption("full-help", tagNone, OptionConsoleOnly (displayHelpFsi tcConfigB), None, None); // "Short form of --help");
]);
PublicOptions(FSComp.SR.optsHelpBannerAdvanced(),
[CompilerOption("exec", "", OptionUnit (fun () -> interact <- false), None, Some (FSIstrings.SR.fsiExec()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="..\service\Symbols.fs">
<Link>Symbols.fs</Link>
</Compile>
<Compile Include="VisualStudioVersusConsoleContextTests.fs" />
<Compile Include="..\service\SyntaxTreeTests\TypeTests.fs">
<Link>SyntaxTree\TypeTests.fs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

module FSharp.Compiler.Service.Tests.VisualStudioVersusConsoleContextTests

open FSharp.Compiler.Text
open NUnit.Framework
open System.IO
open FSharp.Compiler.CompilerConfig
open FSharp.Compiler.CompilerOptions
open Internal.Utilities
open FSharp.Compiler.AbstractIL.ILBinaryReader

// copypasted from the CompilerOptions code,
// not worth changing that code's accessibility just for this test
let private getOptionsFromOptionBlocks blocks =
let GetOptionsOfBlock block =
match block with
| PublicOptions (_, opts) -> opts
| PrivateOptions opts -> opts

List.collect GetOptionsOfBlock blocks

[<Test>] // controls https://github.com/dotnet/fsharp/issues/13549
let ``Console-only options are filtered out for fsc in the VS context`` () =
// just a random thing to make things work
let builder = TcConfigBuilder.CreateNew(
null,
FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value,
ReduceMemoryFlag.Yes,
Directory.GetCurrentDirectory(),
false,
false,
CopyFSharpCoreFlag.No,
(fun _ -> None),
None,
Range.Zero)

let blocks = GetCoreServiceCompilerOptions builder
let options = getOptionsFromOptionBlocks blocks

// this is a very whitebox testing but arguably better than nothing
Assert.IsFalse(
options
|> List.exists (function
| CompilerOption (_, _, OptionConsoleOnly _, _, _) -> true
| _ -> false))

// and a couple of shots in the dark
Assert.False(
options
|> List.exists (function
// ignore deprecated options
// one of them actually allows specifying the compiler version
| CompilerOption (name, _, _, None, _) -> name = "version"
| _ -> false))

Assert.False(
options
|> List.exists (function
| CompilerOption (name, _, _, _, _) -> name = "help"))