Skip to content

Commit b02cc36

Browse files
dungpaKevinRansom
authored andcommitted
Give F# Interactive buffer its own content type (dotnet#2192)
* Give F# Interactive buffer its own content type * Remove dummy classifier
1 parent f8103bb commit b02cc36

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

vsintegration/src/FSharp.VS.FSI/FSHarp.VS.FSI.fsproj

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,26 @@
2727
<GeneratePkgDefFile>true</GeneratePkgDefFile>
2828
<IncludePkgdefInVSIXContainer>true</IncludePkgdefInVSIXContainer>
2929
</PropertyGroup>
30+
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" />
31+
<Import Project="$(FSharpSourcesRoot)\..\vsintegration\vsintegration.targets" />
32+
<Import Project="$(VsSDKInstall)\Microsoft.VsSDK.targets" />
33+
<Target Name="GatherBinariesToBeSigned" AfterTargets="Localize" Condition="'$(UseGatherBinaries)' == 'true'">
34+
<ItemGroup>
35+
<BinariesToBeSigned Include="$(OutDir)$(AssemblyName).dll" />
36+
<BinariesToBeSigned Include="$(OutDir)localize\**\$(AssemblyName).resources.dll" />
37+
<FilesToSign Include="@(BinariesToBeSigned)">
38+
<Authenticode>Microsoft</Authenticode>
39+
<StrongName>StrongName</StrongName>
40+
</FilesToSign>
41+
</ItemGroup>
42+
</Target>
3043
<ItemGroup>
3144
<FilesToLocalize Include="$(OutDir)$(AssemblyName).dll">
3245
<TranslationFile>$(FSharpSourcesRoot)\..\loc\lcl\{Lang}\$(AssemblyName).dll.lcl</TranslationFile>
3346
<LciCommentFile>$(FSharpSourcesRoot)\..\loc\lci\$(AssemblyName).dll.lci</LciCommentFile>
3447
<HasLceComments>false</HasLceComments>
3548
<InProject>false</InProject>
3649
</FilesToLocalize>
37-
</ItemGroup>
38-
<ItemGroup>
3950
<FsSrGen Include="VFSIstrings.txt" />
4051
<Compile Include="AssemblyInfo.fs" />
4152
<Compile Include="srProperties.fs" />
@@ -66,6 +77,7 @@
6677
<Reference Include="Microsoft.VisualStudio.OLE.Interop.dll" />
6778
<Reference Include="EnvDTE.dll" />
6879
<Reference Include="EnvDTE80.dll" />
80+
<Reference Include="System.ComponentModel.Composition" />
6981
<Reference Include="VSLangProj" />
7082
<Reference Include="VSLangProj80" />
7183
<Reference Include="Microsoft.VisualStudio.OLE.Interop.dll" />
@@ -146,17 +158,4 @@
146158
<Project>{d5870cf0-ed51-4cbc-b3d7-6f56da84ac06}</Project>
147159
</ProjectReference>
148160
</ItemGroup>
149-
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" />
150-
<Import Project="$(FSharpSourcesRoot)\..\vsintegration\vsintegration.targets" />
151-
<Import Project="$(VsSDKInstall)\Microsoft.VsSDK.targets" />
152-
<Target Name="GatherBinariesToBeSigned" AfterTargets="Localize" Condition="'$(UseGatherBinaries)' == 'true'">
153-
<ItemGroup>
154-
<BinariesToBeSigned Include="$(OutDir)$(AssemblyName).dll" />
155-
<BinariesToBeSigned Include="$(OutDir)localize\**\$(AssemblyName).resources.dll" />
156-
<FilesToSign Include="@(BinariesToBeSigned)">
157-
<Authenticode>Microsoft</Authenticode>
158-
<StrongName>StrongName</StrongName>
159-
</FilesToSign>
160-
</ItemGroup>
161-
</Target>
162161
</Project>

vsintegration/src/FSharp.VS.FSI/fsiBasis.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ module internal Guids =
7575

7676
let guidFsharpLanguageService = Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B") // The F# source file lang service
7777

78+
[<Literal>]
79+
let fsiContentTypeName = "FSharpInteractive"
80+
7881
module internal Util =
7982
/// Utility function to create an instance of a class from the local registry. [From Iron Python].
8083
let CreateObject (globalProvider:System.IServiceProvider) (classType:Type,interfaceType:Type) =

