 _ = require 'underscore-plus'
 
 hasCommonJSPackageSemantics = (scopeName, filePath) ->
+  # why use `startsWith` is to make `source.js.jsx` true.
   fs.isDirectorySync(filePath) and (scopeName.startsWith('source.js') or scopeName.startsWith('source.coffee'))
 
 getBaseName = (file) ->

  #  - File have same basename
  detectFilePath: (filePath) ->
    # Search existing file from file list.
    if file = _.detect(@getFiles(filePath), (f) -> fs.isFileSync(f))
      return file

    # Search file have same basename.
    baseName = getBaseName(filePath)
    _.detect fs.listSync(path.dirname(filePath)), (f) ->
      (getBaseName(f) is baseName) and fs.isFileSync(f)

  getFilePath: (editor, fileName) ->

    {scopeName} = editor.getGrammar()
    filePath = path.resolve(dirName, fileName)
    if hasCommonJSPackageSemantics scopeName, filePath
      extensions = ['.js', '.coffee', '.jsx']
      indexFilePath = extensions
        .map (ext) -> path.join(filePath, "index#{ext}")
        .find (indexFilePath) -> fs.isFileSync(indexFilePath)
      return indexFilePath if indexFilePath

    if filePath = @detectFilePath(path.resolve(dirName, fileName))
      return filePath
