FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex) { var nameLine = new TextLine { new TextRun { Text = functionInfo.Name, LinkAddress = FixHelpTopic(functionInfo.HelpTopic) } }; nameLine.Add(new TextRun { Text = "(" }); if (functionInfo.ArgumentList.Count > 0) { var argNames = functionInfo.ArgumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = string.Join(_argumentSeparator, argNames) }); } if (functionInfo.ArgumentList.Count > currentArgIndex) { if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = _argumentSeparator }); } nameLine.Add(new TextRun { Text = functionInfo.ArgumentList[currentArgIndex].Name, Style = System.Drawing.FontStyle.Bold }); argNames = functionInfo.ArgumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun {Text = _argumentSeparator + string.Join(_argumentSeparator, argNames)}); } } } nameLine.Add(new TextRun { Text = ")" }); var descriptionLines = GetFunctionDescriptionOrNull(functionInfo); var formattedText = new FormattedText { nameLine, descriptionLines }; if (functionInfo.ArgumentList.Count > currentArgIndex) { var description = GetArgumentDescriptionOrNull(functionInfo.ArgumentList[currentArgIndex]); if (description != null) formattedText.Add(description); } return formattedText; }
// TODO: Think about case again // TODO: Consider locking... public void RegisterFunctionInfo(FunctionInfo functionInfo) { // TODO : Dictionary from KeyLookup FunctionInfo oldFunctionInfo; if (!_functionInfoMap.TryGetValue(functionInfo.Name, out oldFunctionInfo)) { _functionInfoMap.Add(functionInfo.Name, functionInfo); } else { // Update against the function name _functionInfoMap[functionInfo.Name] = functionInfo; } }
TextLine GetArgumentDescriptionOrNull(FunctionInfo.ArgumentInfo argumentInfo) { if (string.IsNullOrEmpty(argumentInfo.Description)) return null; return new TextLine { new TextRun { Style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, Text = argumentInfo.Name + ": " }, new TextRun { Style = System.Drawing.FontStyle.Italic, Text = argumentInfo.Description ?? "" }, }; }
IEnumerable<TextLine> GetFunctionDescriptionOrNull(FunctionInfo functionInfo) { var description = functionInfo.Description; if (string.IsNullOrEmpty(description)) return null; return description.Split(s_newLineStringArray, StringSplitOptions.None) .Select(line => new TextLine { new TextRun { Style = System.Drawing.FontStyle.Regular, Text = line }}); }
public void UnregisterFunctionInfo(FunctionInfo functionInfo) { _functionInfoMap.Remove(functionInfo.Name); }
public void UnregisterFunctionInfo(FunctionInfo functionInfo) { _functionInfoMap.Remove(functionInfo.Name); }
FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex) { var nameLine = new TextLine { new TextRun { Text = functionInfo.Name, LinkAddress = FixHelpTopic(functionInfo.HelpTopic) } }; nameLine.Add(new TextRun { Text = "(" }); if (functionInfo.ArgumentList.Count > 0) { var argNames = functionInfo.ArgumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = string.Join(_argumentSeparator, argNames) }); } if (functionInfo.ArgumentList.Count > currentArgIndex) { if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = _argumentSeparator }); } nameLine.Add(new TextRun { Text = functionInfo.ArgumentList[currentArgIndex].Name, Style = System.Drawing.FontStyle.Bold }); argNames = functionInfo.ArgumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = _argumentSeparator + string.Join(_argumentSeparator, argNames) }); } } } nameLine.Add(new TextRun { Text = ")" }); var descriptionLines = GetFunctionDescriptionOrNull(functionInfo); var formattedText = new FormattedText { nameLine, descriptionLines }; if (functionInfo.ArgumentList.Count > currentArgIndex) { var description = GetArgumentDescriptionOrNull(functionInfo.ArgumentList[currentArgIndex]); if (description != null) { formattedText.Add(description); } } return(formattedText); }
// Not in macro context - don't call Excel, could be any thread. public IEnumerable <FunctionInfo> GetFunctionInfos() { // to avoid worries about locking and this being updated from another thread, we take a copy of the _regInfo reference var regInfo = _regInfo; if (regInfo == null) { yield break; } int numRows = regInfo.GetLength(0); int numCols = regInfo.GetLength(1); if (numRows < 2 || numCols < 2) // Either no registrations or no descriptions - nothing to register { yield break; } var idCheck = regInfo[1, 1] as string; if (!functionInfoId.Equals(idCheck, StringComparison.OrdinalIgnoreCase)) { Logger.Provider.Warn($"WorkbookIntelliSenseProvider - Invalid FunctionInfo Identifier: ({idCheck})"); yield break; } // regInfo is 1-based: object[1..x, 1..y]. for (int i = 2; i <= numRows; i++) { string functionName = regInfo[i, 1] as string; string description = regInfo[i, 2] as string; string helpTopic = (numCols >= 3) ? (regInfo[i, 3] as string) : ""; if (string.IsNullOrEmpty(functionName)) { continue; } List <FunctionInfo.ArgumentInfo> argumentInfos = new List <FunctionInfo.ArgumentInfo>(); for (int j = 4; j <= numCols - 1; j += 2) { var arg = regInfo[i, j] as string; var argDesc = regInfo[i, j + 1] as string; if (!string.IsNullOrEmpty(arg)) { argumentInfos.Add(new FunctionInfo.ArgumentInfo { Name = arg, Description = argDesc }); } } // Some cleanup and normalization functionName = functionName.Trim(); helpTopic = FunctionInfo.ExpandHelpTopic(_path, helpTopic); yield return(new FunctionInfo { Name = functionName, Description = description, HelpTopic = helpTopic, ArgumentList = argumentInfos, SourcePath = _name }); } }
FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex) { // In case of the special params pattern (x, y, arg1, ...) we base the argument display on an expanded argument list, matching Excel's behaviour, // and the magic expansion in the function wizard. var argumentList = GetExpandedArgumentList(functionInfo, currentArgIndex); var nameLine = new TextLine { new TextRun { Text = functionInfo.Name, LinkAddress = FixHelpTopic(functionInfo.HelpTopic) } }; nameLine.Add(new TextRun { Text = "(" }); if (argumentList.Count > 0) { var argNames = argumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = string.Join(_argumentSeparator, argNames) }); } if (argumentList.Count > currentArgIndex) { if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = _argumentSeparator }); } nameLine.Add(new TextRun { Text = argumentList[currentArgIndex].Name, Style = System.Drawing.FontStyle.Bold }); argNames = argumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray(); if (argNames.Length >= 1) { nameLine.Add(new TextRun { Text = _argumentSeparator + string.Join(_argumentSeparator, argNames) }); } } } nameLine.Add(new TextRun { Text = ")" }); var descriptionLines = GetFunctionDescriptionOrNull(functionInfo); var formattedText = new FormattedText { nameLine, descriptionLines }; if (argumentList.Count > currentArgIndex) { var description = GetArgumentDescription(argumentList[currentArgIndex]); formattedText.Add(description); } return(formattedText); }