Skip to content

Commit 8fd3073

Browse files
committed
Refactor providers so that xml file overrides dna attributes
1 parent 3cb4db7 commit 8fd3073

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public void RegisterFunctionInfo(FunctionInfo functionInfo)
516516
}
517517
else
518518
{
519-
// Update against the function name
519+
// Update against the function name
520520
_functionInfoMap[functionInfo.Name] = functionInfo;
521521
}
522522
}

Source/ExcelDna.IntelliSense/IntellisenseHelper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ public IntelliSenseHelper()
2323
_uiMonitor = new UIMonitor(_syncContextMain);
2424
_display = new IntelliSenseDisplay(_syncContextMain, _uiMonitor);
2525

26-
var xmlProvider = new XmlIntelliSenseProvider();
2726
_providers = new List<IIntelliSenseProvider>
2827
{
29-
new ExcelDnaIntelliSenseProvider(xmlProvider),
30-
new WorkbookIntelliSenseProvider(xmlProvider),
31-
xmlProvider
28+
new ExcelDnaIntelliSenseProvider(),
29+
new WorkbookIntelliSenseProvider(),
3230
};
3331

3432
RegisterIntellisense();

Source/ExcelDna.IntelliSense/Providers/ExcelDnaIntelliSenseProvider.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public IEnumerable<FunctionInfo> GetFunctionInfos()
108108
bool _isDirty;
109109
public event EventHandler Invalidate;
110110

111-
public ExcelDnaIntelliSenseProvider(XmlIntelliSenseProvider xmlProvider)
111+
public ExcelDnaIntelliSenseProvider()
112112
{
113-
_xmlProvider = xmlProvider;
114113
_loaderNotification = new LoaderNotification();
115114
_loaderNotification.LoadNotification += loaderNotification_LoadNotification;
116115
_syncContextExcel = new ExcelSynchronizationContext();
116+
_xmlProvider = new XmlIntelliSenseProvider();
117117
}
118118

119119
#region IIntelliSenseProvider implementation
@@ -123,6 +123,9 @@ public void Initialize()
123123
{
124124
Debug.Assert(Thread.CurrentThread.ManagedThreadId == 1);
125125
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize");
126+
127+
_xmlProvider.Initialize();
128+
126129
lock (_xllRegistrationInfos)
127130
{
128131
foreach (var xllPath in GetLoadedXllPaths())
@@ -133,7 +136,7 @@ public void Initialize()
133136
XllRegistrationInfo regInfo = new XllRegistrationInfo(xllPath);
134137
_xllRegistrationInfos[xllPath] = regInfo;
135138

136-
_xmlProvider.RegisterXmlFunctionInfo(GetXmlPath(xllPath));
139+
_xmlProvider.RegisterXmlFunctionInfo(GetXmlPath(xllPath));
137140

138141
regInfo.Refresh();
139142
}
@@ -152,25 +155,30 @@ public void Refresh()
152155
{
153156
regInfo.Refresh();
154157
}
158+
_xmlProvider.Refresh();
155159
_isDirty = false;
156160
}
157161
}
158162

159163
// May be called from any thread
160164
public IList<FunctionInfo> GetFunctionInfos()
161165
{
162-
IList<FunctionInfo> functionInfos;
166+
IList<FunctionInfo> excelDnaInfos;
163167
lock (_xllRegistrationInfos)
164168
{
165-
functionInfos = _xllRegistrationInfos.Values.SelectMany(ri => ri.GetFunctionInfos()).ToList();
169+
excelDnaInfos = _xllRegistrationInfos.Values.SelectMany(ri => ri.GetFunctionInfos()).ToList();
166170
}
167171
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos Begin");
168-
foreach (var info in functionInfos)
172+
foreach (var info in excelDnaInfos)
169173
{
170174
Logger.Provider.Verbose($"\t{info.Name}({info.ArgumentList.Count}) - {info.Description} ");
171175
}
176+
177+
var xmlInfos = _xmlProvider.GetFunctionInfos();
178+
var allInfos = excelDnaInfos.Concat(xmlInfos).ToList();
179+
172180
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos End");
173-
return functionInfos;
181+
return allInfos;
174182
}
175183

