<commit_before>'use strict';

var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var XRegExp = require('xregexp').XRegExp;

var SaveConfirmView = require('./save-confirm-view');
var BuildView = require('./build-view');

module.exports = {
  config: {
    keepVisible: {
      title: 'Keep Visisble',
      description: 'If the build panel should be kept visible at all times.',
      type: 'boolean',
      default: false
    },
    buildOnSave: {
      title: 'Automatically build on save',
      description: 'Autmatically build your project each time an editor is saved.',
      type: 'boolean',
      default: false
    },
    saveOnBuild: {
      title: 'Automatically save on build',
      description: 'Automatically save all edited files when triggering a build.',
      type: 'boolean',
      default: false
    },
    monocleHeight: {
      title: 'Monocle Height',
      description: 'How much of the workspace to use for build panel when it is "maximized".',
      type: 'number',
      default: 0.75,
      minimum: 0.1,
      maximum: 0.9
    },
    minimizedHeight: {
      title: 'Minimized Height',
      description: 'How much of the workspace to use for build panel when it is "minimized".',
      type: 'number',
      default: 0.15,
      minimum: 0.1,
      maximum: 0.9
    }
  },

  activate: function(state) {
    // Manually append /usr/local/bin as it may not be set on some systems,
    // and it's common to have node installed here. Keep it at end so it won't
    // accidentially override any other node installation
    process.env.PATH += ':/usr/local/bin';

    var self = this;
    this.buildView = new BuildView();
    this.cmd = {};
    this.stdout = new Buffer(0);
    this.stderr = new Buffer(0);
    atom.commands.add('atom-workspace', 'build:trigger', this.build.bind(this));
    atom.commands.add('atom-workspace', 'build:error-match', this.errorMatch.bind(this));
    atom.commands.add('atom-workspace', 'build:stop', this.stop.bind(this));
    atom.commands.add('atom-workspace', 'build:confirm', function() {
      document.activeElement.click();
    });
    atom.commands.add('atom-workspace', 'build:no-confirm', function() {
      self.saveConfirmView.cancel();
    });

    atom.workspace.observeTextEditors(function(editor) {
      editor.onDidSave(function(event) {
        if (atom.config.get('build.buildOnSave')) {
          var workspaceElement = atom.views.getView(atom.workspace);
          atom.commands.dispatch(workspaceElement, 'build:trigger');
        }
      });
    });
  },

  deactivate: function() {
    if (this.child) {
      this.child.kill('SIGKILL');
    }
    clearTimeout(this.finishedTimer);
  },

  buildCommand: function() {
    var build, exec, env, args, cwd, sh, errorMatch;
    var root = atom.project.getPaths()[0];
    if (fs.existsSync(root + '/.atom-build.json')) {
      var realAtomBuild = fs.realpathSync(root + '/.atom-build.json');
      delete require.cache[realAtomBuild];
      build = require(realAtomBuild);
      exec = build.cmd;
      env = build.env;
      args = build.args;
      cwd = build.cwd;
      sh = build.sh;
      errorMatch = build.errorMatch;
    }

    if (!exec && fs.existsSync(root + '/package.json')) {
      var realPackage = fs.realpathSync(root + '/package.json');
      delete require.cache[realPackage];
      var pkg = require(realPackage);

      if (pkg.engines && pkg.engines.atom) {
        exec = 'apm';
      }
      if (pkg.engines && pkg.engines.node) {
        exec = 'npm';
      }
      if (pkg.engines && exec) {
        args = [ '--color=always', 'install' ];
      }
    }

    if (!exec && fs.existsSync(root + '/Gruntfile.js')) {
      if (fs.existsSync(root + '/node_modules/.bin/grunt')) {
        // if grunt is installed locally, prefer this
        exec = root + '/node_modules/.bin/grunt';
      } else {
        // else use global installation
        exec = 'grunt';
      }
    }

    if (!exec && fs.existsSync(root + '/gulpfile.js')) {
      if (fs.existsSync(root + '/node_modules/.bin/gulp')) {
        // if gulp is installed locally, prefer this
        exec = root + '/node_modules/.bin/gulp';
      } else {
        // else use global installation
        exec = 'gulp';
      }
    }

    if (!exec && fs.existsSync(root + '/mix.exs')) {
      exec = 'mix';
      args = [ 'compile' ];
    }

    if (!exec && fs.existsSync(root + '/Makefile')) {
      exec = 'make';
      args = [];
    }

    return {
      exec: exec,
      env: env || {},
      args: args || [],
      cwd: cwd || root,
      sh: (undefined === sh) ? true : sh,
      errorMatch: errorMatch || ''
    };
  },

  replace: function(value) {
    var editor = atom.workspace.getActiveTextEditor();
    if (editor && 'untitled' !== editor.getTitle()) {
      var activeFile = fs.realpathSync(editor.getPath());
      value = value.replace('{FILE_ACTIVE}', activeFile);
      value = value.replace('{FILE_ACTIVE_PATH}', path.dirname(activeFile));
      value = value.replace('{FILE_ACTIVE_NAME}', path.basename(activeFile));
      value = value.replace('{FILE_ACTIVE_NAME_BASE}', path.basename(activeFile, path.extname(activeFile)));<commit_msg>Add support for building Rust projects with Cargo<commit_after>'use strict';

var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var XRegExp = require('xregexp').XRegExp;

var SaveConfirmView = require('./save-confirm-view');
var BuildView = require('./build-view');

module.exports = {
  config: {
    keepVisible: {
      title: 'Keep Visisble',
      description: 'If the build panel should be kept visible at all times.',
      type: 'boolean',
      default: false
    },
    buildOnSave: {
      title: 'Automatically build on save',
      description: 'Autmatically build your project each time an editor is saved.',
      type: 'boolean',
      default: false
    },
    saveOnBuild: {
      title: 'Automatically save on build',
      description: 'Automatically save all edited files when triggering a build.',
      type: 'boolean',
      default: false
    },
    monocleHeight: {
      title: 'Monocle Height',
      description: 'How much of the workspace to use for build panel when it is "maximized".',
      type: 'number',
      default: 0.75,
      minimum: 0.1,
      maximum: 0.9
    },
    minimizedHeight: {
      title: 'Minimized Height',
      description: 'How much of the workspace to use for build panel when it is "minimized".',
      type: 'number',
      default: 0.15,
      minimum: 0.1,
      maximum: 0.9
    }
  },

  activate: function(state) {
    // Manually append /usr/local/bin as it may not be set on some systems,
    // and it's common to have node installed here. Keep it at end so it won't
    // accidentially override any other node installation
    process.env.PATH += ':/usr/local/bin';

    var self = this;
    this.buildView = new BuildView();
    this.cmd = {};
    this.stdout = new Buffer(0);
    this.stderr = new Buffer(0);
    atom.commands.add('atom-workspace', 'build:trigger', this.build.bind(this));
    atom.commands.add('atom-workspace', 'build:error-match', this.errorMatch.bind(this));
    atom.commands.add('atom-workspace', 'build:stop', this.stop.bind(this));
    atom.commands.add('atom-workspace', 'build:confirm', function() {
      document.activeElement.click();
    });
    atom.commands.add('atom-workspace', 'build:no-confirm', function() {
      self.saveConfirmView.cancel();
    });

    atom.workspace.observeTextEditors(function(editor) {
      editor.onDidSave(function(event) {
        if (atom.config.get('build.buildOnSave')) {
          var workspaceElement = atom.views.getView(atom.workspace);
          atom.commands.dispatch(workspaceElement, 'build:trigger');
        }
      });
    });
  },

  deactivate: function() {
    if (this.child) {
      this.child.kill('SIGKILL');
    }
    clearTimeout(this.finishedTimer);
  },

  buildCommand: function() {
    var build, exec, env, args, cwd, sh, errorMatch;
    var root = atom.project.getPaths()[0];
    if (fs.existsSync(root + '/.atom-build.json')) {
      var realAtomBuild = fs.realpathSync(root + '/.atom-build.json');
      delete require.cache[realAtomBuild];
      build = require(realAtomBuild);
      exec = build.cmd;
      env = build.env;
      args = build.args;
      cwd = build.cwd;
      sh = build.sh;
      errorMatch = build.errorMatch;
    }

    if (!exec && fs.existsSync(root + '/package.json')) {
      var realPackage = fs.realpathSync(root + '/package.json');
      delete require.cache[realPackage];
      var pkg = require(realPackage);

      if (pkg.engines && pkg.engines.atom) {
        exec = 'apm';
      }
      if (pkg.engines && pkg.engines.node) {
        exec = 'npm';
      }
      if (pkg.engines && exec) {
        args = [ '--color=always', 'install' ];
      }
    }

    if (!exec && fs.existsSync(root + '/Gruntfile.js')) {
      if (fs.existsSync(root + '/node_modules/.bin/grunt')) {
        // if grunt is installed locally, prefer this
        exec = root + '/node_modules/.bin/grunt';
      } else {
        // else use global installation
        exec = 'grunt';
      }
    }

    if (!exec && fs.existsSync(root + '/gulpfile.js')) {
      if (fs.existsSync(root + '/node_modules/.bin/gulp')) {
        // if gulp is installed locally, prefer this
        exec = root + '/node_modules/.bin/gulp';
      } else {
        // else use global installation
        exec = 'gulp';
      }
    }

    if (!exec && fs.existsSync(root + '/mix.exs')) {
      exec = 'mix';
      args = [ 'compile' ];
    }

    if (!exec && fs.existsSync(root + '/Cargo.toml')) {
      exec = 'cargo';
      args = [ 'build' ];
    }

    if (!exec && fs.existsSync(root + '/Makefile')) {
      exec = 'make';
      args = [];
    }

    return {
      exec: exec,
      env: env || {},
      args: args || [],
      cwd: cwd || root,
      sh: (undefined === sh) ? true : sh,
      errorMatch: errorMatch || ''
    };
  },

  replace: function(value) {
    var editor = atom.workspace.getActiveTextEditor();
    if (editor && 'untitled' !== editor.getTitle()) {
      var activeFile = fs.realpathSync(editor.getPath());
      value = value.replace('{FILE_ACTIVE}', activeFile);
      value = value.replace('{FILE_ACTIVE_PATH}', path.dirname(activeFile));
      value = value.replace('{FILE_ACTIVE_NAME}', path.basename(activeFile));
      value = value.replace('{FILE_ACTIVE_NAME_BASE}', path.basename(activeFile, path.extname(activeFile)));
{'fraction_non_alphanumeric': 0.1527686377738084, 'fraction_numerical': 0.0031963899595750683, 'mean_word_length': 2.5650134048257374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6760242', 'n_tokens_mistral': 3332, 'n_tokens_neox': 3281, 'n_words': 796}