<commit_before>'use babel'

import * as util from './util'

/* A Suggestionprovider for Atom's autocompelte+;
  See also: https://github.com/atom/autocomplete-plus/wiki/Provider-API
*/
export default {
  setClient(client) {
    this.client = client
    console.log("setting client in provider")
  },

  //scope for suggestions; taken from language-modelica package
  selector: '.source.modelica',
  //don't activate in comment sections
  disableForSelector: '.comment',
  getSuggestions(options) {
    const {editor, bufferPosition, scopeDescriptor, prefix} = options
    const self = this
    const word = prefix
    return new Promise(resolve => {
      if(self.client === undefined) {
        //client not connected; do nothing
        resolve([])
      } else {
        //ask server for suggestions
        const position = new util.FilePosition(bufferPosition.row, bufferPosition.column)
        const filepath = editor.getPath()
        self.client.codeCompletion(filepath, position, prefix, (data) => {
          //map to autocomplete+ "suggestion-object"
          const suggestions = data.map(x => {
            const suggestion = {
              text: x.name,
              snippet: x.name,
              type: x.completionType.toLowerCase()
            }
            return suggestion
          })
          resolve(suggestions)
        }, (xhr, status, error) => {
          atom.notifications.addError(xhr.responseText)
          this.statusView.error("server-error")
          resolve([])
        })
      }
    })
  }
}<commit_msg>Update providing of suggestions<commit_after>'use babel'

import * as util from './util'

/* A Suggestionprovider for Atom's autocompelte+;
  See also: https://github.com/atom/autocomplete-plus/wiki/Provider-API
*/
export default {
  setClient(client) {
    this.client = client
    console.log("setting client in provider")
  },

  //scope for suggestions; taken from language-modelica package
  selector: '.source.modelica',
  //don't activate in comment sections
  disableForSelector: '.comment',
  getSuggestions(options) {
    const {editor, bufferPosition, scopeDescriptor, prefix} = options
    const self = this
    const word = util.wordBelowCursor()
    return new Promise(resolve => {
      if(self.client === undefined) {
        //client not connected; do nothing
        resolve([])
      } else {
        //ask server for suggestions
        const position = new util.FilePosition(bufferPosition.row, bufferPosition.column)
        const filepath = editor.getPath()
        self.client.codeCompletion(filepath, position, word, (data) => {
          //map to autocomplete+ "suggestion-object"
          const suggestions = data.map(x => self.createSuggestion(prefix, x))
          resolve(suggestions)
        }, (xhr, status, error) => {
          atom.notifications.addError(xhr.responseText)
          this.statusView.error("server-error")
          resolve([])
        })
      }
    })
  },

  createSuggestion(prefix, dataObj) {
    const text =
      (prefix === '.') ?
      dataObj.name.substring(dataObj.name.lastIndexOf('.')+1) :
      dataObj.name
    console.log("text", text)
    return {
      text: text,
      type: this.getType(dataObj.completionType.toLowerCase())
    };
  },

  getType(completionType) {
    if(completionType == 'model')
      return 'class'
    else if(completionType == 'package')
      return 'import'
    else
      return completionType
  }
}
{'fraction_non_alphanumeric': 0.11988388969521045, 'fraction_numerical': 0.00029027576197387516, 'mean_word_length': 2.545267489711934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2236256', 'n_tokens_mistral': 977, 'n_tokens_neox': 955, 'n_words': 232}