//---------------------------------- public static CodeMapItem[] GetMapOf(string code, string codeFile) { bool injected = CSScriptHelper.DecorateIfRequired(ref code); CodeMapItem[] map; if (Config.Instance.UsingRoslyn) { map = Syntaxer.GetMapOf(code, codeFile); } // map = RoslynEngine.GetMapOf(code, injected, codeFile); else { map = MonoEngine.GetMapOf(code, injected, codeFile); } if (injected) { int injectedLineOffset = CSScriptHelper.GetDecorationInfo(code).Item1; int injectedLineNumber = code.Substring(0, injectedLineOffset).Split('\n').Count(); map = map.Where(i => i.Line != injectedLineNumber).ToArray(); foreach (CodeMapItem item in map) { if (item.Line >= injectedLineNumber) { item.Line -= 1; } } } return(map); }
static DomRegion ResolveCSharpMember(string editorText, int offset, string fileName) { if (Config.Instance.UsingRoslyn) { return(Syntaxer.Resolve(editorText, fileName, offset)); } // return RoslynEngine.ResolveCSharpMember(editorText, offset, fileName); else { return(MonoEngine.ResolveCSharpMember(editorText, offset, fileName)); } }
//---------------------------------- static public string[] FindReferences(string editorText, int offset, string fileName) { if (Config.Instance.UsingRoslyn) { return(Syntaxer.FindReferences(editorText, fileName, offset)); } // return RoslynEngine.FindReferences(editorText, offset, fileName); else { return(MonoEngine.FindReferences(editorText, offset, fileName)); } }
public static string[] GetMemberInfo(string editorText, int offset, string fileName, bool collapseOverloads, out int methodStartPos) { if (Config.Instance.UsingRoslyn) { return(Syntaxer.GetMemberInfo(editorText, fileName, offset, collapseOverloads, out methodStartPos)); // return RoslynEngine.GetMemberInfo(editorText, offset, fileName, collapseOverloads, out methodStartPos); } else { return(MonoEngine.GetMemberInfo(editorText, offset, fileName, collapseOverloads, out methodStartPos)); } }
internal static IEnumerable <Intellisense.Common.TypeInfo> GetPossibleNamespaces(string editorText, string nameToResolve, string fileName) // not the best way to put in the whole string every time { if (Config.Instance.UsingRoslyn) { return(Syntaxer.GetPossibleNamespaces(editorText, fileName, nameToResolve)); } // return RoslynEngine.GetPossibleNamespaces(editorText, nameToResolve, fileName); else { return(MonoEngine.GetPossibleNamespaces(editorText, nameToResolve, fileName)); } }
static string FormatCodeWithRoslyn(string code, ref int pos, string file) { try { return(Syntaxer.Format(code, "csharp", ref pos)); } catch (Exception e) { MessageBox.Show("Cannot use Roslyn Formatter.\nError: " + e.Message + "\n\nThis can be caused by the absence of .NET 4.6.\n\nRoslyn Formatter will be disabled and the default formatter enabled instead. You can always reenable RoslynFormatter from the settings dialog.", "CS-Script"); } return(code); }
public static string[] GetMemberInfo(string editorText, int offset, string fileName, bool collapseOverloads, out int methodStartPos) { var includeSpec = Config.Instance.DefaultInclude; var effectiveCode = includeSpec + editorText; var effectiveOffset = offset + includeSpec.Length; var result = Syntaxer.GetMemberInfo(effectiveCode, fileName, effectiveOffset, collapseOverloads, out methodStartPos); methodStartPos -= includeSpec.Length; return(result); }
//---------------------------------- static public string[] FindReferences(string editorText, int offset, string fileName) { var includeSpec = Config.Instance.DefaultInclude; var effectiveCode = includeSpec + editorText; var effectiveOffset = offset + includeSpec.Length; string[] result = Syntaxer.FindReferences(effectiveCode, fileName, effectiveOffset); return(result.Select(x => (x.StartsWith(fileName + "(")) ? x.ChangeLineNumberInLocation(-1) : x) .ToArray()); }
public static string[] GetMemberInfo(string editorText, int offset, string fileName, bool collapseOverloads, out int methodStartPos) { var includeSpec = Config.Instance.DefaultInclude; var effectiveCode = includeSpec + editorText; var effectiveOffset = offset + includeSpec.Length; if (Config.Instance.UsingRoslyn) { return(Syntaxer.GetMemberInfo(effectiveCode, fileName, effectiveOffset, collapseOverloads, out methodStartPos)); } else { return(MonoEngine.GetMemberInfo(effectiveCode, effectiveOffset, fileName, collapseOverloads, out methodStartPos)); } }
public static IEnumerable <ICompletionData> GetCompletionData(string editorText, int offset, string fileName, bool isControlSpace = true) // not the best way to put in the whole string every time { try { if (string.IsNullOrEmpty(editorText)) { return(new ICompletionData[0]); } var effectiveOffset = offset; // VS experience // if (offset > 0) // { // for (int i = offset - 1; i >= 0; i--) // { // if (char.IsWhiteSpace(editorText[i])) // { // break; // } // else if (editorText[i] == '.') // { // effectiveOffset = i + 1; // } // } // } var data = Config.Instance.UsingRoslyn ? Syntaxer.GetCompletions(editorText, fileName, effectiveOffset).ToList() : MonoEngine.GetCompletionData(editorText, effectiveOffset, fileName, isControlSpace).ToList(); // var data = (GetCSharpScriptCompletionData(editorText, offset) ?? // (Config.Instance.UsingRoslyn ? // RoslynEngine.GetCompletionData(editorText, offset, fileName, isControlSpace) : // MonoEngine.GetCompletionData(editorText, offset, fileName, isControlSpace)) // ).ToList(); //suggest default CS-Script usings as well var extraItems = new List <ICompletionData>(); var document = Npp.GetCurrentDocument(); var line = document.GetLine(document.LineFromPosition(offset)).Trim(); bool isUsing = (line == "using"); if (isUsing) { extraItems.AddRange(CssCompletionData.DefaultNamespaces); extraItems.ForEach(x => x.CompletionText = x.CompletionText + ";"); } int length = Math.Min(editorText.Length - offset, 20); string rightHalfOfLine = editorText.Substring(offset, length) .Split(new[] { '\n' }, 2).FirstOrDefault(); data.ForEach(x => { if (isUsing) { x.CompletionText = x.CompletionText + ";"; } else if (Config.Instance.UseMethodBrackets) { if (x.CompletionType == CompletionType.method || x.CompletionType == CompletionType.extension_method) { //"Console.WriteLi| " but not "Console.Write|(" if (rightHalfOfLine == null || rightHalfOfLine.StartsWith(" ") || rightHalfOfLine.StartsWith("\r") || rightHalfOfLine.StartsWith("\n")) { x.CompletionText += "("; if (x.InvokeParametersSet) { if (x.InvokeParameters.Count() == 0 || (x.InvokeParameters.Count() == 1 && x.CompletionType == CompletionType.extension_method)) { x.CompletionText += ")"; //like .Clone() } } } } } }); return(data.Concat(extraItems)); } catch (Exception e) { e.LogAsDebug(); return(new ICompletionData[0]); //the exception can happens even for the internal NRefactor-related reasons } }
public static IEnumerable <ICompletionData> GetCompletionData(string editorText, int offset, string fileName, bool isControlSpace = true) // not the best way to put in the whole string every time { try { if (string.IsNullOrEmpty(editorText)) { return(new ICompletionData[0]); } var includeSpec = $"//css_inc {Config.Instance.DefaultIncludeFile}" + Environment.NewLine; var effectiveCode = includeSpec + editorText; var effectiveOffset = offset + includeSpec.Length; var data = Syntaxer.GetCompletions(effectiveCode, fileName, effectiveOffset).ToList(); //suggest default CS-Script usings as well var extraItems = new List <ICompletionData>(); var document = Npp.GetCurrentDocument(); var line = document.GetLine(document.LineFromPosition(offset)).Trim(); bool isUsing = (line == "using"); if (isUsing) { extraItems.AddRange(CssCompletionData.DefaultNamespaces); extraItems.ForEach(x => x.CompletionText = x.CompletionText + ";"); } int length = Math.Min(editorText.Length - offset, 20); string rightHalfOfLine = editorText.Substring(offset, length) .Split(new[] { '\n' }, 2).FirstOrDefault(); data.ForEach(x => { if (isUsing) { x.CompletionText = x.CompletionText + ";"; } else if (Config.Instance.UseMethodBrackets) { if (x.CompletionType == CompletionType.method || x.CompletionType == CompletionType.extension_method) { //"Console.WriteLi| " but not "Console.Write|(" if (rightHalfOfLine == null || rightHalfOfLine.StartsWith(" ") || rightHalfOfLine.StartsWith("\r") || rightHalfOfLine.StartsWith("\n")) { x.CompletionText += "("; if (x.InvokeParametersSet) { if (x.InvokeParameters.Count() == 0 || (x.InvokeParameters.Count() == 1 && x.CompletionType == CompletionType.extension_method)) { x.CompletionText += ")"; //like .Clone() } } } } } }); return(data.Concat(extraItems)); } catch (Exception e) { e.LogAsDebug(); return(new ICompletionData[0]); //the exception can happens even for the internal NRefactor-related reasons } }
static DomRegion ResolveCSharpMember(string editorText, int offset, string fileName) { return(Syntaxer.Resolve(editorText, fileName, offset)); }
internal static IEnumerable <Intellisense.Common.TypeInfo> GetPossibleNamespaces(string editorText, string nameToResolve, string fileName) // not the best way to put in the whole string every time { return(Syntaxer.GetPossibleNamespaces(editorText, fileName, nameToResolve)); }
//---------------------------------- public static CodeMapItem[] GetMapOf(string code, string codeFile) { CodeMapItem[] map = Syntaxer.GetMapOf(code, codeFile); return(map); }