Esempio n. 1
0
  // Refreshes the current git status in an outside process and asynchronously
  // updates the relevant properties.
  async refreshStatus () {
    const statusRefreshCount = ++this.statusRefreshCount
    const repo = this.getRepo()

    const relativeProjectPaths = this.project && this.project.getPaths()
      .map(projectPath => this.relativize(projectPath))
      .filter(projectPath => (projectPath.length > 0) && !path.isAbsolute(projectPath))

    const branch = await repo.getHeadAsync()
    const upstream = await repo.getAheadBehindCountAsync()

    const statuses = {}
    const repoStatus = relativeProjectPaths.length > 0
      ? await repo.getStatusAsync(relativeProjectPaths)
      : await repo.getStatusAsync()
    for (let filePath in repoStatus) {
      statuses[filePath] = repoStatus[filePath]
    }

    const submodules = {}
    for (let submodulePath in repo.submodules) {
      const submoduleRepo = repo.submodules[submodulePath]
      submodules[submodulePath] = {
        branch: await submoduleRepo.getHeadAsync(),
        upstream: await submoduleRepo.getAheadBehindCountAsync()
      }

      const workingDirectoryPath = submoduleRepo.getWorkingDirectory()
      const submoduleStatus = await submoduleRepo.getStatusAsync()
      for (let filePath in submoduleStatus) {
        const absolutePath = path.join(workingDirectoryPath, filePath)
        const relativizePath = repo.relativize(absolutePath)
        statuses[relativizePath] = submoduleStatus[filePath]
      }
    }

    if (this.statusRefreshCount !== statusRefreshCount || this.isDestroyed()) return

    const statusesUnchanged =
      _.isEqual(branch, this.branch) &&
      _.isEqual(statuses, this.statuses) &&
      _.isEqual(upstream, this.upstream) &&
      _.isEqual(submodules, this.submodules)

    this.branch = branch
    this.statuses = statuses
    this.upstream = upstream
    this.submodules = submodules

    for (let submodulePath in repo.submodules) {
      repo.submodules[submodulePath].upstream = submodules[submodulePath].upstream
    }

    if (!statusesUnchanged) this.emitter.emit('did-change-statuses')
  }
Esempio n. 2
0
  getGrammarPathScore (grammar, filePath) {
    if (!filePath) return -1
    if (process.platform === 'win32') { filePath = filePath.replace(/\\/g, '/') }

    const pathComponents = filePath.toLowerCase().split(PATH_SPLIT_REGEX)
    let pathScore = 0

    let customFileTypes
    if (this.config.get('core.customFileTypes')) {
      customFileTypes = this.config.get('core.customFileTypes')[grammar.scopeName]
    }

    let { fileTypes } = grammar
    if (customFileTypes) {
      fileTypes = fileTypes.concat(customFileTypes)
    }

    for (let i = 0; i < fileTypes.length; i++) {
      const fileType = fileTypes[i]
      const fileTypeComponents = fileType.toLowerCase().split(PATH_SPLIT_REGEX)
      const pathSuffix = pathComponents.slice(-fileTypeComponents.length)
      if (_.isEqual(pathSuffix, fileTypeComponents)) {
        pathScore = Math.max(pathScore, fileType.length)
        if (i >= grammar.fileTypes.length) {
          pathScore += 0.5
        }
      }
    }

    return pathScore
  }
Esempio n. 3
0
 return this.emitter.on('did-change', () => {
   const newValue = this.get(keyPath, {scope})
   if (!_.isEqual(oldValue, newValue)) {
     const event = {oldValue, newValue}
     oldValue = newValue
     callback(event)
   }
 })
Esempio n. 4
0
  sendUpdate(project) {
    for (let key in this.updaters) {
      const {id, query, callback} = this.updaters[key];

      if (Object.keys(query).length === 0) {
        callback(project);
      } else if (id === project._id ||
        _.isEqual(project[query.key], query.value)) {
        callback(project);
      }
    }
  }
Esempio n. 5
0
        providerManager.all({excludeCurrent: false}).then((projects) => {
          this.projects = util.sortProjects(projects)

          // We are currently at what ..
          const currentPaths = atom.project.getPaths()
          let currentIndex = -1
          for (let index = 0; index < projects.length; ++index) {
            if (_.isEqual(projects[index].paths, currentPaths)) {
              currentIndex = index
              break
            }
          }

          this.index = currentIndex
          resolve()
        })
Esempio n. 6
0
 setRawValue (keyPath, value) {
   const defaultValue = getValueAtKeyPath(this.defaultSettings, keyPath)
   if (_.isEqual(defaultValue, value)) {
     if (keyPath != null) {
       deleteValueAtKeyPath(this.settings, keyPath)
     } else {
       this.settings = null
     }
   } else {
     if (keyPath != null) {
       setValueAtKeyPath(this.settings, keyPath, value)
     } else {
       this.settings = value
     }
   }
   return this.emitChangeEvent()
 }
Esempio n. 7
0
  setRawValue (keyPath, value, options = {}) {
    const source = options.source ? options.source : undefined
    const settingsToChange = source === this.projectFile ? 'projectSettings' : 'settings'
    const defaultValue = getValueAtKeyPath(this.defaultSettings, keyPath)

    if (_.isEqual(defaultValue, value)) {
      if (keyPath != null) {
        deleteValueAtKeyPath(this[settingsToChange], keyPath)
      } else {
        this[settingsToChange] = null
      }
    } else {
      if (keyPath != null) {
        setValueAtKeyPath(this[settingsToChange], keyPath, value)
      } else {
        this[settingsToChange] = value
      }
    }
    return this.emitChangeEvent()
  }
