<commit_before>{Range, Point} = require "atom"
{filter, score} = require "fuzzaldrin"

# tags we are interested in are marked by the grammar
JSXSTARTTAGEND = 0
JSXENDTAGSTART = 1
JSXTAG = 2
JSXATTRIBUTE = 3
# regex to search for tag open/close tag and close tag
JSXREGEXP = /(?:(<)|(<\/))([$_A-Za-z](?:[$.\-A-Za-z0-9])*)|(?:(\/>)|(>))/g
TAGREGEXP =  /<([$_a-zA-Z][a-zA-Z0-9.-]*)(\s|\/>|>)/g
COMPLETIONS = require "./completions-jsx"
REACTURL = "http://facebook.github.io/react/docs/tags-and-attributes.html"

module.exports =
  selector: ".meta.tag.jsx"
  inclusionPriority: 10000
  excludeLowerPriority: false


  getSuggestions: (opts) ->
    {editor, bufferPosition, scopeDescriptor, prefix} = opts
    return if editor.getGrammar().packageName isnt "language-babel"

    jsxTag = @getTriggerTag editor, bufferPosition
    return if not jsxTag?

    # build autocomplete list
    suggestions = []

    if jsxTag is JSXSTARTTAGEND
      startOfJSX = @getStartOfJSX editor, bufferPosition
      jsxRange = new Range(startOfJSX, bufferPosition)
      tagNameStack = @buildTagStack(editor, jsxRange)
      while ( tagName = tagNameStack.pop())?
        suggestions.push
            snippet: "$1</#{tagName}>$2"
            type: "tag"
            description: "language-babel JSX supported elements"
            descriptionMoreURL: REACTURL

    else if  jsxTag is JSXENDTAGSTART
      startOfJSX = @getStartOfJSX editor, bufferPosition
      jsxRange = new Range(startOfJSX, bufferPosition)
      tagNameStack = @buildTagStack(editor, jsxRange)
      while ( tagName = tagNameStack.pop())?
        suggestions.push
            text: "#{tagName}>"
            type: "tag"
            description: "language-babel JSX supported elements"
            descriptionMoreURL: REACTURL

    else if jsxTag is JSXTAG
      return if not /^[a-z]/g.exec(prefix)
      htmlElements = filter(COMPLETIONS.htmlElements, prefix, {key: "name"})
      for htmlElement in htmlElements
        if score(htmlElement.name, prefix) < 0.07 then continue
        suggestions.push
          text: htmlElement.name
          type: "tag"
          description: "language-babel JSX supported elements"
          descriptionMoreURL: REACTURL

    else if jsxTag is JSXATTRIBUTE
      tagName = @getThisTagName editor, bufferPosition
      return if not tagName?
      for elementObj in COMPLETIONS.htmlElements
        if elementObj.name is tagName then break
      elementObj.attributes = elementObj.attributes.concat COMPLETIONS.globalAttributes
      elementObj.attributes = elementObj.attributes.concat COMPLETIONS.events
      filteredAttributes = filter(elementObj.attributes, prefix, {key: "name"})
      for attribute in filteredAttributes
        if score(attribute.name, prefix) < 0.07 then continue
        suggestions.push
          text: attribute.name
          type: "attribute"
          rightLabel: "<#{tagName}>"
          description: "language-babel JSXsupported attributes/events"
          descriptionMoreURL: REACTURL

    else return
    suggestions

  # get tagname for this attribute
  getThisTagName: ( editor, bufferPosition) ->
    row = bufferPosition.row
    column = null
    while row >= 0<commit_msg>Use sniippet rather than text in suggestions as these seem to have more weight.<commit_after>{Range, Point} = require "atom"
{filter, score} = require "fuzzaldrin"

# tags we are interested in are marked by the grammar
JSXSTARTTAGEND = 0
JSXENDTAGSTART = 1
JSXTAG = 2
JSXATTRIBUTE = 3
# regex to search for tag open/close tag and close tag
JSXREGEXP = /(?:(<)|(<\/))([$_A-Za-z](?:[$.\-A-Za-z0-9])*)|(?:(\/>)|(>))/g
TAGREGEXP =  /<([$_a-zA-Z][a-zA-Z0-9.-]*)(\s|\/>|>)/g
COMPLETIONS = require "./completions-jsx"
REACTURL = "http://facebook.github.io/react/docs/tags-and-attributes.html"

module.exports =
  selector: ".meta.tag.jsx"
  inclusionPriority: 10000
  excludeLowerPriority: false


  getSuggestions: (opts) ->
    {editor, bufferPosition, scopeDescriptor, prefix} = opts
    return if editor.getGrammar().packageName isnt "language-babel"

    jsxTag = @getTriggerTag editor, bufferPosition
    return if not jsxTag?

    # build autocomplete list
    suggestions = []

    if jsxTag is JSXSTARTTAGEND
      startOfJSX = @getStartOfJSX editor, bufferPosition
      jsxRange = new Range(startOfJSX, bufferPosition)
      tagNameStack = @buildTagStack(editor, jsxRange)
      while ( tagName = tagNameStack.pop())?
        suggestions.push
            snippet: "$1</#{tagName}>$2"
            type: "tag"
            description: "language-babel tag closer"

    else if  jsxTag is JSXENDTAGSTART
      startOfJSX = @getStartOfJSX editor, bufferPosition
      jsxRange = new Range(startOfJSX, bufferPosition)
      tagNameStack = @buildTagStack(editor, jsxRange)
      while ( tagName = tagNameStack.pop())?
        suggestions.push
            snippet: "#{tagName}>"
            type: "tag"
            description: "language-babel tag closer"

    else if jsxTag is JSXTAG
      return if not /^[a-z]/g.exec(prefix)
      htmlElements = filter(COMPLETIONS.htmlElements, prefix, {key: "name"})
      for htmlElement in htmlElements
        if score(htmlElement.name, prefix) < 0.07 then continue
        suggestions.push
          snippet: htmlElement.name
          type: "tag"
          description: "language-babel JSX supported elements"
          descriptionMoreURL: REACTURL

    else if jsxTag is JSXATTRIBUTE
      tagName = @getThisTagName editor, bufferPosition
      return if not tagName?
      for elementObj in COMPLETIONS.htmlElements
        if elementObj.name is tagName then break
      elementObj.attributes = elementObj.attributes.concat COMPLETIONS.globalAttributes
      elementObj.attributes = elementObj.attributes.concat COMPLETIONS.events
      filteredAttributes = filter(elementObj.attributes, prefix, {key: "name"})
      for attribute in filteredAttributes
        if score(attribute.name, prefix) < 0.07 then continue
        suggestions.push
          snippet: attribute.name
          type: "attribute"
          rightLabel: "<#{tagName}>"
          description: "language-babel JSXsupported attributes/events"
          descriptionMoreURL: REACTURL

    else return
    suggestions

  # get tagname for this attribute
  getThisTagName: ( editor, bufferPosition) ->
    row = bufferPosition.row
    column = null
    while row >= 0
{'fraction_non_alphanumeric': 0.10431372549019607, 'fraction_numerical': 0.0069019607843137255, 'mean_word_length': 2.9775421085464755, 'pattern_counts': {'":': 0, '<': 17, '<?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': '2855619', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1889, 'n_words': 502}