176184
#endregion
@@ -215,14 +223,15 @@ void ProcessLoadNotification(object state)
215223
_isDirty = true;
216224
_syncContextExcel.Post(OnInvalidate, null);
217225
}
226+
218227
}
219228
}
220229
else if (notification.Reason == LoaderNotification.Reason.Unloaded)
221230
{
222231
_xllRegistrationInfos.Remove(xllPath);
223232
_xmlProvider.UnregisterXmlFunctionInfo(GetXmlPath(xllPath));
224233

225-
// Not too worried about cleaning up
234+
// Not too eager when cleaning up
226235
// OnInvalidate();
227236
}
228237
}

Source/ExcelDna.IntelliSense/Providers/WorkbookIntelliSenseProvider.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ public IEnumerable<FunctionInfo> GetFunctionInfos()
115115

116116
#region IIntelliSenseProvider implementation
117117

118-
public WorkbookIntelliSenseProvider(XmlIntelliSenseProvider xmlProvider)
118+
public WorkbookIntelliSenseProvider()
119119
{
120-
_xmlProvider = xmlProvider;
120+
_xmlProvider = new XmlIntelliSenseProvider();
121121
}
122122

123123
public void Initialize()
124124
{
125125
Logger.Provider.Info("WorkbookIntelliSenseProvider.Initialize");
126+
_xmlProvider.Initialize();
126127

127128
// The events are just to keep track of the set of open workbooks,
128129
var xlApp = (Application)ExcelDnaUtil.Application;
@@ -143,9 +144,9 @@ public void Initialize()
143144
WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
144145
_workbookRegistrationInfos[name] = regInfo;
145146

146-
RegisterWithXmlProvider(wb);
147-
148147
regInfo.Refresh();
148+
149+
RegisterWithXmlProvider(wb);
149150
}
150151
}
151152
}
@@ -161,6 +162,7 @@ public void Refresh()
161162
{
162163
regInfo.Refresh();
163164
}
165+
_xmlProvider.Refresh();
164166
}
165167
}
166168

@@ -169,7 +171,9 @@ public IList<FunctionInfo> GetFunctionInfos()
169171
{
170172
lock (_workbookRegistrationInfos)
171173
{
172-
return _workbookRegistrationInfos.Values.SelectMany(ri => ri.GetFunctionInfos()).ToList();
174+
var workbookInfos = _workbookRegistrationInfos.Values.SelectMany(ri => ri.GetFunctionInfos()).ToList();
175+
var xmlInfos = _xmlProvider.GetFunctionInfos();
176+
return workbookInfos.Concat(xmlInfos).ToList();
173177
}
174178
}
175179

@@ -216,8 +220,8 @@ void UnregisterWithXmlProvider(Workbook wb)
216220
{
217221
var path = wb.FullName;
218222
var xmlPath = GetXmlPath(path);
219-
_xmlProvider.UnregisterXmlFunctionInfo(xmlPath);
220223
_xmlProvider.UnregisterXmlFunctionInfo(path);
224+
_xmlProvider.UnregisterXmlFunctionInfo(xmlPath);
221225
}
222226

223227
//private void Excel_WorkbookAddinInstall(Workbook Wb)

Source/ExcelDna.IntelliSense/Providers/XmlIntelliSenseProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespace ExcelDna.IntelliSense
1111
{
1212
// CONSIDER: Support regular .NET XML documentation, either as files or packed?
13+
// NOTE: There will be multiple instances of the XmlIntelliSenseProvider instantiated,
14+
// by the ExcelDna- and Workbook-providers
1315
class XmlIntelliSenseProvider : IIntelliSenseProvider
1416
{
1517
public class XmlRegistrationInfo

0 commit comments

Comments
 (0)