Skip to content

Commit 9bd52be

Browse files
Added hack in order to make sure that intellisense is not triggered for windows others that F# interactive.
1 parent ea4ce3e commit 9bd52be

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

FSharp.Interactive.Intellisense/FSharpCompletionHandlerProvider .cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
namespace FSharp.Interactive.Intellisense
1515
{
1616
[Export(typeof(IVsTextViewCreationListener))]
17+
[Export(typeof(FSharpCompletionHandlerProvider))]
1718
[Name("F# completion")]
18-
[ContentType("any")] // F# and FSharpInteractive do not work here.
19+
[ContentType("text")] // F# and FSharpInteractive do not work here.
1920
[TextViewRole(PredefinedTextViewRoles.Interactive)]
21+
// [Order(Before = PredefinedCompletionProviderNames.Keyword)] - investigate this
2022
internal class FSharpCompletionHandlerProvider : IVsTextViewCreationListener
2123
{
2224
[Import]
@@ -28,6 +30,8 @@ internal class FSharpCompletionHandlerProvider : IVsTextViewCreationListener
2830
[Import]
2931
internal IContentTypeRegistryService ContentTypeRegistryService { get; set; }
3032

33+
public ITextView TextView { get; private set; }
34+
3135
public void VsTextViewCreated(IVsTextView textViewAdapter)
3236
{
3337
ITextView textView = AdapterService.GetWpfTextView(textViewAdapter);
@@ -42,6 +46,8 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
4246
return; // I didn't find a btter way to figure out if this IVsTextView is indeed F# interactive.
4347
}
4448

49+
this.TextView = textView;
50+
4551
FsiLanguageServiceHelper fsiLanguageServiceHelper = new FsiLanguageServiceHelper();
4652
fsiLanguageServiceHelper.StartRegisterAutocompleteWatchdogLoop();
4753

FSharp.Interactive.Intellisense/FSharpCompletionSourceProvider.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.VisualStudio.Language.Intellisense;
1+
using Microsoft.VisualStudio.Editor;
2+
using Microsoft.VisualStudio.Language.Intellisense;
23
using Microsoft.VisualStudio.Shell;
34
using Microsoft.VisualStudio.Text;
45
using Microsoft.VisualStudio.Text.Operations;
@@ -13,7 +14,7 @@
1314
namespace FSharp.Interactive.Intellisense
1415
{
1516
[Export(typeof(ICompletionSourceProvider))]
16-
[ContentType("any")]
17+
[ContentType("text")]
1718
[Name("F# completion handler")]
1819
internal class FSharpCompletionSourceProvider : ICompletionSourceProvider
1920
{
@@ -30,9 +31,27 @@ public FSharpCompletionSourceProvider()
3031
[Import]
3132
internal SVsServiceProvider ServiceProvider { get; set; }
3233

34+
[Import]
35+
internal IContentTypeRegistryService ContentTypeRegistryService { get; set; }
36+
37+
[Import]
38+
internal FSharpCompletionHandlerProvider FSharpCompletionHandlerProvider { get; set; }
39+
40+
3341
public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
3442
{
35-
return new FSharpCompletionSource(this, textBuffer);
43+
// There is no way to filter F# intellisense provider by content type since it is "text",
44+
// therefore have to do this small hack to trigger completions only for F# intellisense TextView.
45+
if (FSharpCompletionHandlerProvider != null &&
46+
FSharpCompletionHandlerProvider.TextView != null &&
47+
FSharpCompletionHandlerProvider.TextView.TextBuffer == textBuffer)
48+
{
49+
return new FSharpCompletionSource(this, textBuffer);
50+
}
51+
else
52+
{
53+
return null;
54+
}
3655
}
3756

3857
}

0 commit comments

Comments
 (0)