-
Notifications
You must be signed in to change notification settings - Fork 35
/
MarkdownLanguageInfo.cs
139 lines (121 loc) · 5.75 KB
/
MarkdownLanguageInfo.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
namespace MarkdownMode
{
using System;
using System.Runtime.InteropServices;
using ErrorHandler = Microsoft.VisualStudio.ErrorHandler;
using IConnectionPointContainer = Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer;
using IVsCodeWindow = Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow;
using IVsCodeWindowManager = Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindowManager;
using IVsColorizer = Microsoft.VisualStudio.TextManager.Interop.IVsColorizer;
using IVsEnumBSTR = Microsoft.VisualStudio.TextManager.Interop.IVsEnumBSTR;
using IVsEnumDebugName = Microsoft.VisualStudio.TextManager.Interop.IVsEnumDebugName;
using IVsLanguageDebugInfo = Microsoft.VisualStudio.TextManager.Interop.IVsLanguageDebugInfo;
using IVsLanguageInfo = Microsoft.VisualStudio.TextManager.Interop.IVsLanguageInfo;
using IVsTextBuffer = Microsoft.VisualStudio.TextManager.Interop.IVsTextBuffer;
using IVsTextLines = Microsoft.VisualStudio.TextManager.Interop.IVsTextLines;
using IVsTextManager2 = Microsoft.VisualStudio.TextManager.Interop.IVsTextManager2;
using IVsTextManagerEvents2 = Microsoft.VisualStudio.TextManager.Interop.IVsTextManagerEvents2;
using LANGPREFERENCES2 = Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES2;
using SVsServiceProvider = Microsoft.VisualStudio.Shell.SVsServiceProvider;
using SVsTextManager = Microsoft.VisualStudio.TextManager.Interop.SVsTextManager;
using TextSpan = Microsoft.VisualStudio.TextManager.Interop.TextSpan;
using VSConstants = Microsoft.VisualStudio.VSConstants;
[Guid("986C3927-0E8B-4E7B-B26D-DAF18F78F2C0")]
class MarkdownLanguageInfo : IVsLanguageInfo, IVsLanguageDebugInfo, IDisposable
{
/* The language name (used for the language service) and content type must be the same
* due to the way Visual Studio internally registers file extensions and content types.
*/
internal const string LanguageName = ContentType.Name;
internal const int LanguageResourceId = 100;
static readonly string[] FileExtensions = { ".mkd", ".md", ".mdown", ".mkdn", ".markdown" };
readonly SVsServiceProvider _serviceProvider;
LanguagePreferences _languagePreferences;
IDisposable _languagePreferencesCookie;
public MarkdownLanguageInfo(SVsServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
IVsTextManager2 textManager = (IVsTextManager2)serviceProvider.GetService(typeof(SVsTextManager));
LANGPREFERENCES2[] preferences = new LANGPREFERENCES2[1];
preferences[0].guidLang = typeof(MarkdownLanguageInfo).GUID;
ErrorHandler.ThrowOnFailure(textManager.GetUserPreferences2(null, null, preferences, null));
_languagePreferences = CreateLanguagePreferences(preferences[0]);
_languagePreferencesCookie = ((IConnectionPointContainer)textManager).Advise<LanguagePreferences, IVsTextManagerEvents2>(_languagePreferences);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_languagePreferencesCookie != null)
{
_languagePreferencesCookie.Dispose();
_languagePreferencesCookie = null;
}
}
}
public int GetCodeWindowManager(IVsCodeWindow pCodeWin, out IVsCodeWindowManager ppCodeWinMgr)
{
// will need to implement this method to support type and member dropdown bars
ppCodeWinMgr = null;
return VSConstants.E_FAIL;
}
public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer)
{
ppColorizer = null;
return VSConstants.E_FAIL;
}
public int GetFileExtensions(out string pbstrExtensions)
{
pbstrExtensions = string.Join(";", FileExtensions);
return VSConstants.S_OK;
}
public int GetLanguageName(out string bstrName)
{
bstrName = LanguageName;
return VSConstants.S_OK;
}
protected virtual LanguagePreferences CreateLanguagePreferences(LANGPREFERENCES2 preferences)
{
return new LanguagePreferences(preferences);
}
public int GetLanguageID(IVsTextBuffer pBuffer, int iLine, int iCol, out Guid pguidLanguageID)
{
pguidLanguageID = typeof(MarkdownLanguageInfo).GUID;
return VSConstants.S_OK;
}
public int GetLocationOfName(string pszName, out string pbstrMkDoc, TextSpan[] pspanLocation)
{
pbstrMkDoc = null;
return VSConstants.E_NOTIMPL;
}
public int GetNameOfLocation(IVsTextBuffer pBuffer, int iLine, int iCol, out string pbstrName, out int piLineOffset)
{
pbstrName = null;
piLineOffset = 0;
return VSConstants.E_NOTIMPL;
}
public int GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, int cLines, out IVsEnumBSTR ppEnum)
{
ppEnum = null;
return VSConstants.E_NOTIMPL;
}
public int IsMappedLocation(IVsTextBuffer pBuffer, int iLine, int iCol)
{
return VSConstants.S_FALSE;
}
public int ResolveName(string pszName, uint dwFlags, out IVsEnumDebugName ppNames)
{
ppNames = null;
return VSConstants.E_NOTIMPL;
}
public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol, TextSpan[] pCodeSpan)
{
return VSConstants.E_NOTIMPL;
}
}
}