get-args.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. case 'zed':
  20. return [`${fileName}:${lineNumber}:${columnNumber}`]
  21. case 'notepad++':
  22. return ['-n' + lineNumber, '-c' + columnNumber, fileName]
  23. case 'vim':
  24. case 'mvim':
  25. return [`+call cursor(${lineNumber}, ${columnNumber})`, fileName]
  26. case 'joe':
  27. case 'gvim':
  28. return ['+' + `${lineNumber}`, fileName]
  29. case 'emacs':
  30. case 'emacsclient':
  31. return [`+${lineNumber}:${columnNumber}`, fileName]
  32. case 'rmate':
  33. case 'mate':
  34. case 'mine':
  35. return ['--line', lineNumber, fileName]
  36. case 'code':
  37. case 'Code':
  38. case 'code-insiders':
  39. case 'Code - Insiders':
  40. case 'codium':
  41. case 'cursor':
  42. case 'vscodium':
  43. case 'VSCodium':
  44. return ['-r', '-g', `${fileName}:${lineNumber}:${columnNumber}`]
  45. case 'appcode':
  46. case 'clion':
  47. case 'clion64':
  48. case 'idea':
  49. case 'idea64':
  50. case 'phpstorm':
  51. case 'phpstorm64':
  52. case 'pycharm':
  53. case 'pycharm64':
  54. case 'rubymine':
  55. case 'rubymine64':
  56. case 'webstorm':
  57. case 'webstorm64':
  58. case 'goland':
  59. case 'goland64':
  60. case 'rider':
  61. case 'rider64':
  62. return ['--line', lineNumber, '--column', columnNumber, fileName]
  63. }
  64. if (process.env.LAUNCH_EDITOR) {
  65. return [fileName, lineNumber, columnNumber]
  66. }
  67. // For all others, drop the lineNumber until we have
  68. // a mapping above, since providing the lineNumber incorrectly
  69. // can result in errors or confusing behavior.
  70. return [fileName]
  71. }