dapetcu21 / atom-autocomplete-lua

Extensible autocomplete+ provider for Lua
35 stars 6 forks source link

problem loading .luacompleterc #10

Closed THE-FYP closed 7 years ago

THE-FYP commented 7 years ago

trying to implement .luacompleterc in my package i ran into a problem with loading the file. after some research i found out that autocomplete-lua tries to load file from the wrong directory C:\Users\root\.luacompleterc instead of C:\Users\root\.atom\dev\packages\mypackage\.luacompleterc, i guess it is likely a bug.

Windows 10 Atom v1.14.2

dapetcu21 commented 7 years ago

The .luacompleterc file is loaded relative to the file being edited. If you're developing a package providing autocomplete, you shouldn't use a .luacompleterc file directly. That is intended for the end user to customize his setup. Instead, you should use the option provider mechanism to load your custom options. Something like this:

getLoadedOptions = async (utils) => {
  if (this.loadedOptions) { return this.loadedOptions }
  let options = await loadMyOptionsFromAFileSomewhereOrJustRequireThemAsJSON()
  options = utils.reviveOptions(options)
  this.loadedOptions = options
  return options
}

getOptions = async (request, getPreviousOptions, utils, cache) => {
  if (providerIsNotApplicableToTheCurrentFile) {
    return { options: await getPreviousOptions() }
  }
  const newOptions = this.getLoadedOptions(utils)
  const previousOptions = await getPreviousOptions()
  return utils.mergeOptionsCached(previousOptions, newOptions, cache)
}

Read more about option providers here: https://github.com/dapetcu21/atom-autocomplete-lua#option-providers

THE-FYP commented 7 years ago

oh, okay. thank you.