Skip to content

Commit

Permalink
Added switch between old/new language services
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Tawfik committed Feb 12, 2016
1 parent 21571ca commit 497c854
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
6 changes: 4 additions & 2 deletions vsintegration/src/FSharp.Editor/FSRoslynContentType.fs
Expand Up @@ -7,16 +7,18 @@ open System.ComponentModel.Composition
open Microsoft.CodeAnalysis.Editor
open Microsoft.VisualStudio.Utilities

open Microsoft.VisualStudio.FSharp.LanguageService

module FSRoslynStaticTypeDefinitions =
[<Export>]
[<Name("F#")>]
[<BaseDefinition(ContentTypeNames.RoslynContentType)>]
let FSRoslynContentTypeDefinition = ContentTypeDefinition()

[<ExportContentTypeLanguageService("F#", "F#")>]
[<ExportContentTypeLanguageService(FSRoslynCommonConstants.FSharpContentType, FSRoslynCommonConstants.FSharpLanguageName)>]
type FSRoslynContentTypeLanguageService [<System.Composition.ImportingConstructor>](contentTypeRegistry : IContentTypeRegistryService) =
member this.contentTypeRegistryService = contentTypeRegistry

interface IContentTypeLanguageService with
member this.GetDefaultContentType() =
this.contentTypeRegistryService.GetContentType("F#");
this.contentTypeRegistryService.GetContentType(FSRoslynCommonConstants.FSharpContentType);
2 changes: 1 addition & 1 deletion vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Expand Up @@ -23,11 +23,11 @@
<ItemGroup>
<Compile Include="TokenContext.fs" />
<Compile Include="SmartIndent.fs" />
<Compile Include="FSRoslynProjectSiteService.fs" />
<Content Include="extension.vsixmanifest">
<CopyToOutputDirectory>false</CopyToOutputDirectory>
</Content>
<Compile Include="BraceCompletion.fs" />
<Compile Include="FSRoslynProjectSiteService.fs" />
<Compile Include="FSRoslynContentType.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
Expand Up @@ -18,18 +18,6 @@ open Microsoft.VisualStudio.LanguageServices.Implementation
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop

module FSRoslynCommonConstants =
[<Literal>]
let packageGuid = "871D2A70-12A2-4e42-9440-425DD92A4116"
[<Literal>]
let languageServiceGuid = "BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"
[<Literal>]
let editorFactoryGuid = "4EB7CCB7-4336-4FFD-B12B-396E9FD079A9"
[<Literal>]
let FSharpLanguageName = "F#"
[<Literal>]
let FSharpContentType = "F#"

[<Guid(FSRoslynCommonConstants.languageServiceGuid)>]
type FSRoslynLanguageService(package : FSRoslynPackage) =
inherit AbstractLanguageService<FSRoslynPackage, FSRoslynLanguageService, FSRoslynProject>(package)
Expand Down Expand Up @@ -79,7 +67,8 @@ and [<Guid(FSRoslynCommonConstants.packageGuid)>]
override this.RoslynLanguageName = FSRoslynCommonConstants.FSharpLanguageName

override this.Initialize() =
base.Initialize()
if LanguageServiceUtils.shouldEnableRoslynLanguageService then
base.Initialize()

override this.CreateWorkspace() = this.ComponentModel.GetService<VisualStudioWorkspaceImpl>()

Expand Down
Expand Up @@ -25,6 +25,7 @@
<EmbeddedResource Include="VSPackage.resx" />
<EmbeddedResource Include="FSLangSvcStrings.resx" />
<Compile Include="InternalsVisibleTo.fs" />
<Compile Include="LanguageServiceUtils.fs" />
<Compile Include="Error.fs" />
<Compile Include="Quickparse.fs" />
<Compile Include="Vs.fs" />
Expand Down
Expand Up @@ -44,8 +44,6 @@ module internal FSharpConstants =
let PLKProductName = "f#" // "Visual Studio Integration of FSharp Language Service"
let PLKProductVersion = "1.0"
let PLKResourceID = 1s
let enableLanguageService = "fsharp-language-service-enabled"



/// This class defines capabilities of the language service.
Expand Down
11 changes: 1 addition & 10 deletions vsintegration/src/FSharp.LanguageService/FSharpPackage.fs
Expand Up @@ -19,20 +19,11 @@ type internal SVsSettingsPersistenceManager = class end
[<Guid("871D2A70-12A2-4e42-9440-425DD92A4116")>]
type internal FSharpPackage() as self =
inherit Package()

// In case the config file is incorrect, we silently recover and leave the feature enabled
let enableLanguageService =
try
"false" <> ConfigurationManager.AppSettings.[FSharpConstants.enableLanguageService]
with e ->
System.Diagnostics.Debug.Assert
(false, sprintf "Error while loading 'devenv.exe.config' configuration: %A" e)
true

let mutable componentID = 0u

let CreateIfEnabled container serviceType =
if enableLanguageService then
if LanguageServiceUtils.shouldEnableVSLanguageService then
self.CreateService(container,serviceType)
else
null
Expand Down
42 changes: 42 additions & 0 deletions vsintegration/src/FSharp.LanguageService/LanguageServiceUtils.fs
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.LanguageService

open System
open System.Configuration
open System.Diagnostics

module FSRoslynCommonConstants =
[<Literal>]
let packageGuid = "871D2A70-12A2-4e42-9440-425DD92A4116"
[<Literal>]
let languageServiceGuid = "BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"
[<Literal>]
let editorFactoryGuid = "4EB7CCB7-4336-4FFD-B12B-396E9FD079A9"
[<Literal>]
let FSharpLanguageName = "F#"
[<Literal>]
let FSharpContentType = "F#"

module LanguageServiceUtils =

// This key can have 'off', 'vs', and 'roslyn' states. Will default to 'vs'.
let private languageServiceTypeKey = "fsharp-language-service"

let private getConfigValue(key: string) =
try
ConfigurationManager.AppSettings.[key].ToLower()
with ex ->
Debug.Assert(false, sprintf "Error loading 'devenv.exe.config' configuration[%s]: %A" key ex)
String.Empty

let shouldEnableVSLanguageService =
match getConfigValue(languageServiceTypeKey) with
| "off" -> false
| "roslyn" -> false
| _ -> true

let shouldEnableRoslynLanguageService =
match getConfigValue(languageServiceTypeKey) with
| "roslyn" -> true
| _ -> false

0 comments on commit 497c854

Please sign in to comment.