Skip to content

Commit

Permalink
Explicitly set custom F# VS settings if they are missing
Browse files Browse the repository at this point in the history
On package load, check if any of the custom F# settings are somehow missing
from the settings store.  Explicitly set them to their desired defaults if
they are indeed missing.

Added to the language service package since this is guaranteed
to load any time the project system package is loaded, but the converse is
not true (e.g. open loose F# script file without opening a solution).

fixes #199
closes #491

commit da9f29a
Author: latkin <latkin@microsoft.com>
Date:   Wed Jun 10 09:33:28 2015 -0700

    Don't create unused binding in VS 12.0

commit 92c8919
Author: latkin <latkin@microsoft.com>
Date:   Tue Jun 9 18:55:54 2015 -0700

    APIs used are new for 14.0, omit them for 12.0 builds

commit a662e18
Author: latkin <latkin@microsoft.com>
Date:   Tue Jun 9 17:28:22 2015 -0700

    Code review feedback, and add clickable URLs setting

commit b6697a7
Author: latkin <latkin@microsoft.com>
Date:   Mon Jun 8 18:13:35 2015 -0700

    Explicitly set custom F# VS settings if they are missing
  • Loading branch information
latkin committed Jun 10, 2015
1 parent 275b832 commit 66109b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0.dll" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.dll" />
<Reference Include="Microsoft.VisualStudio.Shell.Design, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Utilities, Version=$(VisualStudioVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Package.LanguageService.$(VisualStudioVersion)" />
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.11.0" />
<Reference Include="Microsoft.VisualStudio.ProjectAggregator" />
Expand Down
36 changes: 35 additions & 1 deletion vsintegration/src/vs/FsPkgs/FSharp.LanguageService/servicem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,11 @@ module Setup =
context.RemoveKey(providerRegKey())
#endif

// Workaround to access non-public settings persistence type.
// GetService( ) with this will work as long as the GUID matches the real type.
[<Guid("9B164E40-C3A2-4363-9BC5-EB4039DEF653")>]
type internal SVsSettingsPersistenceManager = class end

[<Guid("871D2A70-12A2-4e42-9440-425DD92A4116")>]
type FSharpPackage() as self =
inherit Package()
Expand All @@ -2016,12 +2021,41 @@ type FSharpPackage() as self =
let callback = new ServiceCreatorCallback(CreateIfEnabled)

let mutable mgr : IOleComponentManager = null


#if !VS_VERSION_DEV12
let fsharpSpecificProfileSettings =
[| "TextEditor.F#.Insert Tabs", box false
"TextEditor.F#.Brace Completion", box true
"TextEditor.F#.Make URLs Hot", box false
"TextEditor.F#.Indent Style", box 1u |]
#endif

override self.Initialize() =
UIThread.CaptureSynchronizationContext()
self.EstablishDefaultSettingsIfMissing()
(self :> IServiceContainer).AddService(typeof<FSharpLanguageService>, callback, true)
base.Initialize()

/// In case custom VS profile settings for F# are not applied, explicitly set them here.
/// e.g. 'keep tabs' is the text editor default, but F# requires 'insert spaces'.
/// We specify our customizations in the General profile for VS, but we have found that in some cases
/// those customizations are incorrectly ignored.
member private this.EstablishDefaultSettingsIfMissing() =
#if VS_VERSION_DEV12
() // ISettingsManager only implemented for VS 14.0+
#else
match this.GetService(typeof<SVsSettingsPersistenceManager>) with
| :? Microsoft.VisualStudio.Settings.ISettingsManager as settingsManager ->
for settingName,defaultValue in fsharpSpecificProfileSettings do
// Only take action if the setting has no current custom value
// If cloud-synced settings have already been applied or the user has made an explicit change, do nothing
match settingsManager.TryGetValue(settingName) with
| Microsoft.VisualStudio.Settings.GetValueResult.Missing, _ ->
settingsManager.SetValueAsync(settingName, defaultValue, false) |> ignore
| _ -> ()
| _ -> ()
#endif

member self.RegisterForIdleTime() =
mgr <- (self.GetService(typeof<SOleComponentManager>) :?> IOleComponentManager)
if (componentID = 0u && mgr <> null) then
Expand Down

0 comments on commit 66109b7

Please sign in to comment.