<commit_before>_ = require 'underscore-plus'
ProviderBase = require './provider-base'
{requireFrom} = require '../utils'
{Point} = require 'atom'
path = require 'path'

TagReader = requireFrom('symbols-view', 'tag-reader')
SymbolsView = requireFrom('symbols-view', 'symbols-view')
getTagLine = SymbolsView::getTagLine

module.exports =
class ProjectSymbols extends ProviderBase
  includeHeaderGrammar: true
  showLineHeader: true
  supportCacheItems: true # manage manually
  items: null

  @cache: null

  itemForTag: (tag) ->
    {directory, file, lineNumber, name} = tag
    point = getTagLine(tag)
    if point?
      {
        point: point
        filePath: path.join(directory, file)
        text: name
      }

  stop: ->
    @loadTagsTask?.terminate()

  start: ->
    @stop()

    new Promise (resolve) =>
      if @cache?
        resolve(@cache)

      @loadTagsTask = TagReader.getAllTags (tags) =>
        items = tags
          .map(@itemForTag)
          .filter (item) -> item?
          .sort (a, b) -> a.point.compare(b.point)
        @cache = @getItemsWithHeaders(items)
        resolve(@cache)

  getItems: ->
    @start()

  filterItems: (items, filterSpec) ->
    @getItemsWithoutUnusedHeader(super)<commit_msg>limit interest, unique duplicate items, cache globally<commit_after>_ = require 'underscore-plus'
ProviderBase = require './provider-base'
{requireFrom} = require '../utils'
{Point} = require 'atom'
path = require 'path'

TagReader = requireFrom('symbols-view', 'tag-reader')
SymbolsView = requireFrom('symbols-view', 'symbols-view')
getTagLine = SymbolsView::getTagLine

module.exports =
class ProjectSymbols extends ProviderBase
  includeHeaderGrammar: true
  showLineHeader: true
  supportCacheItems: true # manage manually
  items: null

  @cache: null

  itemForTag: (tag) ->
    {directory, file, lineNumber, name} = tag
    point = getTagLine(tag)
    if point?
      {
        point: point
        filePath: path.join(directory, file)
        text: name
      }

  stop: ->
    @loadTagsTask?.terminate()

  cacheItems: (items) ->
    @constructor.cachedItems = items

  getCachedItems: ->
    @constructor.cachedItems

  start: ->
    @stop()

    # excludeKinds = ['v']
    kindOfInterests = 'cfm'

    new Promise (resolve) =>
      cache = @getCachedItems()
      if cache?
        return resolve(cache)

      @loadTagsTask = TagReader.getAllTags (tags) =>
        items = tags
          .filter (tag) -> tag.kind in kindOfInterests
          .map(@itemForTag)
          .filter (item) -> item?
          .sort (a, b) -> a.point.compare(b.point)
        items = _.uniq items, (item) -> item.filePath + item.text
        items = @getItemsWithHeaders(items)
        @cacheItems(items)
        resolve(items)

  getItems: ->
    @start()

  filterItems: (items, filterSpec) ->
    @getItemsWithoutUnusedHeader(super)
{'fraction_non_alphanumeric': 0.1270118964310707, 'fraction_numerical': 0.0, 'mean_word_length': 2.8687415426251692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3728412', 'n_tokens_mistral': 902, 'n_tokens_neox': 877, 'n_words': 210}