PluginPyright.py

Tue, 07 Nov 2023 15:17:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 07 Nov 2023 15:17:48 +0100
changeset 1
191e9ec72893
parent 0
PluginPyright@1b1bf094c013
child 3
109b8e5513d8
permissions
-rw-r--r--

Implemented the first iteration of the pyright typing checker interface.

1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
1 # -*- coding: utf-8 -*-
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
2
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
4 #
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
5
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
6 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
7 Module implementing the pyright plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
8 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
9
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
10 import contextlib
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
11 import os
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
12
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
13 from PyQt6.QtCore import QObject, QTranslator, pyqtSlot
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
14
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15 from eric7 import Preferences
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
16 from eric7.EricGui.EricAction import EricAction
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from eric7.EricWidgets.EricApplication import ericApp
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
18 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
19
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
20 # Start-Of-Header
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
21 __header__ = {
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
22 "name": "Python Typing Checker Plug-in",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
23 "author": "Detlev Offenbach <detlev@die-offenbachs.de>",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
24 "autoactivate": True,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
25 "deactivateable": True,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
26 "version": "10.0.0",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
27 "className": "PyrightPlugin",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
28 "packageName": "PyrightChecker",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
29 "shortDescription": "Plug-in to check Python sources for typing issues.",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
30 "longDescription": ("""Plug-in to check Python sources for typing issues."""),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
31 "needsRestart": False,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
32 "pyqtApi": 2,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
33 }
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
34 # End-Of-Header
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
35
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
36 error = "" # noqa: U200
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
37
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
38
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
39 def prepareUninstall():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
40 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
41 Module function to prepare for an uninstallation.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
42 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
43 Preferences.Prefs.settings.remove(PyrightPlugin.PreferencesKey)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
44
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
45
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
46 class PyrightPlugin(QObject):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
47 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
48 Class documentation goes here.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
49 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
50
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
51 PreferencesKey = "Pyright"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
52
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
53 def __init__(self, ui):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
54 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
55 Constructor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
56
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
57 @param ui reference to the user interface object
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
58 @type UI.UserInterface
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
59 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
60 super().__init__(ui)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
61 self.__ui = ui
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
62 self.__initialize()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
63
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
64 def __initialize(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
65 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
66 Private slot to (re)initialize the plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
67 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
68 self.__projectAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
69 self.__projectPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
70
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
71 self.__projectBrowserAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
72 self.__projectBrowserMenu = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
73 self.__projectBrowserPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
74
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
75 self.__editors = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
76 self.__editorAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
77 self.__editorPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
78
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
79 def activate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
80 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
81 Public method to activate this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
82
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
83 @return tuple of None and activation status
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
84 @rtype bool
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
85 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
86 global error
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
87 error = "" # clear previous error
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
88
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
89 menu = ericApp().getObject("Project").getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
90 if menu:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
91 self.__projectAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
92 self.tr("Static Type Check"),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
93 self.tr("Static &Typing..."),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
94 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
95 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
96 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
97 "project_check_pyright",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
98 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
99 self.__projectAct.setStatusTip(self.tr("Check for typing issues"))
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
100 self.__projectAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
101 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
102 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
103 """<p>This checks a Python project for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
104 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
105 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
106 self.__projectAct.triggered.connect(self.__projectPyrightCheck)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
107 ericApp().getObject("Project").addEricActions([self.__projectAct])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
108 menu.addAction(self.__projectAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
109
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
110 self.__editorAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
111 self.tr("Static Type Check"), self.tr("Static &Typing..."), 0, 0, self, ""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
112 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
113 self.__editorAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
114 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
115 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
116 """<p>This checks a Python file for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
117 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
118 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
119 self.__editorAct.triggered.connect(self.__editorPyrightCheck)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
120
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
121 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
122 ericApp().getObject("ProjectBrowser").getProjectBrowser(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
123 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
124 ).showMenu.connect(self.__projectBrowserShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
125 ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
126 ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
127
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
128 for editor in ericApp().getObject("ViewManager").getOpenEditors():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
129 self.__editorOpened(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
130
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
131 return None, True
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
132
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
133 def deactivate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
134 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
135 Public method to deactivate this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
136 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
137 ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
138 ericApp().getObject("ProjectBrowser").getProjectBrowser(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
139 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
140 ).showMenu.disconnect(self.__projectBrowserShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
141
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
142 menu = ericApp().getObject("Project").getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
143 if menu is not None and self.__projectAct is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
144 menu.removeAction(self.__projectAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
145 ericApp().getObject("Project").removeEricActions([self.__projectAct])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
146
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
147 if self.__projectBrowserMenu and self.__projectBrowserAct:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
148 self.__projectBrowserMenu.removeAction(self.__projectBrowserAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
149
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
150 for editor in self.__editors:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
151 editor.showMenu.disconnect(self.__editorShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
152 menu = editor.getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
153 if menu is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154 menu.removeAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
155
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
156 self.__initialize()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
157
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
158 def __loadTranslator(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
159 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
160 Private method to load the translation file.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
161 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
162 if self.__ui is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
163 loc = self.__ui.getLocale()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
164 if loc and loc != "C":
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
165 locale_dir = os.path.join(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
166 os.path.dirname(__file__), "PyrightChecker", "i18n"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
167 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
168 translation = "pyright_{0}".format(loc)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
169 translator = QTranslator(None)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
170 loaded = translator.load(translation, locale_dir)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
171 if loaded:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
172 self.__translator = translator
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
173 ericApp().installTranslator(self.__translator)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
174 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
175 print(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
176 "Warning: translation file '{0}' could not be"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
177 " loaded.".format(translation)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
178 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
179 print("Using default.")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
180
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
181 def __projectShowMenu(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
182 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
183 menuName,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
184 menu, # noqa: U100
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
185 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
186 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
187 Private slot called, when the the project menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
188 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
189
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
190 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
191 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
192 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
193 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
194 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
195 if menuName == "Check" and self.__projectAct is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
196 self.__projectAct.setEnabled(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
197 ericApp().getObject("Project").getProjectLanguage() == "Python3"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
199
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 def __projectBrowserShowMenu(self, menuName, menu):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
201 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 Private slot called, when the the project browser menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
203 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
204
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
205 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
206 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
207 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
208 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
209 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
210 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
211 menuName == "Checks"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
212 and ericApp().getObject("Project").getProjectLanguage() == "Python3"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
213 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
214 self.__projectBrowserMenu = menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
215 if self.__projectBrowserAct is None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
216 self.__projectBrowserAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
217 self.tr("Static Type Check"),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
218 self.tr("Static &Typing..."),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
219 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
220 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
221 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
222 "",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
223 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
224 self.__projectBrowserAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
225 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
226 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
227 """<p>This checks Python files for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
228 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
229 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
230 self.__projectBrowserAct.triggered.connect(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
231 self.__projectBrowserPyrightCheck
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
232 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
233 if self.__projectBrowserAct not in menu.actions():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
234 menu.addAction(self.__projectBrowserAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
235
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
236 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
237 def __projectPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
238 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
239 Private slot used to check the project for static typing issues.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
240 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
242
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
243 project = ericApp().getObject("Project")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
244 project.saveAllScripts()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
245
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
246 if self.__projectPyrightCheckerDialog is None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
247 self.__projectPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
248 self.__projectPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
249 self.__projectPyrightCheckerDialog.prepare(project)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
250
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
251 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
252 def __projectBrowserPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
253 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
254 Private method to handle the static typing check context menu action of
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
255 the project sources browser.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
256 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
257 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
258
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
259 browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
260 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
261 fn = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
262 for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
263 fn.append(itm.fileName())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
264 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
265 itm = browser.model().item(browser.currentIndex())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
266 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
267 fn = [itm.fileName()]
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
268 except AttributeError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
269 fn = [itm.dirName()]
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
270
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
271 self.__projectBrowserPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
272 self.__projectBrowserPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
273 self.__projectBrowserPyrightCheckerDialog.start(fn, save=True)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
274
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
275 def __editorOpened(self, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
276 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
277 Private slot called, when a new editor was opened.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
278
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
279 @param editor reference to the new editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
280 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
281 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
282 menu = editor.getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
283 if menu is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
284 menu.addAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
285 editor.showMenu.connect(self.__editorShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
286 self.__editors.append(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
287
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
288 def __editorClosed(self, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
289 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
290 Private slot called, when an editor was closed.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
291
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
292 @param editor reference to the editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
293 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
294 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
295 with contextlib.suppress(ValueError):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
296 self.__editors.remove(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
297
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
298 def __editorShowMenu(self, menuName, menu, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
299 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
300 Private slot called, when the the editor context menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
301 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
302
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
303 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
304 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
305 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
306 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
307 @param editor reference to the editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
308 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
309 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
310 if menuName == "Checks":
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
311 if self.__editorAct not in menu.actions():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
312 menu.addAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
313 self.__editorAct.setEnabled(editor.isPyFile())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
314
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
315 def __editorPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
316 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
317 Private slot to handle the code style check context menu action
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
318 of the editors.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
319 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
320 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
321
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
322 editor = ericApp().getObject("ViewManager").activeWindow()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
323 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
324 editor is not None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
325 and editor.checkDirty()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
326 and editor.getFileName() is not None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
327 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
328 self.__editorPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
329 self.__editorPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
330 self.__editorPyrightCheckerDialog.start([editor.getFileName()], save=True)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
331
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
332
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
333 def installDependencies(pipInstall):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
334 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
335 Function to install dependencies of this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
336
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
337 @param pipInstall function to be called with a list of package names.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
338 @type function
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
339 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
340 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
341 import pyright # __IGNORE_WARNING__
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
342 except ImportError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
343 pipInstall(["pyright"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
344 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
345 import tomlkit # __IGNORE_WARNING__
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
346 except ImportError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
347 pipInstall(["tomlkit"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
348
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
349
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
350 #
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
351 # eflag: noqa = M801

eric ide

mercurial