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.

I've added this 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 dotnet#199
  • Loading branch information
latkin committed Jun 9, 2015
1 parent 275b832 commit b6697a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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
25 changes: 25 additions & 0 deletions 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,32 @@ type FSharpPackage() as self =
let callback = new ServiceCreatorCallback(CreateIfEnabled)

let mutable mgr : IOleComponentManager = null

let fsharpSpecificProfileSettings =
[| "TextEditor.F#.Insert Tabs", box false
"TextEditor.F#.Brace Completion", box true
"TextEditor.F#.Indent Style", box 1u |]

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() =
let settingsManager = this.GetService(typeof<SVsSettingsPersistenceManager>) :?> Microsoft.VisualStudio.Settings.ISettingsManager
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
| _ -> ()

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

0 comments on commit b6697a7

Please sign in to comment.