Esempio n. 8
0
  tokenizeNextChunk () {
    let rowsRemaining = this.chunkSize

    while (this.firstInvalidRow() != null && rowsRemaining > 0) {
      var endRow, filledRegion
      const startRow = this.invalidRows.shift()
      const lastRow = this.buffer.getLastRow()
      if (startRow > lastRow) continue

      let row = startRow
      while (true) {
        const previousStack = this.stackForRow(row)
        this.tokenizedLines[row] = this.buildTokenizedLineForRow(row, this.stackForRow(row - 1), this.openScopesForRow(row))
        if (--rowsRemaining === 0) {
          filledRegion = false
          endRow = row
          break
        }
        if (row === lastRow || _.isEqual(this.stackForRow(row), previousStack)) {
          filledRegion = true
          endRow = row
          break
        }
        row++
      }

      this.validateRow(endRow)
      if (!filledRegion) this.invalidateRow(endRow + 1)

      this.emitter.emit('did-invalidate-range', Range(Point(startRow, 0), Point(endRow + 1, 0)))
    }

    if (this.firstInvalidRow() != null) {
      this.tokenizeInBackground()
    } else {
      this.markTokenizationComplete()
    }
  }
Esempio n. 9
0
  bufferDidChange (e) {
    this.changeCount = this.buffer.changeCount

    const {oldRange, newRange} = e
    const start = oldRange.start.row
    const end = oldRange.end.row
    const delta = newRange.end.row - oldRange.end.row
    const oldLineCount = (oldRange.end.row - oldRange.start.row) + 1
    const newLineCount = (newRange.end.row - newRange.start.row) + 1

    this.updateInvalidRows(start, end, delta)
    const previousEndStack = this.stackForRow(end) // used in spill detection below
    if (this.largeFileMode || (this.grammar.name === 'Null Grammar')) {
      _.spliceWithArray(this.tokenizedLines, start, oldLineCount, new Array(newLineCount))
    } else {
      const newTokenizedLines = this.buildTokenizedLinesForRows(start, end + delta, this.stackForRow(start - 1), this.openScopesForRow(start))
      _.spliceWithArray(this.tokenizedLines, start, oldLineCount, newTokenizedLines)
      const newEndStack = this.stackForRow(end + delta)
      if (newEndStack && !_.isEqual(newEndStack, previousEndStack)) {
        this.invalidateRow(end + delta + 1)
      }
    }
  }
Esempio n. 10
0
  updateEditorSettingsForLanguageMode (editor, oldLanguageMode) {
    const newLanguageMode = editor.buffer.getLanguageMode()

    if (oldLanguageMode) {
      const newSettings = this.textEditorParamsForScope(newLanguageMode.rootScopeDescriptor)
      const oldSettings = this.textEditorParamsForScope(oldLanguageMode.rootScopeDescriptor)

      const updatedSettings = {}
      for (const [, paramName] of EDITOR_PARAMS_BY_SETTING_KEY) {
        // Update the setting only if it has changed between the two language
        // modes.  This prevents user-modified settings in an editor (like
        // 'softWrapped') from being reset when the language mode changes.
        if (!_.isEqual(newSettings[paramName], oldSettings[paramName])) {
          updatedSettings[paramName] = newSettings[paramName]
        }
      }

      if (_.size(updatedSettings) > 0) {
        editor.update(updatedSettings)
      }
    } else {
      editor.update(this.textEditorParamsForScope(newLanguageMode.rootScopeDescriptor))
    }
  }
Esempio n. 11
0
 isEqual(other) {
   return _.isEqual(this.state, other.state)
 }
Esempio n. 12
0
 isSubKeyPath (keyPath, subKeyPath) {
   if ((keyPath == null) || (subKeyPath == null)) { return false }
   const pathSubTokens = splitKeyPath(subKeyPath)
   const pathTokens = splitKeyPath(keyPath).slice(0, pathSubTokens.length)
   return _.isEqual(pathTokens, pathSubTokens)
 }
Esempio n. 13
0
    },

    validateEnum (keyPath, value, schema) {
      let possibleValues = schema.enum

      if (Array.isArray(possibleValues)) {
        possibleValues = possibleValues.map(value => {
          if (value.hasOwnProperty('value')) { return value.value } else { return value }
        })
      }

      if ((possibleValues == null) || !Array.isArray(possibleValues) || !possibleValues.length) { return value }

      for (let possibleValue of possibleValues) {
        // Using `isEqual` for possibility of placing enums on array and object schemas
        if (_.isEqual(possibleValue, value)) { return value }
      }

      throw new Error(`Validation failed at ${keyPath}, ${JSON.stringify(value)} is not one of ${JSON.stringify(possibleValues)}`)
    }
  }
})

let isPlainObject = value => _.isObject(value) && !Array.isArray(value) && !_.isFunction(value) && !_.isString(value) && !(value instanceof Color)

let sortObject = value => {
  if (!isPlainObject(value)) { return value }
  const result = {}
  for (let key of Object.keys(value).sort()) {
    result[key] = sortObject(value[key])
  }
Esempio n. 14
0
 .then(([repositoryStatus, submoduleStatus]) => {
   const statusesByPath = _.extend({}, repositoryStatus, submoduleStatus)
   const changed = !_.isEqual(this.pathStatusCache, statusesByPath)
   this.pathStatusCache = statusesByPath
   return changed
 })
Esempio n. 15
0
 .then(counts => {
   const changed = !_.isEqual(counts, this.upstream)
   this.upstream = counts
   return changed
 })