<commit_before>fs = require 'fs'
path = require 'path'

module.exports =
class Helper

  projectRoot: null
  manager: null
  checkpointsDefinition: []

  constructor: (manager) ->
    @manager = manager

  updateTernFile: (content) ->
    @projectRoot = @manager.server?.rootPath
    return unless @projectRoot
    @writeFile(path.resolve(__dirname, @projectRoot + '/.tern-project'), content)

  fileExists: (path) ->
    try fs.accessSync path, fs.F_OK, (err) =>
      console.log err
    catch e then return false

  writeFile: (filePath, content) ->
    fs.writeFile filePath, content, (err) =>
      atom.workspace.open(filePath)
      return unless err
      message = 'Could not create/update .tern-project file. Use the README to manually create a .tern-project file.'
      atom.notifications.addInfo(message, dismissable: true)

  readFile: (path) ->
    fs.readFileSync path, 'utf8'

  getFileContent: (filePath, projectRoot) ->
    @projectRoot = @manager.server?.rootPath
    return false unless @projectRoot
    if projectRoot
      filePath = @projectRoot + filePath
    resolvedPath = path.resolve(__dirname, filePath)
    return false unless @fileExists(resolvedPath) is undefined
    @readFile(resolvedPath)

  markerCheckpointBack: ->
    return unless @checkpointsDefinition.length
    checkpoint = @checkpointsDefinition.pop()
    @openFileAndGoToPosition(checkpoint.marker.range.start, checkpoint.editor.getURI())

  setMarkerCheckpoint: ->
    editor = atom.workspace.getActiveTextEditor()
    buffer = editor.getBuffer()
    cursor = editor.getLastCursor()
    return unless cursor
    marker = buffer.markPosition(cursor.getBufferPosition(), {})
    @checkpointsDefinition.push
      marker: marker
      editor: editor<commit_msg>use getRange method to optain range. fixes #109<commit_after>fs = require 'fs'
path = require 'path'

module.exports =
class Helper

  projectRoot: null
  manager: null
  checkpointsDefinition: []

  constructor: (manager) ->
    @manager = manager

  updateTernFile: (content) ->
    @projectRoot = @manager.server?.rootPath
    return unless @projectRoot
    @writeFile(path.resolve(__dirname, @projectRoot + '/.tern-project'), content)

  fileExists: (path) ->
    try fs.accessSync path, fs.F_OK, (err) =>
      console.log err
    catch e then return false

  writeFile: (filePath, content) ->
    fs.writeFile filePath, content, (err) =>
      atom.workspace.open(filePath)
      return unless err
      message = 'Could not create/update .tern-project file. Use the README to manually create a .tern-project file.'
      atom.notifications.addInfo(message, dismissable: true)

  readFile: (path) ->
    fs.readFileSync path, 'utf8'

  getFileContent: (filePath, projectRoot) ->
    @projectRoot = @manager.server?.rootPath
    return false unless @projectRoot
    if projectRoot
      filePath = @projectRoot + filePath
    resolvedPath = path.resolve(__dirname, filePath)
    return false unless @fileExists(resolvedPath) is undefined
    @readFile(resolvedPath)

  markerCheckpointBack: ->
    return unless @checkpointsDefinition.length
    checkpoint = @checkpointsDefinition.pop()
    @openFileAndGoToPosition(checkpoint.marker.getRange().start, checkpoint.editor.getURI())

  setMarkerCheckpoint: ->
    editor = atom.workspace.getActiveTextEditor()
    buffer = editor.getBuffer()
    cursor = editor.getLastCursor()
    return unless cursor
    marker = buffer.markPosition(cursor.getBufferPosition(), {})
    @checkpointsDefinition.push
      marker: marker
      editor: editor
{'fraction_non_alphanumeric': 0.10481825866441251, 'fraction_numerical': 0.0014088475626937165, 'mean_word_length': 3.7019867549668874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '2463245', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1006, 'n_words': 258}