Search in sources :

Example 1 with CommandLinePatcher

use of com.jetbrains.python.run.CommandLinePatcher in project intellij-community by JetBrains.

the class PyDebugRunner method createDebugServerPatcher.

private CommandLinePatcher createDebugServerPatcher(final Project project, final PythonCommandLineState pyState, final int serverLocalPort) {
    return new CommandLinePatcher() {

        private void patchExeParams(ParametersList parametersList) {
            // we should remove '-m' parameter, but notify debugger of it
            // but we can't remove one parameter from group, so we create new parameters group
            ParamsGroup newExeParams = new ParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
            int exeParamsIndex = parametersList.getParamsGroups().indexOf(parametersList.getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS));
            ParamsGroup exeParamsOld = parametersList.removeParamsGroup(exeParamsIndex);
            isModule = false;
            for (String param : exeParamsOld.getParameters()) {
                if (!param.equals("-m")) {
                    newExeParams.addParameter(param);
                } else {
                    isModule = true;
                }
            }
            parametersList.addParamsGroupAt(exeParamsIndex, newExeParams);
        }

        @Override
        public void patchCommandLine(GeneralCommandLine commandLine) {
            // script name is the last parameter; all other params are for python interpreter; insert just before name
            ParametersList parametersList = commandLine.getParametersList();
            @SuppressWarnings("ConstantConditions") @NotNull ParamsGroup debugParams = parametersList.getParamsGroup(PythonCommandLineState.GROUP_DEBUGGER);
            patchExeParams(parametersList);
            @SuppressWarnings("ConstantConditions") @NotNull ParamsGroup exeParams = parametersList.getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
            final PythonSdkFlavor flavor = pyState.getSdkFlavor();
            if (flavor != null) {
                assert exeParams != null;
                for (String option : flavor.getExtraDebugOptions()) {
                    exeParams.addParameter(option);
                }
            }
            assert debugParams != null;
            fillDebugParameters(project, debugParams, serverLocalPort, pyState, commandLine);
        }
    };
}
Also used : CommandLinePatcher(com.jetbrains.python.run.CommandLinePatcher) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CommandLinePatcher (com.jetbrains.python.run.CommandLinePatcher)1 PythonSdkFlavor (com.jetbrains.python.sdk.flavors.PythonSdkFlavor)1 NotNull (org.jetbrains.annotations.NotNull)1