Skip to content

Commit dad20ed

Browse files
authored
Merge pull request #142 from Excel-DNA/Refresh
Fixed REFRESH for .intellisense.xml file and Workbook.CustomXMLParts
2 parents 65f82cf + 8207c86 commit dad20ed

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

Source/ExcelDna.IntelliSense/Providers/WorkbookIntelliSenseProvider.cs

+22-15
Original file line numberDiff line numberDiff line change
@@ -353,21 +353,7 @@ void RegisterWithXmlProvider(Workbook wb)
353353
var path = wb.FullName;
354354
var xmlPath = GetXmlPath(path);
355355
_xmlProvider.RegisterXmlFunctionInfo(xmlPath); // Will check if file exists
356-
357-
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - Checking CustomXMLParts");
358-
359-
var customXmlParts = wb.CustomXMLParts.SelectByNamespace(XmlIntelliSense.Namespace);
360-
if (customXmlParts.Count > 0)
361-
{
362-
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - CustomXMLPart found");
363-
// We just take the first one - register against the Bworkbook name
364-
_xmlProvider.RegisterXmlFunctionInfo(path, customXmlParts[1].XML);
365-
}
366-
else
367-
{
368-
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - No CustomXMLPart found");
369-
}
370-
356+
_xmlProvider.RegisterXmlFunctionInfo(path, () => GetIntelliSenseFromCustomXMLParts(wb));
371357
}
372358

373359
void UnregisterWithXmlProvider(Workbook wb)
@@ -404,6 +390,27 @@ public void Dispose()
404390
}
405391
}
406392

393+
string GetIntelliSenseFromCustomXMLParts(Workbook wb)
394+
{
395+
string result = null;
396+
397+
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - Checking CustomXMLParts");
398+
399+
var customXmlParts = wb.CustomXMLParts.SelectByNamespace(XmlIntelliSense.Namespace);
400+
if (customXmlParts.Count > 0)
401+
{
402+
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - CustomXMLPart found");
403+
// We just take the first one - register against the workbook name
404+
result = customXmlParts[1].XML;
405+
}
406+
else
407+
{
408+
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.RegisterWithXmlProvider - No CustomXMLPart found");
409+
}
410+
411+
return result;
412+
}
413+
407414
string GetXmlPath(string wbPath) => Path.ChangeExtension(wbPath, ".intellisense.xml");
408415
}
409416
}

Source/ExcelDna.IntelliSense/Providers/XmlIntelliSenseProvider.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,25 @@ class XmlIntelliSenseProvider : IIntelliSenseProvider
1717
{
1818
public class XmlRegistrationInfo
1919
{
20-
string _fileName; // Might be .xml file or Workbook path. Use only if _xmlIntelliSense is null.
21-
string _xmlIntelliSense; // Might be null
20+
string _fileName; // Might be .xml file or Workbook path. Use only if _xmlIntelliSenseSource is null.
21+
Func<string> _xmlIntelliSenseSource; // Might be null
2222
XmlIntelliSense _intelliSense; // Might be null - lazy parsed
2323
string _path; // Directory of file, used to expand HelpTopic
2424

25-
public XmlRegistrationInfo(string fileName, string xmlIntelliSense)
25+
public XmlRegistrationInfo(string fileName, Func<string> xmlIntelliSenseSource)
2626
{
2727
_fileName = fileName;
28-
_xmlIntelliSense = xmlIntelliSense;
28+
_xmlIntelliSenseSource = xmlIntelliSenseSource;
2929
_path = Path.GetDirectoryName(fileName);
3030
}
3131

3232
// Called in a macro context
3333
public void Refresh()
3434
{
35-
if (_intelliSense != null)
36-
return; // Already done
37-
3835
try
3936
{
4037
// Parse first
41-
var xml = _xmlIntelliSense;
38+
var xml = _xmlIntelliSenseSource?.Invoke();
4239
if (xml == null)
4340
{
4441
xml = File.ReadAllText(_fileName);
@@ -87,15 +84,15 @@ public XmlIntelliSenseProvider()
8784
// May be called on the main Excel thread or on another thread (e.g. our automation thread)
8885
// Pass in the xmlFunctionInfo if available (from inside document), else file will be read
8986
// We make the parsing lazy...
90-
public void RegisterXmlFunctionInfo(string fileName, string xmlIntelliSense = null)
87+
public void RegisterXmlFunctionInfo(string fileName, Func<string> xmlIntelliSenseSource = null)
9188
{
92-
if (!File.Exists(fileName) && xmlIntelliSense == null)
89+
if (!File.Exists(fileName) && xmlIntelliSenseSource == null)
9390
{
9491
Logger.Provider.Verbose($"XmlIntelliSenseProvider.RegisterXmlFunctionInfo - Not IntelliSense file at {fileName}");
9592
return;
9693
}
97-
98-
var regInfo = new XmlRegistrationInfo(fileName, xmlIntelliSense);
94+
95+
var regInfo = new XmlRegistrationInfo(fileName, xmlIntelliSenseSource);
9996
Logger.Provider.Verbose($"XmlIntelliSenseProvider.RegisterXmlFunctionInfo - Created XmlRegistrationInfo info for {fileName}");
10097
lock (_xmlRegistrationInfos)
10198
{
@@ -157,7 +154,7 @@ public IList<FunctionInfo> GetFunctionInfos()
157154
Logger.Provider.Verbose("XmlIntelliSenseProvider.GetFunctionInfos - End");
158155
return functionInfos;
159156
}
160-
157+
161158
void OnInvalidate(object _unused_)
162159
{
163160
Logger.Provider.Verbose($"XmlIntelliSenseProvider.OnInvalidate - Invoking Invalidate event");

0 commit comments

Comments
 (0)