Skip to content

Commit 43e189d

Browse files
committed
Change .xll enumeration approach and add some tracing
1 parent bed2568 commit 43e189d

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

Source/ExcelDna.IntelliSense/Providers/ExcelDnaIntelliSenseProvider.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void Initialize()
133133

134134
lock (_xllRegistrationInfos)
135135
{
136+
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize - inside lock");
136137
foreach (var xllPath in GetLoadedXllPaths())
137138
{
138139
if (!_xllRegistrationInfos.ContainsKey(xllPath))
@@ -147,6 +148,7 @@ public void Initialize()
147148
}
148149
}
149150
}
151+
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Initialize - after lock");
150152
}
151153

152154
// Must be called on the main Excel thread
@@ -156,24 +158,28 @@ public void Refresh()
156158
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Refresh");
157159
lock (_xllRegistrationInfos)
158160
{
161+
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Refresh - inside lock");
159162
foreach (var regInfo in _xllRegistrationInfos.Values)
160163
{
161164
regInfo.Refresh();
162165
}
163166
_xmlProvider.Refresh();
164167
_isDirty = false;
165168
}
169+
Logger.Provider.Info("ExcelDnaIntelliSenseProvider.Refresh - after lock");
166170
}
167171

168172
// May be called from any thread
169173
public IList<FunctionInfo> GetFunctionInfos()
170174
{
171175
IList<FunctionInfo> excelDnaInfos;
176+
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos");
172177
lock (_xllRegistrationInfos)
173178
{
179+
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos - inside lock");
174180
excelDnaInfos = _xllRegistrationInfos.Values.SelectMany(ri => ri.GetFunctionInfos()).ToList();
175181
}
176-
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos Begin");
182+
Logger.Provider.Verbose("ExcelDnaIntelliSenseProvider.GetFunctionInfos - after lock");
177183
foreach (var info in excelDnaInfos)
178184
{
179185
Logger.Provider.Verbose($"\t{info.Name}({info.ArgumentList.Count}) - {info.Description} ");
@@ -207,9 +213,9 @@ void ProcessLoadNotification(object state)
207213
var xllPath = notification.FullDllName;
208214

209215
Logger.Provider.Verbose($"ExcelDnaIntelliSenseProvider.ProcessLoadNotification {notification}, {xllPath}");
210-
211216
lock (_xllRegistrationInfos)
212217
{
218+
Logger.Provider.Verbose($"ExcelDnaIntelliSenseProvider.ProcessLoadNotification - inside lock");
213219
XllRegistrationInfo regInfo;
214220
if (!_xllRegistrationInfos.TryGetValue(xllPath, out regInfo))
215221
{
@@ -240,6 +246,7 @@ void ProcessLoadNotification(object state)
240246
// OnInvalidate();
241247
}
242248
}
249+
Logger.Provider.Verbose($"ExcelDnaIntelliSenseProvider.ProcessLoadNotification - after lock");
243250
}
244251

245252
string GetXmlPath(string xllPath) => Path.ChangeExtension(xllPath, ".intellisense.xml");
@@ -252,13 +259,42 @@ void ProcessLoadNotification(object state)
252259
// Alternative, more in line with our update watch, is to enumerate all loaded modules...
253260
IEnumerable<string> GetLoadedXllPaths()
254261
{
255-
// TODO: Implement properly...
256-
dynamic app = ExcelDnaUtil.Application;
257-
foreach (var addin in app.AddIns2)
262+
//// DOCUMENT(2) does not seem to include .xll add-ins
263+
264+
//var loadedDocs = Integration.XlCall.Excel(Integration.XlCall.xlfDocuments, 2) as object[,];
265+
//if (loadedDocs == null)
266+
//{
267+
// Logger.Provider.Verbose($"ExcelDnaIntelliSenseProvider.GetLoadedXllPaths - DOCUMENTS(2) failed");
268+
// yield break;
269+
//}
270+
//for (int i = 0; i < loadedDocs.GetLength(1); i++)
271+
//{
272+
// var docName = loadedDocs[0, i] as string;
273+
// if (docName != null && Path.GetExtension(docName) == ".xll")
274+
// {
275+
// yield return docName;
276+
// }
277+
//}
278+
279+
//// TODO: Implement properly...
280+
//dynamic app = ExcelDnaUtil.Application;
281+
//foreach (var addin in app.AddIns2)
282+
//{
283+
// if (addin.IsOpen && Path.GetExtension(addin.FullName) == ".xll")
284+
// {
285+
// yield return addin.FullName;
286+
// }
287+
//}
288+
289+
// Enumerate loaded modules - pick .xll files
290+
var process = Process.GetCurrentProcess();
291+
var modules = process.Modules;
292+
foreach (ProcessModule module in modules)
258293
{
259-
if (addin.IsOpen && Path.GetExtension(addin.FullName) == ".xll")
294+
var fileName = module.FileName;
295+
if (Path.GetExtension(fileName) == ".xll")
260296
{
261-
yield return addin.FullName;
297+
yield return fileName;
262298
}
263299
}
264300
}

0 commit comments

Comments
 (0)