get-args.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const path = require('path')
  2. // normalize file/line numbers into command line args for specific editors
  3. module.exports = function getArgumentsForPosition (
  4. editor,
  5. fileName,
  6. lineNumber,
  7. columnNumber = 1
  8. ) {
  9. const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '')
  10. switch (editorBasename) {
  11. case 'atom':
  12. case 'Atom':
  13. case 'Atom Beta':
  14. case 'subl':
  15. case 'sublime':
  16. case 'sublime_text':
  17. case 'wstorm':
  18. case 'charm':
  19. return [`${fileName}:${lineNumber}:${columnNumber}`]
  20. case 'notepad++':
  21. return ['-n' + lineNumber, fileName]
  22. case 'vim':
  23. case 'mvim':
  24. return [`+call cursor(${lineNumber}, ${columnNumber})`, fileName]
  25. case 'joe':
  26. return ['+' + `${lineNumber}`, fileName]
  27. case 'emacs':
  28. case 'emacsclient':
  29. return [`+${lineNumber}:${columnNumber}`, fileName]
  30. case 'rmate':
  31. case 'mate':
  32. case 'mine':
  33. return ['--line', lineNumber, fileName]
  34. case 'code':
  35. case 'code-insiders':
  36. case 'Code':
  37. return ['-r', '-g', `${fileName}:${lineNumber}:${columnNumber}`]
  38. case 'appcode':
  39. case 'clion':
  40. case 'clion64':
  41. case 'idea':
  42. case 'idea64':
  43. case 'phpstorm':
  44. case 'phpstorm64':
  45. case 'pycharm':
  46. case 'pycharm64':
  47. case 'rubymine':
  48. case 'rubymine64':
  49. case 'webstorm':
  50. case 'webstorm64':
  51. return ['--line', lineNumber, fileName]
  52. }
  53. // For all others, drop the lineNumber until we have
  54. // a mapping above, since providing the lineNumber incorrectly
  55. // can result in errors or confusing behavior.
  56. return [fileName]
  57. }