打开文本编辑器,并定位到文件位置
在 react dev 中的运行场景:webpack dev server 中注册__open-stack-frame-in-editor
接口
launchEditor
code --help
单独运行的前提
运行过程
process.env.REACT_EDITOR
process.platform === 'darwin'
=> ps x
process.platform === 'win32'
=> wmic process where "executablepath is not null" get executablepath
process.platform === 'linux'
=> ps x --no-heading -o comm --sort=comm
这里提取vscode相关信息
const COMMON_EDITORS_OSX = {
// ...
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
// ...
};
const COMMON_EDITORS_LINUX = {
// ...
code: 'code',
// ...
};
const COMMON_EDITORS_WIN = [
// ...
'Code.exe',
// ...
];
function addWorkspaceToArgumentsIfExists(args, workspace) {
if (workspace) {
args.unshift(workspace);
}
return args;
}
function getArgumentsForLineNumber(
editor,
fileName,
lineNumber,
colNumber,
workspace
) {
const editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '');
switch (editorBasename) {
// ...
case 'code':
case 'Code':
return addWorkspaceToArgumentsIfExists(
['-g', fileName + ':' + lineNumber + ':' + colNumber],
workspace
);
// ...
}
return [fileName];
}
← mpvue react-native →