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

Enable language preview option for fsi in the ide #8443

Merged
merged 1 commit into from Feb 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/fsharp/service/service.fs
Expand Up @@ -742,7 +742,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
member bc.ParseAndCheckProject(options, userOpName) =
reactor.EnqueueAndAwaitOpAsync(userOpName, "ParseAndCheckProject", options.ProjectFileName, fun ctok -> bc.ParseAndCheckProjectImpl(options, ctok, userOpName))

member __.GetProjectOptionsFromScript(filename, sourceText, loadedTimeStamp, otherFlags, useFsiAuxLib: bool option, useSdkRefs: bool option, assumeDotNetFramework: bool option, extraProjectInfo: obj option, optionsStamp: int64 option, userOpName) =
member __.GetProjectOptionsFromScript(filename, sourceText, previewEnabled, loadedTimeStamp, otherFlags, useFsiAuxLib: bool option, useSdkRefs: bool option, assumeDotNetFramework: bool option, extraProjectInfo: obj option, optionsStamp: int64 option, userOpName) =
reactor.EnqueueAndAwaitOpAsync (userOpName, "GetProjectOptionsFromScript", filename, fun ctok ->
cancellable {
use errors = new ErrorScope()
Expand All @@ -751,10 +751,16 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
let useFsiAuxLib = defaultArg useFsiAuxLib true
let useSdkRefs = defaultArg useSdkRefs true
let reduceMemoryUsage = ReduceMemoryFlag.Yes
let previewEnabled = defaultArg previewEnabled false

// Do we assume .NET Framework references for scripts?
let assumeDotNetFramework = defaultArg assumeDotNetFramework true
let otherFlags = defaultArg otherFlags [| |]
let extraFlags =
if previewEnabled then
[| "--langversion:preview" |]
else
[||]
let otherFlags = defaultArg otherFlags extraFlags
Copy link
Member

Choose a reason for hiding this comment

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

Should otherFlags not be the combination of otherFlags and preview?

let useSimpleResolution =
#if ENABLE_MONO_SUPPORT
runningOnMono || otherFlags |> Array.exists (fun x -> x = "--simpleresolution")
Expand Down Expand Up @@ -1142,9 +1148,9 @@ type FSharpChecker(legacyReferenceResolver,
backgroundCompiler.ParseAndCheckProject(options, userOpName)

/// For a given script file, get the ProjectOptions implied by the #load closure
member __.GetProjectOptionsFromScript(filename, source, ?loadedTimeStamp, ?otherFlags, ?useFsiAuxLib, ?useSdkRefs, ?assumeDotNetFramework, ?extraProjectInfo: obj, ?optionsStamp: int64, ?userOpName: string) =
member __.GetProjectOptionsFromScript(filename, source, ?previewEnabled, ?loadedTimeStamp, ?otherFlags, ?useFsiAuxLib, ?useSdkRefs, ?assumeDotNetFramework, ?extraProjectInfo: obj, ?optionsStamp: int64, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
backgroundCompiler.GetProjectOptionsFromScript(filename, source, loadedTimeStamp, otherFlags, useFsiAuxLib, useSdkRefs, assumeDotNetFramework, extraProjectInfo, optionsStamp, userOpName)
backgroundCompiler.GetProjectOptionsFromScript(filename, source, previewEnabled, loadedTimeStamp, otherFlags, useFsiAuxLib, useSdkRefs, assumeDotNetFramework, extraProjectInfo, optionsStamp, userOpName)

member __.GetProjectOptionsFromCommandLineArgs(projectFileName, argv, ?loadedTimeStamp, ?extraProjectInfo: obj) =
let loadedTimeStamp = defaultArg loadedTimeStamp DateTime.MaxValue // Not 'now', we don't want to force reloading
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/service/service.fsi
Expand Up @@ -228,7 +228,7 @@ type public FSharpChecker =
/// so that an 'unload' and 'reload' action will cause the script to be considered as a new project,
/// so that references are re-resolved.</param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member GetProjectOptionsFromScript : filename: string * sourceText: ISourceText * ?loadedTimeStamp: DateTime * ?otherFlags: string[] * ?useFsiAuxLib: bool * ?useSdkRefs: bool * ?assumeDotNetFramework: bool * ?extraProjectInfo: obj * ?optionsStamp: int64 * ?userOpName: string -> Async<FSharpProjectOptions * FSharpErrorInfo list>
member GetProjectOptionsFromScript : filename: string * sourceText: ISourceText * ?previewEnabled:bool * ?loadedTimeStamp: DateTime * ?otherFlags: string[] * ?useFsiAuxLib: bool * ?useSdkRefs: bool * ?assumeDotNetFramework: bool * ?extraProjectInfo: obj * ?optionsStamp: int64 * ?userOpName: string -> Async<FSharpProjectOptions * FSharpErrorInfo list>

/// <summary>
/// <para>Get the FSharpProjectOptions implied by a set of command line arguments.</para>
Expand Down
Expand Up @@ -20,6 +20,7 @@ open System.Threading
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.LanguageServices.Implementation.TaskList
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.LanguageServices
open Microsoft.VisualStudio.FSharp.Interactive.Session

[<AutoOpen>]
module private FSharpProjectOptionsHelpers =
Expand Down Expand Up @@ -97,7 +98,7 @@ type private FSharpProjectOptionsReactor (_workspace: VisualStudioWorkspace, set
match singleFileCache.TryGetValue(document.Id) with
| false, _ ->
let! sourceText = document.GetTextAsync(ct) |> Async.AwaitTask
let! scriptProjectOptions, _ = checkerProvider.Checker.GetProjectOptionsFromScript(document.FilePath, sourceText.ToFSharpSourceText())
let! scriptProjectOptions, _ = checkerProvider.Checker.GetProjectOptionsFromScript(document.FilePath, sourceText.ToFSharpSourceText(), SessionsProperties.fsiPreview)
let projectOptions =
if isScriptFile document.FilePath then
scriptProjectOptions
Expand Down
Expand Up @@ -11,6 +11,7 @@ open Microsoft.VisualStudio.TextManager.Interop
open Microsoft.VisualStudio.Text
open FSharp.Compiler.SourceCodeServices
open Microsoft.VisualStudio.FSharp.LanguageService.SiteProvider
open Microsoft.VisualStudio.FSharp.Interactive.Session

#nowarn "44" // use of obsolete CheckFileInProjectAllowingStaleCachedResults

Expand Down Expand Up @@ -94,7 +95,7 @@ type internal FSharpLanguageServiceBackgroundRequests_DEPRECATED
lazy // This portion is executed on the language service thread
let timestamp = if source=null then System.DateTime(2000,1,1) else source.OpenedTime // source is null in unit tests
let checker = getInteractiveChecker()
let checkOptions, _diagnostics = checker.GetProjectOptionsFromScript(fileName, FSharp.Compiler.Text.SourceText.ofString sourceText, timestamp, [| |]) |> Async.RunSynchronously
let checkOptions, _diagnostics = checker.GetProjectOptionsFromScript(fileName, FSharp.Compiler.Text.SourceText.ofString sourceText, SessionsProperties.fsiPreview, timestamp, [| |]) |> Async.RunSynchronously
let referencedProjectFileNames = [| |]
let projectSite = ProjectSitesAndFiles.CreateProjectSiteForScript(fileName, referencedProjectFileNames, checkOptions)
{ ProjectSite = projectSite
Expand Down
10 changes: 10 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/Properties.resx
Expand Up @@ -148,4 +148,14 @@
<data name="FSharpInteractiveDebugging" xml:space="preserve">
<value>Debugging</value>
</data>
<data name="FSharpInteractivePreview" xml:space="preserve">
<value>FSI Preview</value>
</data>
<data name="FSharpInteractivePreviewModeDescr" xml:space="preserve">
<value>Enable preview of in-development language features in F# Interactive</value>
</data>
<data name="FSharpInteractivePreviewMode" xml:space="preserve">
<value>Enable preview language features</value>
</data>

</root>
21 changes: 13 additions & 8 deletions vsintegration/src/FSharp.VS.FSI/fsiLanguageService.fs
Expand Up @@ -36,30 +36,35 @@ module internal ContentType =
[<ClassInterface(ClassInterfaceType.AutoDual)>]
[<Guid("4489e9de-6ac1-3cd6-bff8-a904fd0e82d4")>]
type FsiPropertyPage() =
inherit DialogPage()
inherit DialogPage()

[<ResourceCategory(SRProperties.FSharpInteractiveMisc)>]
[<ResourceDisplayName(SRProperties.FSharpInteractive64Bit)>]
[<ResourceDescription(SRProperties.FSharpInteractive64BitDescr)>]
[<ResourceDisplayName(SRProperties.FSharpInteractive64Bit)>]
[<ResourceDescription(SRProperties.FSharpInteractive64BitDescr)>]
member this.FsiPreferAnyCPUVersion with get() = SessionsProperties.useAnyCpuVersion and set (x:bool) = SessionsProperties.useAnyCpuVersion <- x

[<ResourceCategory(SRProperties.FSharpInteractiveMisc)>]
[<ResourceDisplayName(SRProperties.FSharpInteractiveOptions)>]
[<ResourceDescription(SRProperties.FSharpInteractiveOptionsDescr)>]
[<ResourceDescription(SRProperties.FSharpInteractiveOptionsDescr)>]
member this.FsiCommandLineArgs with get() = SessionsProperties.fsiArgs and set (x:string) = SessionsProperties.fsiArgs <- x

[<ResourceCategory(SRProperties.FSharpInteractiveMisc)>]
[<ResourceDisplayName(SRProperties.FSharpInteractiveShadowCopy)>]
[<ResourceDescription(SRProperties.FSharpInteractiveShadowCopyDescr)>]
[<ResourceDescription(SRProperties.FSharpInteractiveShadowCopyDescr)>]
member this.FsiShadowCopy with get() = SessionsProperties.fsiShadowCopy and set (x:bool) = SessionsProperties.fsiShadowCopy <- x

[<ResourceCategory(SRProperties.FSharpInteractiveDebugging)>]
[<ResourceDisplayName(SRProperties.FSharpInteractiveDebugMode)>]
[<ResourceDescription(SRProperties.FSharpInteractiveDebugModeDescr)>]
[<ResourceDescription(SRProperties.FSharpInteractiveDebugModeDescr)>]
member this.FsiDebugMode with get() = SessionsProperties.fsiDebugMode and set (x:bool) = SessionsProperties.fsiDebugMode <- x

[<ResourceCategory(SRProperties.FSharpInteractivePreview)>]
[<ResourceDisplayName(SRProperties.FSharpInteractivePreviewMode)>]
[<ResourceDescription(SRProperties.FSharpInteractivePreviewModeDescr)>]
member this.FsiPreview with get() = SessionsProperties.fsiPreview and set (x:bool) = SessionsProperties.fsiPreview <- x

// CompletionSet
type internal FsiCompletionSet(imageList,source:Source) =
type internal FsiCompletionSet(imageList,source:Source) =
inherit CompletionSet(imageList, source)

// Declarations
Expand Down
20 changes: 14 additions & 6 deletions vsintegration/src/FSharp.VS.FSI/sessions.fs
Expand Up @@ -70,6 +70,7 @@ module SessionsProperties =
let mutable fsiArgs = "--optimize"
let mutable fsiShadowCopy = true
let mutable fsiDebugMode = false
let mutable fsiPreview = false

// This code pre-dates the events/object system.
// Later: Tidy up.
Expand Down Expand Up @@ -218,7 +219,7 @@ let fsiStartInfo channelName =

let addBoolOption name value args = sprintf "%s --%s%s" args name (if value then "+" else "-")
let addStringOption name value args = sprintf "%s --%s:%O" args name value

let procArgs =
""
|> addStringOption "fsi-server-output-codepage" outCP
Expand All @@ -227,11 +228,18 @@ let fsiStartInfo channelName =
|> addStringOption "fsi-server" channelName
|> (fun s -> s + sprintf " %s" SessionsProperties.fsiArgs)
|> addBoolOption "shadowcopyreferences" SessionsProperties.fsiShadowCopy
|> (fun args -> if SessionsProperties.fsiDebugMode then
// for best debug experience, need optimizations OFF and debug info ON
// tack these on the the end, they will override whatever comes earlier
args |> addBoolOption "optimize" false |> addBoolOption "debug" true
else args)
|> (fun args ->
// for best debug experience, need optimizations OFF and debug info ON
// tack these on the the end, they will override whatever comes earlier
if SessionsProperties.fsiDebugMode then
args |> addBoolOption "optimize" false |> addBoolOption "debug" true
else
args)
|> (fun args ->
if SessionsProperties.fsiPreview then
args |> addStringOption "langversion" "preview"
else
args)

procInfo.Arguments <- procArgs
procInfo.CreateNoWindow <- true
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.cs.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Různé</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Sestavení stínových kopií</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.de.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Verschiedene</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Schattenkopie-Assemblys</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.es.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Varios</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Ensamblados de instantánea</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.fr.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Divers</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Assemblys de cliché instantané</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.it.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Varie</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Assembly copie shadow</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.ja.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">その他</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">シャドウ コピーのアセンブリ</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.ko.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">기타</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">섀도 복사본 어셈블리</target>
Expand Down
15 changes: 15 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/xlf/Properties.pl.xlf
Expand Up @@ -27,6 +27,21 @@
<target state="translated">Różne</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreview">
<source>FSI Preview</source>
<target state="new">FSI Preview</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewMode">
<source>Enable preview language features</source>
<target state="new">Enable preview language features</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractivePreviewModeDescr">
<source>Enable preview of in-development language features in F# Interactive</source>
<target state="new">Enable preview of in-development language features in F# Interactive</target>
<note />
</trans-unit>
<trans-unit id="FSharpInteractiveShadowCopy">
<source>Shadow copy assemblies</source>
<target state="translated">Zestawy kopii w tle</target>
Expand Down