private static void setupLogging(string path) { var reader = new ConfigReader(path); var logPath = reader.Get("oi.logpath"); if (Directory.Exists(logPath)) Logger.Assign(new FileLogger(Path.Combine(logPath, "OpenIDE.CodeEngine.log"))); }
public static void Main(string[] args) { if (args.Length < 1) return; var path = args[0]; setupLogging(path); Logger.Write("Initializing with path: {0}", path); string defaultLanguage = null; if (args.Length > 1) { defaultLanguage = args[1]; Logger.Write("Default language is: {0}", defaultLanguage); } string[] enabledLanguages = null; if (args.Length > 2 && args[2].Length > 0) { enabledLanguages = args[2].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Logger.Write("Enabled languages are: {0}", args[2]); } if (!Directory.Exists(path) && !File.Exists(path)) return; var endpoint = Bootstrapper.GetEndpoint(path, enabledLanguages); var reader = new ConfigReader(path); var fallbackmode = reader.Get("oi.fallbackmode") != "disabled"; if (fallbackmode) { Logger.Write("Starting code engine with fallback mode"); if (!runForm(endpoint, defaultLanguage)) startEngine(endpoint); } else { Logger.Write("Starting code engine"); startEngineNoX(endpoint); } Bootstrapper.Shutdown(); }
public AppSettings(string path, Func<IEnumerable<ICommandHandler>> handlers, Func<IEnumerable<ICommandHandler>> pluginHandlers) { _path = path; SourcePrioritization = new string[] {}; var locator = new ProfileLocator(fixPath(Environment.CurrentDirectory)); RootPath = locator.GetLocalProfilePath("default"); if (RootPath == null) RootPath = fixPath(Directory.GetCurrentDirectory()); else RootPath = System.IO.Path.GetDirectoryName(RootPath); var reader = new ConfigReader(RootPath); var defaultLanguage = reader.Get("default.language"); if (defaultLanguage != null) DefaultLanguage = defaultLanguage; var enabledLanguages = reader.Get("enabled.languages"); if (enabledLanguages != null) EnabledLanguages = splitValue(enabledLanguages); var prioritizedSources = reader.Get("oi.source.prioritization"); if (prioritizedSources != null) SourcePrioritization = splitValue(prioritizedSources); }
public static CommandEndpoint GetEndpoint(string path, string[] enabledLanguages) { _path = path; var reader = new ConfigReader(_path); _interpreters = new Interpreters(_path); ProcessExtensions.GetInterpreter = (file) => { var interpreters = _interpreters .GetInterpreterFor(Path.GetExtension(file)); return interpreters; }; _cache = new TypeCache(); _outputEndpoint = new OutputEndpoint(_path); Logger.Write("Event endpoint serving on port: {0}", _outputEndpoint.Port); var responseDispatcher = new ResponseDispatcher( _path, false, "language-output ", (p, m) => _outputEndpoint.Send(p, m), (m) => _endpoint.Handle(m), (m) => {} ); responseDispatcher.OnlyCommands(); _pluginLocator = new PluginLocator( enabledLanguages, new ProfileLocator(_path), (msg) => { responseDispatcher.Handle(false, msg); } ); initPlugins(_pluginLocator); _eventEndpoint = new EventEndpoint(_path, _pluginLocator, _outputEndpoint); _eventEndpoint.Start(); Logger.Write("Event endpoint listening on port: {0}", _eventEndpoint.Port); Logger.Write("Creating plugin file tracker"); _tracker = new PluginFileTracker(); Logger.Write("Starting plugin file tracker"); var ignoreDirSetting = reader.Get("oi.ignore.directories"); var ignoreDirectories = new string[] {}; if (ignoreDirSetting != null) { ignoreDirectories = ignoreDirSetting .Split(new[] {','}) .Select(x => { if (Path.IsPathRooted(x)) { return x; } return Path.Combine(_path, x); }) .ToArray(); } _tracker.Start( _path, _cache, _cache, _pluginLocator, _eventEndpoint, ignoreDirectories); Logger.Write("Plugin file tracker started"); _endpoint = new CommandEndpoint(_path, _cache, _eventEndpoint); _endpoint.AddHandler(messageHandler); _handlers.AddRange(new IHandler[] { new GetProjectsHandler(_endpoint, _cache), new GetFilesHandler(_endpoint, _cache), new GetCodeRefsHandler(_endpoint, _cache), new GetSignatureRefsHandler(_endpoint, _cache), new GoToDefinitionHandler(_endpoint, _cache, _pluginLocator), new FindTypeHandler(_endpoint, _cache), new SnippetEditHandler(_endpoint, _cache, _path), new SnippetDeleteHandler(_cache, _path), new GetRScriptStateHandler(_endpoint, _eventEndpoint), new CompleteSnippetHandler(_cache, _path, _endpoint), new WriteOutputHandler(_eventEndpoint), new GetTokenPathHandler(_endpoint), // Make sure this handler is the last one since the command can be file extension or language name new LanguageCommandHandler(_endpoint, _cache, _pluginLocator) }); Logger.Write("Command endpoint started"); return _endpoint; }
private void printMergedConfig(string path) { Console.WriteLine("Configuration for: " + path); Console.WriteLine(); var reader = new ConfigReader(path); foreach (var key in reader.GetKeys().OrderBy(x => x)) { Console.WriteLine("\t{0}={1}", key, reader.Get(key)); } }
private string getLogFileArgument(string token) { var config = new ConfigReader(token); var path = config.Get("oi.logpath"); if (path == null) return ""; return " \"--logging=" + Path.Combine(path, "EditorEngine.log") + "\""; }
public void Execute(string[] arguments) { Logger.Write ("Getting editor instance"); var instance = _editorFactory.GetInstance(_rootPath); // TODO remove that unbeleavable nasty setfocus solution. Only init if launching editor var isSetfocus = arguments.Length > 0 && arguments[0] == "setfocus"; if (instance == null && arguments.Length >= 0 && !isSetfocus) { var args = new List<string>(); Logger.Write("Reading configuration from " + _rootPath); var configReader = new ConfigReader(_rootPath); if (arguments.Length == 0) { var name = configReader.Get("default.editor"); if (name == null) { Console.WriteLine("To launch without specifying editor you must specify the default.editor config option"); return; } args.Add(name); } else { args.AddRange(arguments); } var editorName = args[0]; args.AddRange( configReader .GetStartingWith("editor." + editorName) .Select(x => "--" + x.Key + "=" + x.Value)); if (!_environment.HasEditorEngine(_rootPath)) { if (!_environment.StartEditorEngine(args, _rootPath)) { Console.WriteLine("Could not launch editor " + args[0]); return; } } if (!_environment.HasEditorEngine(_rootPath)) { Console.WriteLine("Could not launch editor " + args[0]); return; } if (!_environment.IsRunning(_rootPath)) _environment.Start(_rootPath); } else if (arguments.Length >= 1 && arguments[0] == "get-dirty-files") { if (instance == null) return; string file = null; if (arguments.Length > 1) file = arguments[1]; Console.WriteLine(instance.GetDirtyFiles(file)); } else { if (instance == null) return; instance.Run(arguments); } }
public void Execute(string[] arguments) { Logger.Write ("Getting editor instance"); var instance = _editorFactory.GetInstance(_rootPath); // TODO remove that unbeleavable nasty setfocus solution. Only init if launching editor var isSetfocus = arguments.Length > 0 && arguments[0] == "setfocus"; if (instance == null && arguments.Length >= 0 && !isSetfocus) { var args = new List<string>(); Logger.Write("Reading configuration from " + _rootPath); var configReader = new ConfigReader(_rootPath); if (arguments.Length == 0) { var name = configReader.Get("default.editor"); if (name == null) { Console.WriteLine("To launch without specifying editor you must specify the default.editor config option"); return; } args.Add(name); } else { args.AddRange(arguments); } var editorName = args[0]; args.AddRange( configReader .GetStartingWith("editor." + editorName) .Select(x => "--" + x.Key + "=" + x.Value)); // A bit of a hack but if we find a configuration called executable for the editor // if the path is rooted (avvoids checking for files in PATH) display a warning // if it does not exist. var executableSetting = configReader.Get("editor." + editorName + ".executable"); if (executableSetting != null) { if (Path.IsPathRooted(executableSetting)) { if (!File.Exists(executableSetting)) _dispatch("warning|The configured path for the " + editorName + " editor does not exist: " + executableSetting); } } if (!_environment.HasEditorEngine(_rootPath)) { if (!_environment.StartEditorEngine(args, _rootPath)) { Logger.Write("Could not launch editor " + args[0]); return; } } if (!_environment.HasEditorEngine(_rootPath)) { Logger.Write("Could not launch editor " + args[0]); return; } if (!_environment.IsRunning(_rootPath)) { _environment.Start(_rootPath); } } else if (arguments.Length >= 1 && arguments[0] == "get-dirty-files") { if (instance == null) return; string file = null; if (arguments.Length > 1) file = arguments[1]; Console.WriteLine(instance.GetDirtyFiles(file)); } else if (arguments.Length == 1 && arguments[0] == "get-caret") { Console.WriteLine(instance.GetCaret()); } else if (arguments.Length == 3 && arguments[0] == "user-select") { instance.UserSelect(arguments[1], arguments[2]); } else if (arguments.Length >= 2 && arguments[0] == "user-input") { var defaultvalue = ""; if (arguments.Length > 2) defaultvalue = arguments[2]; instance.UserInput(arguments[1], defaultvalue); } else if (arguments.Length == 1 && arguments[0] == "get-windows") { Console.WriteLine(instance.GetWindows()); } else { if (instance == null) return; instance.Run(arguments); } }