//---------------------------------- 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); }
public IEnumerable <string> FindReferences(string editorText, string pattern, ResolveResult target, string fileName) { var references = new List <string>(); IDocument document = null; Type patternType = target.GetType(); string targetReflectionName = target.ToString(); if (target is MemberResolveResult) //the caret is on the member implementation { targetReflectionName = targetReflectionName.Replace("MemberResolveResult", "CSharpInvocationResolveResult"); patternType = typeof(CSharpInvocationResolveResult); } //we are looking for the member invocation code. //For example: "[CSharpInvocationResolveResult [Method Test.Who():System.Void]]" foreach (Match m in Regex.Matches(editorText, pattern)) { var match = ResolveFromPosition(editorText, m.Index, fileName); if (match != null && match.GetType() == patternType && match.ToString() == targetReflectionName) { if (document == null) { document = new ReadOnlyDocument(editorText); } int position = m.Index; var location = document.GetLocation(position); var line = document.GetLineByOffset(position); string lineText = editorText.GetTextOf(line); Tuple <int, int> decoration = CSScriptHelper.GetDecorationInfo(editorText); if (decoration.Item1 != -1) //the file content is no the actual one but an auto-generated (decorated) { if (position > decoration.Item1) { position -= decoration.Item2; string actualText = File.ReadAllText(fileName); if (actualText != editorText) { document = new ReadOnlyDocument(actualText); location = document.GetLocation(position); line = document.GetLineByOffset(position); lineText = actualText.GetTextOf(line); } } } references.Add(string.Format("{0}({1},{2}): {3}", fileName, location.Line, location.Column, lineText.Trim())); } } return(references); }
static string GetHelpFile() { if (CSScriptHelper.GetEngineExe() == null) { return(null); } string file = Path.Combine(Path.GetTempPath(), "CSScriptNpp\\ReflctedTypes", "cs-script." + typeof(CSScriptLibrary.CSScript).Assembly.GetName().Version + ".help.txt"); if (!File.Exists(file)) { var dir = Path.GetDirectoryName(file); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } foreach (string oldFile in Directory.GetFiles(dir, "cs-script.*.help.txt")) { try { File.Delete(oldFile); } catch { } } try { string cmdText = string.Format("\"{0}\" > \"{1}\"", CSScriptHelper.GetEngineExe(), file); var p = new Process(); p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = string.Format("/C \"{0}\"", cmdText); p.Start(); p.WaitForExit(); } catch { } if (!File.Exists(file)) { return(null); } } return(file); }