Search in sources :

Example 66 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PythonConsoleView method addTextRangeToHistory.

@NotNull
protected String addTextRangeToHistory(@NotNull TextRange textRange, @NotNull EditorEx inputEditor, boolean preserveMarkup) {
    String text;
    EditorHighlighter highlighter;
    if (inputEditor instanceof EditorWindow) {
        PsiFile file = ((EditorWindow) inputEditor).getInjectedFile();
        highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), getProject());
        String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
        highlighter.setText(fullText);
        text = textRange.substring(fullText);
    } else {
        text = inputEditor.getDocument().getText(textRange);
        highlighter = inputEditor.getHighlighter();
    }
    SyntaxHighlighter syntax = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
    doAddPromptToHistory(true);
    if (syntax != null) {
        ConsoleViewUtil.printWithHighlighting(this, text, syntax, () -> doAddPromptToHistory(false));
    } else {
        print(text, ConsoleViewContentType.USER_INPUT);
    }
    print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
    return text;
}
Also used : PsiFile(com.intellij.psi.PsiFile) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PydevConsoleRunner method findPythonSdkAndModule.

@NotNull
static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
    Sdk sdk = null;
    Module module = null;
    PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
    String sdkHome = settings.getSdkHome();
    if (sdkHome != null) {
        sdk = PythonSdkType.findSdkByPath(sdkHome);
        if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        } else {
            module = contextModule;
            if (module == null && ModuleManager.getInstance(project).getModules().length > 0) {
                module = ModuleManager.getInstance(project).getModules()[0];
            }
        }
    }
    if (sdk == null && settings.isUseModuleSdk()) {
        if (contextModule != null) {
            module = contextModule;
        } else if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        }
        if (module != null) {
            if (PythonSdkType.findPythonSdk(module) != null) {
                sdk = PythonSdkType.findPythonSdk(module);
            }
        }
    } else if (contextModule != null) {
        if (module == null) {
            module = contextModule;
        }
        if (sdk == null) {
            sdk = PythonSdkType.findPythonSdk(module);
        }
    }
    if (sdk == null) {
        for (Module m : ModuleManager.getInstance(project).getModules()) {
            if (PythonSdkType.findPythonSdk(m) != null) {
                sdk = PythonSdkType.findPythonSdk(m);
                module = m;
                break;
            }
        }
    }
    if (sdk == null) {
        if (PythonSdkType.getAllSdks().size() > 0) {
            //noinspection UnusedAssignment
            //take any python sdk
            sdk = PythonSdkType.getAllSdks().get(0);
        }
    }
    return Pair.create(sdk, module);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method connectToDebugger.

private XDebugSession connectToDebugger() throws ExecutionException {
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
    final XDebugSession session = XDebuggerManager.getInstance(myProject).startSessionAndShowTab("Python Console Debugger", PythonIcons.Python.Python, null, true, new XDebugProcessStarter() {

        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PythonDebugLanguageConsoleView debugConsoleView = new PythonDebugLanguageConsoleView(myProject, mySdk);
            PyConsoleDebugProcessHandler consoleDebugProcessHandler = new PyConsoleDebugProcessHandler(myProcessHandler);
            PyConsoleDebugProcess consoleDebugProcess = new PyConsoleDebugProcess(session, serverSocket, debugConsoleView, consoleDebugProcessHandler);
            PythonDebugConsoleCommunication communication = PyDebugRunner.initDebugConsoleView(myProject, consoleDebugProcess, debugConsoleView, consoleDebugProcessHandler, session);
            communication.addCommunicationListener(new ConsoleCommunicationListener() {

                @Override
                public void commandExecuted(boolean more) {
                    session.rebuildViews();
                }

                @Override
                public void inputRequested() {
                }
            });
            myPydevConsoleCommunication.setDebugCommunication(communication);
            debugConsoleView.attachToProcess(consoleDebugProcessHandler);
            consoleDebugProcess.waitForNextConnection();
            try {
                consoleDebugProcess.connect(myPydevConsoleCommunication);
            } catch (Exception e) {
                //TODO
                LOG.error(e);
            }
            myProcessHandler.notifyTextAvailable("\nDebugger connected.\n", ProcessOutputTypes.STDERR);
            return consoleDebugProcess;
        }
    });
    return session;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConsoleCommunicationListener(com.jetbrains.python.console.pydev.ConsoleCommunicationListener) ServerSocket(java.net.ServerSocket) NotNull(org.jetbrains.annotations.NotNull) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 69 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method createExecuteActionHandler.

@NotNull
protected PydevConsoleExecuteActionHandler createExecuteActionHandler() {
    myConsoleExecuteActionHandler = new PydevConsoleExecuteActionHandler(myConsoleView, myProcessHandler, myPydevConsoleCommunication);
    myConsoleExecuteActionHandler.setEnabled(false);
    new ConsoleHistoryController(myConsoleType.getTypeId(), "", myConsoleView).install();
    return myConsoleExecuteActionHandler;
}
Also used : ConsoleHistoryController(com.intellij.execution.console.ConsoleHistoryController) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyAttachToProcessDebugRunner method launchRemoteDebugServer.

private XDebugSession launchRemoteDebugServer() throws ExecutionException {
    final ServerSocket serverSocket;
    try {
        //noinspection SocketOpenedButNotSafelyClosed
        serverSocket = new ServerSocket(0);
    } catch (IOException e) {
        throw new ExecutionException("Failed to find free socket port", e);
    }
    PyAttachToProcessCommandLineState state = PyAttachToProcessCommandLineState.create(myProject, mySdkPath, serverSocket.getLocalPort(), myPid);
    final ExecutionResult result = state.execute(state.getEnvironment().getExecutor(), this);
    //start remote debug server
    return XDebuggerManager.getInstance(myProject).startSessionAndShowTab(String.valueOf(myPid), null, new XDebugProcessStarter() {

        @org.jetbrains.annotations.NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PyRemoteDebugProcess pyDebugProcess = new PyRemoteDebugProcess(session, serverSocket, result.getExecutionConsole(), result.getProcessHandler(), "") {

                @Override
                protected void printConsoleInfo() {
                }

                @Override
                protected String getConnectionMessage() {
                    return "Attaching to a process with PID=" + myPid;
                }

                @Override
                protected String getConnectionTitle() {
                    return "Attaching Debugger";
                }
            };
            pyDebugProcess.setPositionConverter(new PyLocalPositionConverter());
            createConsoleCommunicationAndSetupActions(myProject, result, pyDebugProcess, session);
            return pyDebugProcess;
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) ServerSocket(java.net.ServerSocket) ExecutionResult(com.intellij.execution.ExecutionResult) IOException(java.io.IOException) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) PyLocalPositionConverter(com.jetbrains.python.debugger.PyLocalPositionConverter) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) PyRemoteDebugProcess(com.jetbrains.python.debugger.PyRemoteDebugProcess)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146