Ejemplo n.º 1
0
 public Interpreters(string token)
 {
     Logger.Write("Initializing interpreters");
     _token = token;
     var reader = new ConfigReader(_token);
     readInterpreters(reader);
 }
Ejemplo n.º 2
0
 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")));
 }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        private void readInterpreters(ConfigReader config)
        {
            var prefix = "interpreter.";
            foreach (var interpreter in config.GetStartingWith(prefix)) {
                if (interpreter.Key.Length <= prefix.Length)
                    continue;

                var extension =
                    interpreter.Key
                        .Substring(
                            prefix.Length,
                             interpreter.Key.Length - prefix.Length);
                if (extension.Length == 0)
                    continue;

                extension = "." + extension;
                var path = interpreter.Value;
                if (Environment.OSVersion.Platform != PlatformID.Unix &&
                    Environment.OSVersion.Platform != PlatformID.MacOSX) {
                    path.Replace("/", "\\");
                }
                if (!File.Exists(path)) {
                    var modifiedPath =
                        System.IO.Path.Combine(
                            System.IO.Path.GetDirectoryName(
                                Assembly.GetExecutingAssembly().Location),
                            path);
                    if (File.Exists(path))
                        path = modifiedPath;
                }
                if (!_interpreters.ContainsKey(extension)) {
                    Logger.Write("Adding interpreter: " + path + " for " + extension);
                    _interpreters.Add(extension, path);
                }
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        private void build(string[] args)
        {
            string source = args[1];
            string destination = null;
            if (args.Length == 3) {
                destination = Path.GetFullPath(args[2]);
            } else {
                var setting = new ConfigReader(_token).Get("default.package.destination");
                if (setting != null)
                    destination = setting;
            }
            if (!Directory.Exists(destination))
                return;

            string name;
            string dir;
            string command;
            string packageFile;
            var package =
                getPackages()
                    .FirstOrDefault(x => x.ID == source);
            if (package == null) {
                var packageDefinition = "";
                if (File.Exists(source) && Path.GetFileName(source) == "package.json") {
                    packageDefinition = source;
                } else {
                    source = Path.GetFullPath(source);
                    dir = Path.GetDirectoryName(source);
                    name = Path.GetFileNameWithoutExtension(source);
                    packageDefinition = Path.Combine(Path.Combine(dir, name + "-files"), "package.json");
                    if (!File.Exists(packageDefinition)) {
                        _dispatch("error|Cannot find package.json. Run package init to create one");
                        return;
                    }
                }
                package = Package.Read(packageDefinition);
            }

            name = package.ID;
            command = package.Command;
            dir = Path.GetDirectoryName(Path.GetDirectoryName(package.File));
            packageFile = package.File;
            destination = Path.GetFullPath(destination);

            var appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            new Process()
                .Query(
                    Path.Combine(Path.Combine(appDir, "Packaging"), "oipckmngr.exe"),
                    string.Format("build \"{0}\" \"{1}\" \"{2}\" \"{3}\"", name, command, dir, destination),
                    false,
                    Environment.CurrentDirectory,
                    (err, line) => { Console.WriteLine(line); });
            _dispatch("event|builtin package built \"" + packageFile + "\"");
        }
Ejemplo n.º 7
0
        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));
     }
 }
Ejemplo n.º 9
0
 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") + "\"";
 }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
 private void userSelect(MessageArgs message, Editor editor)
 {
     var state = new ConfigReader(_endpoint.Token).Get("oi.userselect.ui.fallback");
     if (state == "disabled")
         return;
     _ctx.Post((s) =>
         {
             try {
                 var args = new CommandStringParser().Parse(message.Message).ToArray();
                 var items = new List<string>();
                 var keys = new List<string>();
                 foreach (var item in args[3].Split(new[] {','})) {
                     var chunks = item.Split(new[] {"||"}, StringSplitOptions.None);
                     if (chunks.Length > 1) {
                         keys.Add(chunks[0]);
                         items.Add(chunks[1]);
                     } else {
                         keys.Add(item);
                         items.Add(item);
                     }
                 }
                 var command = "user-selected";
                 if (message.Message.StartsWith("user-select-at-caret "))
                     command = "user-selected-at-caret";
                 var form = new UserSelectForm(items, keys, (item) => {
                     if (item != null)
                         _endpoint.PublishEvent(command+" '" + args[2] + "' '"  + item + "'");
                     else
                         _endpoint.PublishEvent(command+" '" + args[2] + "' 'user-cancelled'");
                     editor.SetFocus();
                 });
                 form.Show(this);
                 setToForeground(form);
             } catch {
             }
         }, null);
 }
Ejemplo n.º 13
0
 private void userInput(MessageArgs message, Editor editor)
 {
     Logger.Write("Getting state for userinput fallback");
     var state = new ConfigReader(_endpoint.Token).Get("oi.userinput.ui.fallback");
     Logger.Write("State is "+state);
     if (state == "disabled")
         return;
     _ctx.Post((s) =>
         {
             Logger.Write("Launching user input form");
             try {
                 var args = new CommandStringParser().Parse(message.Message).ToArray();
                 var defaultValue = "";
                 if (args.Length > 3)
                     defaultValue = args[3];
                 var form = new UserInputForm(defaultValue, (item) => {
                     if (item != null)
                         _endpoint.PublishEvent("user-inputted '" + args[2] + "' '"  + item + "'");
                     else
                         _endpoint.PublishEvent("user-inputted '" + args[2] + "' 'user-cancelled'");
                     editor.SetFocus();
                 });
                 form.Show(this);
                 setToForeground(form);
             } catch (Exception ex) {
                 Logger.Write(ex);
             }
         }, null);
 }