vsintegration/src/FSharp.VS.FSI/fsiLanguageService.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ open Microsoft.VisualStudio.Shell
1616
open Microsoft.VisualStudio.Shell.Interop
1717
open Microsoft.VisualStudio.Package
1818
open Microsoft.VisualStudio.TextManager.Interop
19+
open System.ComponentModel.Composition
20+
open Microsoft.VisualStudio.Utilities
1921

2022
open Util
2123
open System.ComponentModel
@@ -24,6 +26,11 @@ open Microsoft.VisualStudio.FSharp.Interactive.Session
2426
module SP = Microsoft.VisualStudio.FSharp.Interactive.Session.SessionsProperties
2527

2628

29+
module internal ContentType =
30+
[<Export>]
31+
[<Name(Guids.fsiContentTypeName)>]
32+
[<BaseDefinition("code")>]
33+
let FSharpContentTypeDefinition = ContentTypeDefinition()
2734

2835
// FsiPropertyPage
2936
[<ComVisible(true)>]

vsintegration/src/FSharp.VS.FSI/fsiSessionToolWindow.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ open EnvDTE
1919
open Microsoft.VisualStudio.ComponentModelHost
2020
open Microsoft.VisualStudio.Editor
2121
open Microsoft.VisualStudio.Text.Editor
22-
22+
open Microsoft.VisualStudio.Text
23+
open Microsoft.VisualStudio.Utilities
2324

2425
type VSStd2KCmdID = VSConstants.VSStd2KCmdID // nested type
2526
type VSStd97CmdID = VSConstants.VSStd97CmdID // nested type
@@ -86,14 +87,14 @@ type internal FsiToolWindow() as this =
8687

8788
let providerGlobal = Package.GetGlobalService(typeof<IOleServiceProvider>) :?> IOleServiceProvider
8889
let provider = new ServiceProvider(providerGlobal) :> System.IServiceProvider
89-
let textViewAdapter =
90+
let textViewAdapter, contentTypeRegistry =
9091
// end of 623708 workaround.
9192
let componentModel = provider.GetService(typeof<SComponentModel>) :?> IComponentModel
92-
componentModel.GetService<IVsEditorAdaptersFactoryService>()
93+
componentModel.GetService<IVsEditorAdaptersFactoryService>(), componentModel.GetService<IContentTypeRegistryService>()
9394

9495
// REVIEW: trap provider nulls?
9596
let providerNative = provider.GetService(typeof<IOleServiceProvider>) :?> IOleServiceProvider
96-
let textLines = Util.CreateObjectT<VsTextBufferClass,IVsTextLines> provider
97+
let textLines = Util.CreateObjectT<VsTextBufferClass,IVsTextLines> provider
9798
do setSiteForObjectWithSite textLines providerNative
9899
do textLines.InitializeContent("", 0) |> throwOnFailure0
99100
let textView = Util.CreateObjectT<VsTextViewClass,IVsTextView> provider
@@ -123,7 +124,7 @@ type internal FsiToolWindow() as this =
123124
do codeWinMan.OnNewView(textView) |> throwOnFailure0
124125

125126
// Create the stream on top of the text buffer.
126-
let textStream = new TextBufferStream(textViewAdapter.GetDataBuffer(textLines))
127+
let textStream = new TextBufferStream(textViewAdapter.GetDataBuffer(textLines), contentTypeRegistry)
127128
let synchronizationContext = System.Threading.SynchronizationContext.Current
128129
let win32win = { new System.Windows.Forms.IWin32Window with member this.Handle = textView.GetWindowHandle()}
129130
let mutable textView = textView

vsintegration/src/FSharp.VS.FSI/fsiTextBufferStream.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ open Util
1919
open Microsoft.VisualStudio.Editor
2020
open Microsoft.VisualStudio.Text
2121
open Microsoft.VisualStudio.Text.Editor
22+
open Microsoft.VisualStudio.Utilities
2223

2324
// This type wraps the IVsTextLines which contains the FSI session (output and input).
2425
// It provides the API for writing directly to the read-only part of the buffer.
2526
// It extends the read-only marker on the buffer (making the written text read-only).
2627
//
27-
type internal TextBufferStream(textLines:ITextBuffer) =
28+
type internal TextBufferStream(textLines:ITextBuffer, contentTypeRegistry: IContentTypeRegistryService) =
2829
do if null = textLines then raise (new ArgumentNullException("textLines"))
29-
30+
do textLines.ChangeContentType(contentTypeRegistry.GetContentType Guids.fsiContentTypeName, Guid Guids.guidFsiLanguageService)
3031
let mutable readonlyRegion = null : IReadOnlyRegion
3132

3233
let extendReadOnlyRegion position =

0 commit comments

Comments
 (0)