editorUrl.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. export default function editorUrl(config, file, lineNumber) {
  2. const editor = config.editor;
  3. const editors = {
  4. sublime: 'subl://open?url=file://%path&line=%line',
  5. textmate: 'txmt://open?url=file://%path&line=%line',
  6. emacs: 'emacs://open?url=file://%path&line=%line',
  7. macvim: 'mvim://open/?url=file://%path&line=%line',
  8. phpstorm: 'phpstorm://open?file=%path&line=%line',
  9. idea: 'idea://open?file=%path&line=%line',
  10. vscode: 'vscode://file/%path:%line',
  11. 'vscode-insiders': 'vscode-insiders://file/%path:%line',
  12. 'vscode-remote': 'vscode://vscode-remote/%path:%line',
  13. 'vscode-insiders-remote': 'vscode-insiders://vscode-remote/%path:%line',
  14. vscodium: 'vscodium://file/%path:%line',
  15. atom: 'atom://core/open/file?filename=%path&line=%line',
  16. nova: 'nova://core/open/file?filename=%path&line=%line',
  17. netbeans: 'netbeans://open/?f=%path:%line',
  18. xdebug: 'xdebug://%path@%line',
  19. };
  20. file =
  21. (config.remoteSitesPath || false).length > 0 && (config.localSitesPath || false).length > 0
  22. ? file.replace(config.remoteSitesPath, config.localSitesPath)
  23. : file;
  24. if (!Object.keys(editors).includes(editor)) {
  25. console.error(
  26. `'${editor}' is not supported. Support editors are: ${Object.keys(editors).join(', ')}`,
  27. );
  28. return null;
  29. }
  30. return editors[editor]
  31. .replace('%path', encodeURIComponent(file))
  32. .replace('%line', encodeURIComponent(lineNumber));
  33. }