2023-12-18 13:12:25 +08:00
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
// normalize file/line numbers into command line args for specific editors
|
|
|
|
module.exports = function getArgumentsForPosition (
|
|
|
|
editor,
|
|
|
|
fileName,
|
|
|
|
lineNumber,
|
|
|
|
columnNumber = 1
|
|
|
|
) {
|
|
|
|
const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '')
|
|
|
|
switch (editorBasename) {
|
|
|
|
case 'atom':
|
|
|
|
case 'Atom':
|
|
|
|
case 'Atom Beta':
|
|
|
|
case 'subl':
|
|
|
|
case 'sublime':
|
|
|
|
case 'sublime_text':
|
|
|
|
case 'wstorm':
|
|
|
|
case 'charm':
|
|
|
|
return [`${fileName}:${lineNumber}:${columnNumber}`]
|
|
|
|
case 'notepad++':
|
2024-01-16 21:26:16 +08:00
|
|
|
return ['-n' + lineNumber, '-c' + columnNumber, fileName]
|
2023-12-18 13:12:25 +08:00
|
|
|
case 'vim':
|
|
|
|
case 'mvim':
|
|
|
|
return [`+call cursor(${lineNumber}, ${columnNumber})`, fileName]
|
|
|
|
case 'joe':
|
2024-01-16 21:26:16 +08:00
|
|
|
case 'gvim':
|
2023-12-18 13:12:25 +08:00
|
|
|
return ['+' + `${lineNumber}`, fileName]
|
|
|
|
case 'emacs':
|
|
|
|
case 'emacsclient':
|
|
|
|
return [`+${lineNumber}:${columnNumber}`, fileName]
|
|
|
|
case 'rmate':
|
|
|
|
case 'mate':
|
|
|
|
case 'mine':
|
|
|
|
return ['--line', lineNumber, fileName]
|
|
|
|
case 'code':
|
|
|
|
case 'Code':
|
2024-01-16 21:26:16 +08:00
|
|
|
case 'code-insiders':
|
|
|
|
case 'Code - Insiders':
|
|
|
|
case 'codium':
|
|
|
|
case 'vscodium':
|
|
|
|
case 'VSCodium':
|
2023-12-18 13:12:25 +08:00
|
|
|
return ['-r', '-g', `${fileName}:${lineNumber}:${columnNumber}`]
|
|
|
|
case 'appcode':
|
|
|
|
case 'clion':
|
|
|
|
case 'clion64':
|
|
|
|
case 'idea':
|
|
|
|
case 'idea64':
|
|
|
|
case 'phpstorm':
|
|
|
|
case 'phpstorm64':
|
|
|
|
case 'pycharm':
|
|
|
|
case 'pycharm64':
|
|
|
|
case 'rubymine':
|
|
|
|
case 'rubymine64':
|
|
|
|
case 'webstorm':
|
|
|
|
case 'webstorm64':
|
2024-01-16 21:26:16 +08:00
|
|
|
case 'goland':
|
|
|
|
case 'goland64':
|
|
|
|
case 'rider':
|
|
|
|
case 'rider64':
|
|
|
|
return ['--line', lineNumber, '--column', columnNumber, fileName]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.LAUNCH_EDITOR) {
|
|
|
|
return [fileName, lineNumber, columnNumber]
|
2023-12-18 13:12:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For all others, drop the lineNumber until we have
|
|
|
|
// a mapping above, since providing the lineNumber incorrectly
|
|
|
|
// can result in errors or confusing behavior.
|
|
|
|
return [fileName]
|
|
|
|
}
|