-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCommandRegistration.cs
More file actions
47 lines (39 loc) · 1.7 KB
/
Copy pathCommandRegistration.cs
File metadata and controls
47 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
namespace JavaScriptPrettier
{
[Export(typeof(IVsTextViewCreationListener))]
[ContentType("TypeScript")]
[ContentType("JavaScript")]
[TextViewRole(PredefinedTextViewRoles.PrimaryDocument)]
internal sealed class CommandRegistration : IVsTextViewCreationListener
{
[Import]
private IVsEditorAdaptersFactoryService AdaptersFactory { get; set; }
[Import]
private ITextDocumentFactoryService DocumentService { get; set; }
[Import]
private ITextBufferUndoManagerProvider UndoProvider { get; set; }
public void VsTextViewCreated(IVsTextView textViewAdapter)
{
IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
if (!DocumentService.TryGetTextDocument(view.TextBuffer, out ITextDocument doc))
return;
ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
var cmd = new PrettierCommand(view, undoManager, doc.Encoding, doc.FilePath);
view.Properties.AddProperty("prettierCommand", cmd);
AddCommandFilter(textViewAdapter, cmd);
}
private void AddCommandFilter(IVsTextView textViewAdapter, BaseCommand command)
{
textViewAdapter.AddCommandFilter(command, out IOleCommandTarget next);
command.Next = next;
}
}
}