pycforge 0.15.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. pycforge/__init__.py +8 -0
  2. pycforge/__main__.py +2 -0
  3. pycforge/_version.py +1 -0
  4. pycforge/converter/__init__.py +0 -0
  5. pycforge/converter/analysis/__init__.py +5 -0
  6. pycforge/converter/analysis/functions.py +723 -0
  7. pycforge/converter/analysis/model.py +158 -0
  8. pycforge/converter/analysis/planning.py +464 -0
  9. pycforge/converter/analysis/stage.py +1976 -0
  10. pycforge/converter/analysis/symbols.py +237 -0
  11. pycforge/converter/analysis/validation.py +2166 -0
  12. pycforge/converter/c_output/__init__.py +2 -0
  13. pycforge/converter/c_output/conformance.py +297 -0
  14. pycforge/converter/c_output/renderer.py +220 -0
  15. pycforge/converter/conditional_regions/__init__.py +71 -0
  16. pycforge/converter/conditional_regions/analysis.py +481 -0
  17. pycforge/converter/conditional_regions/lowering.py +579 -0
  18. pycforge/converter/conditional_regions/model.py +243 -0
  19. pycforge/converter/conditional_regions/validation.py +690 -0
  20. pycforge/converter/containers/__init__.py +19 -0
  21. pycforge/converter/containers/analysis.py +542 -0
  22. pycforge/converter/containers/lowering.py +290 -0
  23. pycforge/converter/containers/model.py +146 -0
  24. pycforge/converter/contracts/__init__.py +0 -0
  25. pycforge/converter/contracts/configuration.py +178 -0
  26. pycforge/converter/contracts/identifiers.py +68 -0
  27. pycforge/converter/contracts/versions.py +71 -0
  28. pycforge/converter/core/__init__.py +0 -0
  29. pycforge/converter/core/artifact_io.py +87 -0
  30. pycforge/converter/core/cancellation.py +7 -0
  31. pycforge/converter/core/canonicalization.py +254 -0
  32. pycforge/converter/core/context.py +13 -0
  33. pycforge/converter/core/diagnostics.py +95 -0
  34. pycforge/converter/core/enums.py +23 -0
  35. pycforge/converter/core/fingerprint.py +22 -0
  36. pycforge/converter/core/pipeline.py +8 -0
  37. pycforge/converter/core/progress.py +25 -0
  38. pycforge/converter/core/request.py +50 -0
  39. pycforge/converter/core/resource_policy.py +31 -0
  40. pycforge/converter/core/result.py +23 -0
  41. pycforge/converter/core/serialization.py +36 -0
  42. pycforge/converter/core/stage.py +10 -0
  43. pycforge/converter/core/stage_artifact.py +80 -0
  44. pycforge/converter/core/stage_outcome.py +15 -0
  45. pycforge/converter/decision_trace/__init__.py +0 -0
  46. pycforge/converter/decision_trace/recorder.py +52 -0
  47. pycforge/converter/facade.py +459 -0
  48. pycforge/converter/frontend/__init__.py +4 -0
  49. pycforge/converter/frontend/normalizer.py +59 -0
  50. pycforge/converter/frontend/parser.py +20 -0
  51. pycforge/converter/frontend/source_document.py +93 -0
  52. pycforge/converter/frontend/stages.py +518 -0
  53. pycforge/converter/frontend/validation.py +76 -0
  54. pycforge/converter/io/__init__.py +0 -0
  55. pycforge/converter/io/atomic_writer.py +33 -0
  56. pycforge/converter/ir/__init__.py +1 -0
  57. pycforge/converter/ir/c_ir/__init__.py +4 -0
  58. pycforge/converter/ir/c_ir/builder.py +26 -0
  59. pycforge/converter/ir/c_ir/model.py +318 -0
  60. pycforge/converter/ir/c_ir/serialization.py +88 -0
  61. pycforge/converter/ir/c_ir/validation.py +834 -0
  62. pycforge/converter/ir/python_ir/__init__.py +17 -0
  63. pycforge/converter/ir/python_ir/nodes.py +86 -0
  64. pycforge/converter/keyword_calls/__init__.py +68 -0
  65. pycforge/converter/keyword_calls/analysis.py +458 -0
  66. pycforge/converter/keyword_calls/lowering.py +271 -0
  67. pycforge/converter/keyword_calls/model.py +304 -0
  68. pycforge/converter/keyword_calls/validation.py +802 -0
  69. pycforge/converter/keyword_only_calls/__init__.py +68 -0
  70. pycforge/converter/keyword_only_calls/analysis.py +640 -0
  71. pycforge/converter/keyword_only_calls/lowering.py +376 -0
  72. pycforge/converter/keyword_only_calls/model.py +328 -0
  73. pycforge/converter/keyword_only_calls/validation.py +1357 -0
  74. pycforge/converter/lowering.py +1000 -0
  75. pycforge/converter/modules/__init__.py +13 -0
  76. pycforge/converter/modules/analysis.py +1250 -0
  77. pycforge/converter/modules/lowering.py +200 -0
  78. pycforge/converter/modules/model.py +73 -0
  79. pycforge/converter/modules/stage.py +192 -0
  80. pycforge/converter/numeric_semantics/__init__.py +23 -0
  81. pycforge/converter/numeric_semantics/analysis.py +420 -0
  82. pycforge/converter/numeric_semantics/lowering.py +153 -0
  83. pycforge/converter/numeric_semantics/model.py +123 -0
  84. pycforge/converter/records/__init__.py +34 -0
  85. pycforge/converter/records/analysis.py +1394 -0
  86. pycforge/converter/records/lowering.py +393 -0
  87. pycforge/converter/records/model.py +319 -0
  88. pycforge/converter/rules/__init__.py +3 -0
  89. pycforge/converter/support_templates/__init__.py +49 -0
  90. pycforge/converter/support_templates/assembly.py +106 -0
  91. pycforge/converter/support_templates/factories.py +348 -0
  92. pycforge/converter/support_templates/model.py +159 -0
  93. pycforge/converter/support_templates/registry.py +388 -0
  94. pycforge/converter/telemetry/__init__.py +0 -0
  95. pycforge/converter/telemetry/sink.py +39 -0
  96. pycforge/ide/__init__.py +19 -0
  97. pycforge/ide/__main__.py +5 -0
  98. pycforge/ide/_worker_event_codec.py +276 -0
  99. pycforge/ide/_worker_protocol_json.py +197 -0
  100. pycforge/ide/_worker_protocol_types.py +90 -0
  101. pycforge/ide/_worker_request_codec.py +200 -0
  102. pycforge/ide/_worker_request_data.py +260 -0
  103. pycforge/ide/_worker_result_data.py +343 -0
  104. pycforge/ide/action_contract.py +469 -0
  105. pycforge/ide/action_validation.py +229 -0
  106. pycforge/ide/command_palette.py +223 -0
  107. pycforge/ide/controller.py +904 -0
  108. pycforge/ide/controller_conversion.py +546 -0
  109. pycforge/ide/controller_io.py +205 -0
  110. pycforge/ide/editor.py +951 -0
  111. pycforge/ide/editor_commands_qt.py +274 -0
  112. pycforge/ide/editor_lexical.py +43 -0
  113. pycforge/ide/editor_sidebars.py +236 -0
  114. pycforge/ide/editor_syntax.py +243 -0
  115. pycforge/ide/find_replace.py +535 -0
  116. pycforge/ide/icons.py +91 -0
  117. pycforge/ide/io_service.py +196 -0
  118. pycforge/ide/model.py +164 -0
  119. pycforge/ide/panels.py +903 -0
  120. pycforge/ide/positions.py +220 -0
  121. pycforge/ide/process_worker.py +130 -0
  122. pycforge/ide/qt.py +230 -0
  123. pycforge/ide/qt_actions.py +418 -0
  124. pycforge/ide/qt_close.py +169 -0
  125. pycforge/ide/qt_command_palette.py +297 -0
  126. pycforge/ide/qt_contract.py +220 -0
  127. pycforge/ide/qt_documents.py +590 -0
  128. pycforge/ide/qt_editor_buffers.py +113 -0
  129. pycforge/ide/qt_editor_surfaces.py +112 -0
  130. pycforge/ide/qt_menus.py +324 -0
  131. pycforge/ide/qt_projection.py +500 -0
  132. pycforge/ide/qt_shell.py +348 -0
  133. pycforge/ide/qt_shell_interactions.py +320 -0
  134. pycforge/ide/qt_state.py +393 -0
  135. pycforge/ide/qt_workspace_features.py +398 -0
  136. pycforge/ide/qt_workspace_navigation.py +208 -0
  137. pycforge/ide/qt_workspace_observers.py +173 -0
  138. pycforge/ide/qt_workspace_panels.py +545 -0
  139. pycforge/ide/qt_workspace_widgets.py +228 -0
  140. pycforge/ide/resources/icons/about.svg +1 -0
  141. pycforge/ide/resources/icons/add-document.svg +1 -0
  142. pycforge/ide/resources/icons/brand-mark.svg +1 -0
  143. pycforge/ide/resources/icons/bundle-search.svg +1 -0
  144. pycforge/ide/resources/icons/cancel.svg +1 -0
  145. pycforge/ide/resources/icons/check.svg +1 -0
  146. pycforge/ide/resources/icons/chevron-right.svg +1 -0
  147. pycforge/ide/resources/icons/close.svg +1 -0
  148. pycforge/ide/resources/icons/collapse-all.svg +1 -0
  149. pycforge/ide/resources/icons/command-palette.svg +1 -0
  150. pycforge/ide/resources/icons/convert.svg +1 -0
  151. pycforge/ide/resources/icons/copy.svg +1 -0
  152. pycforge/ide/resources/icons/cut.svg +1 -0
  153. pycforge/ide/resources/icons/decision-trace.svg +1 -0
  154. pycforge/ide/resources/icons/details.svg +1 -0
  155. pycforge/ide/resources/icons/diagnostics.svg +1 -0
  156. pycforge/ide/resources/icons/duplicate-line.svg +1 -0
  157. pycforge/ide/resources/icons/exit.svg +1 -0
  158. pycforge/ide/resources/icons/expand-all.svg +1 -0
  159. pycforge/ide/resources/icons/export.svg +1 -0
  160. pycforge/ide/resources/icons/find.svg +1 -0
  161. pycforge/ide/resources/icons/go-to-line.svg +1 -0
  162. pycforge/ide/resources/icons/go-to-output.svg +1 -0
  163. pycforge/ide/resources/icons/go-to-source.svg +1 -0
  164. pycforge/ide/resources/icons/history.svg +1 -0
  165. pycforge/ide/resources/icons/indent.svg +1 -0
  166. pycforge/ide/resources/icons/link-c.svg +1 -0
  167. pycforge/ide/resources/icons/mappings.svg +1 -0
  168. pycforge/ide/resources/icons/module.svg +1 -0
  169. pycforge/ide/resources/icons/move-down.svg +1 -0
  170. pycforge/ide/resources/icons/move-line-down.svg +1 -0
  171. pycforge/ide/resources/icons/move-line-up.svg +1 -0
  172. pycforge/ide/resources/icons/move-up.svg +1 -0
  173. pycforge/ide/resources/icons/next.svg +1 -0
  174. pycforge/ide/resources/icons/open.svg +1 -0
  175. pycforge/ide/resources/icons/outdent.svg +1 -0
  176. pycforge/ide/resources/icons/outline.svg +1 -0
  177. pycforge/ide/resources/icons/paste.svg +1 -0
  178. pycforge/ide/resources/icons/previous.svg +1 -0
  179. pycforge/ide/resources/icons/primary-module.svg +1 -0
  180. pycforge/ide/resources/icons/redo.svg +1 -0
  181. pycforge/ide/resources/icons/remove-document.svg +1 -0
  182. pycforge/ide/resources/icons/replace.svg +1 -0
  183. pycforge/ide/resources/icons/save-as.svg +1 -0
  184. pycforge/ide/resources/icons/save.svg +1 -0
  185. pycforge/ide/resources/icons/select-all.svg +1 -0
  186. pycforge/ide/resources/icons/settings.svg +1 -0
  187. pycforge/ide/resources/icons/show-c.svg +1 -0
  188. pycforge/ide/resources/icons/split-view.svg +1 -0
  189. pycforge/ide/resources/icons/summary.svg +1 -0
  190. pycforge/ide/resources/icons/telemetry.svg +1 -0
  191. pycforge/ide/resources/icons/toggle-comment.svg +1 -0
  192. pycforge/ide/resources/icons/toggle-fold.svg +1 -0
  193. pycforge/ide/resources/icons/undo.svg +1 -0
  194. pycforge/ide/resources/icons/whitespace.svg +1 -0
  195. pycforge/ide/revisions.py +400 -0
  196. pycforge/ide/search_service.py +280 -0
  197. pycforge/ide/session_history.py +150 -0
  198. pycforge/ide/source_editing.py +417 -0
  199. pycforge/ide/source_structure.py +558 -0
  200. pycforge/ide/source_structure_async.py +191 -0
  201. pycforge/ide/supervisor.py +503 -0
  202. pycforge/ide/theme.py +119 -0
  203. pycforge/ide/theme_stylesheet.py +598 -0
  204. pycforge/ide/theme_workspace_stylesheet.py +155 -0
  205. pycforge/ide/visual_tokens.py +142 -0
  206. pycforge/ide/worker_protocol.py +80 -0
  207. pycforge/ide/workspace_search.py +462 -0
  208. pycforge/ide/workspace_session.py +256 -0
  209. pycforge/laboratory/__init__.py +6 -0
  210. pycforge/laboratory/audits.py +2244 -0
  211. pycforge/laboratory/checkpoint_e.py +2685 -0
  212. pycforge/laboratory/cli.py +119 -0
  213. pycforge/laboratory/exit_codes.py +11 -0
  214. pycforge/laboratory/keyword_audit.py +661 -0
  215. pycforge/laboratory/keyword_only_audit.py +481 -0
  216. pycforge-0.15.2.dist-info/METADATA +209 -0
  217. pycforge-0.15.2.dist-info/RECORD +221 -0
  218. pycforge-0.15.2.dist-info/WHEEL +5 -0
  219. pycforge-0.15.2.dist-info/entry_points.txt +5 -0
  220. pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
  221. pycforge-0.15.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,297 @@
1
+ """Optional Qt command-palette and go-to-line presentation adapters.
2
+
3
+ This module is imported only by the optional Qt workspace. It creates no
4
+ actions and owns no action implementation: palette rows are inert projections
5
+ from the headless action contract, and activation resolves the selected stable
6
+ ID through the existing :class:`QtActionRegistry`.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Mapping
12
+
13
+ from PyQt5.QtCore import QEvent, Qt
14
+ from PyQt5.QtGui import QKeySequence
15
+ from PyQt5.QtWidgets import (
16
+ QAbstractItemView,
17
+ QDialog,
18
+ QHBoxLayout,
19
+ QInputDialog,
20
+ QLabel,
21
+ QLineEdit,
22
+ QTreeWidget,
23
+ QTreeWidgetItem,
24
+ QVBoxLayout,
25
+ QWidget,
26
+ )
27
+
28
+ from .action_contract import ActionState
29
+ from .command_palette import (
30
+ MAX_COMMAND_PALETTE_RESULTS,
31
+ CommandPaletteProjection,
32
+ project_command_palette,
33
+ )
34
+ from .qt_actions import QtActionRegistry
35
+
36
+
37
+ class CommandPaletteDialog(QDialog):
38
+ """Keyboard-complete projection of the existing Qt action registry."""
39
+
40
+ def __init__(
41
+ self,
42
+ owner: QWidget,
43
+ registry: QtActionRegistry,
44
+ states: Mapping[str, ActionState],
45
+ ) -> None:
46
+ if not isinstance(registry, QtActionRegistry):
47
+ raise TypeError("registry must be QtActionRegistry")
48
+ if not isinstance(states, Mapping):
49
+ raise TypeError("palette states must be a mapping")
50
+ super().__init__(owner)
51
+ self._registry = registry
52
+ self._states = dict(states)
53
+ self._visible_action_ids: frozenset[str] = frozenset()
54
+ self._invoked_action_id: str | None = None
55
+
56
+ self.setObjectName("CommandPaletteDialog")
57
+ self.setWindowTitle("Command Palette")
58
+ self.setModal(True)
59
+ self.setMinimumWidth(620)
60
+ self.resize(720, 480)
61
+ self.setAccessibleName("PyCForge command palette")
62
+ self.setAccessibleDescription(
63
+ "Filter and invoke declared PyCForge workspace actions."
64
+ )
65
+
66
+ heading = QLabel("COMMAND PALETTE")
67
+ heading.setObjectName("PanelEyebrow")
68
+ self.query_edit = QLineEdit()
69
+ self.query_edit.setObjectName("CommandPaletteQuery")
70
+ self.query_edit.setPlaceholderText("Type an action name or shortcut…")
71
+ self.query_edit.setClearButtonEnabled(True)
72
+ self.query_edit.setAccessibleName("Filter workspace actions")
73
+
74
+ self.count_label = QLabel()
75
+ self.count_label.setObjectName("MutedLabel")
76
+ self.count_label.setAccessibleName("Command palette result count")
77
+ heading_row = QHBoxLayout()
78
+ heading_row.addWidget(heading)
79
+ heading_row.addStretch(1)
80
+ heading_row.addWidget(self.count_label)
81
+
82
+ self.results = QTreeWidget()
83
+ self.results.setObjectName("CommandPaletteResults")
84
+ self.results.setColumnCount(2)
85
+ self.results.setHeaderLabels(("Action", "Shortcut"))
86
+ self.results.setRootIsDecorated(False)
87
+ self.results.setUniformRowHeights(True)
88
+ self.results.setAlternatingRowColors(False)
89
+ self.results.setSelectionMode(QAbstractItemView.SingleSelection)
90
+ self.results.setAccessibleName("Matching workspace actions")
91
+ self.results.setAccessibleDescription(
92
+ "Use Up and Down to choose an enabled action and Enter to invoke it."
93
+ )
94
+ self.results.header().setStretchLastSection(False)
95
+ self.results.header().resizeSection(0, 510)
96
+ self.results.header().resizeSection(1, 130)
97
+
98
+ self.empty_label = QLabel("No matching declared actions")
99
+ self.empty_label.setObjectName("MutedLabel")
100
+ self.empty_label.setAlignment(Qt.AlignCenter)
101
+ self.empty_label.setAccessibleName("No matching actions")
102
+ self.empty_label.hide()
103
+
104
+ layout = QVBoxLayout(self)
105
+ layout.setContentsMargins(14, 14, 14, 14)
106
+ layout.setSpacing(9)
107
+ layout.addLayout(heading_row)
108
+ layout.addWidget(self.query_edit)
109
+ layout.addWidget(self.results, 1)
110
+ layout.addWidget(self.empty_label)
111
+
112
+ self.query_edit.textChanged.connect(self._refresh_projection)
113
+ self.results.itemActivated.connect(self._activate_item)
114
+ self.query_edit.installEventFilter(self)
115
+ self.results.installEventFilter(self)
116
+ self._refresh_projection("")
117
+ self.query_edit.setFocus()
118
+
119
+ @property
120
+ def invoked_action_id(self) -> str | None:
121
+ return self._invoked_action_id
122
+
123
+ def projection(self) -> CommandPaletteProjection:
124
+ """Return the current bounded headless projection."""
125
+
126
+ return project_command_palette(
127
+ self.query_edit.text(),
128
+ states=self._states,
129
+ limit=MAX_COMMAND_PALETTE_RESULTS,
130
+ )
131
+
132
+ def _refresh_projection(self, _query: str) -> None:
133
+ projection = self.projection()
134
+ self.results.clear()
135
+ visible_ids: list[str] = []
136
+ first_enabled: QTreeWidgetItem | None = None
137
+ for palette_item in projection.items:
138
+ action = self._registry.action(palette_item.action_id)
139
+ rendered_shortcut = action.shortcut().toString(
140
+ QKeySequence.NativeText
141
+ )
142
+ if not rendered_shortcut:
143
+ rendered_shortcut = palette_item.shortcut or ""
144
+ item = QTreeWidgetItem(
145
+ (palette_item.label, rendered_shortcut)
146
+ )
147
+ item.setData(0, Qt.UserRole, palette_item.action_id)
148
+ item.setIcon(0, action.icon())
149
+ item.setToolTip(0, palette_item.tooltip)
150
+ item.setData(
151
+ 0,
152
+ Qt.AccessibleTextRole,
153
+ (
154
+ palette_item.accessible_name
155
+ + (
156
+ f", shortcut {rendered_shortcut}"
157
+ if rendered_shortcut
158
+ else ""
159
+ )
160
+ ),
161
+ )
162
+ enabled = palette_item.enabled and action.isEnabled()
163
+ item.setDisabled(not enabled)
164
+ self.results.addTopLevelItem(item)
165
+ visible_ids.append(palette_item.action_id)
166
+ if enabled and first_enabled is None:
167
+ first_enabled = item
168
+
169
+ self._visible_action_ids = frozenset(visible_ids)
170
+ if first_enabled is not None:
171
+ self.results.setCurrentItem(first_enabled)
172
+ shown = len(projection.items)
173
+ if projection.truncated:
174
+ count = f"{shown} of {projection.total_count}"
175
+ else:
176
+ count = str(shown)
177
+ self.count_label.setText(count)
178
+ self.count_label.setAccessibleDescription(
179
+ f"{shown} matching action" + ("" if shown == 1 else "s")
180
+ )
181
+ self.results.setVisible(bool(projection.items))
182
+ self.empty_label.setVisible(not projection.items)
183
+
184
+ def eventFilter(self, watched, event) -> bool: # noqa: N802 - Qt API
185
+ if (
186
+ watched in (self.query_edit, self.results)
187
+ and event.type() == QEvent.KeyPress
188
+ ):
189
+ key = event.key()
190
+ if key == Qt.Key_Down:
191
+ self._move_selection(1)
192
+ event.accept()
193
+ return True
194
+ if key == Qt.Key_Up:
195
+ self._move_selection(-1)
196
+ event.accept()
197
+ return True
198
+ if key in (Qt.Key_Return, Qt.Key_Enter):
199
+ self._activate_item(self.results.currentItem(), 0)
200
+ event.accept()
201
+ return True
202
+ if key == Qt.Key_Escape:
203
+ self.reject()
204
+ event.accept()
205
+ return True
206
+ return super().eventFilter(watched, event)
207
+
208
+ def _enabled_items(self) -> tuple[QTreeWidgetItem, ...]:
209
+ return tuple(
210
+ item
211
+ for row in range(self.results.topLevelItemCount())
212
+ for item in (self.results.topLevelItem(row),)
213
+ if not item.isDisabled()
214
+ and isinstance(item.data(0, Qt.UserRole), str)
215
+ )
216
+
217
+ def _move_selection(self, step: int) -> None:
218
+ choices = self._enabled_items()
219
+ if not choices:
220
+ return
221
+ current = self.results.currentItem()
222
+ try:
223
+ index = choices.index(current)
224
+ except ValueError:
225
+ index = -1 if step > 0 else 0
226
+ self.results.setCurrentItem(choices[(index + step) % len(choices)])
227
+ self.results.scrollToItem(self.results.currentItem())
228
+
229
+ def _activate_item(
230
+ self,
231
+ item: QTreeWidgetItem | None,
232
+ _column: int,
233
+ ) -> None:
234
+ if item is None or item.isDisabled():
235
+ return
236
+ action_id = item.data(0, Qt.UserRole)
237
+ if (
238
+ not isinstance(action_id, str)
239
+ or action_id not in self._visible_action_ids
240
+ ):
241
+ return
242
+ action = self._registry.action(action_id)
243
+ if not action.isEnabled():
244
+ return
245
+ self._invoked_action_id = action_id
246
+ self.accept()
247
+ action.trigger()
248
+
249
+
250
+ def open_command_palette(
251
+ owner: QWidget,
252
+ registry: QtActionRegistry,
253
+ states: Mapping[str, ActionState],
254
+ ) -> str | None:
255
+ """Open the declared-action palette and return its invoked action ID."""
256
+
257
+ dialog = CommandPaletteDialog(owner, registry, states)
258
+ dialog.exec_()
259
+ return dialog.invoked_action_id
260
+
261
+
262
+ def open_go_to_line(editor, owner: QWidget | None = None) -> int | None:
263
+ """Prompt for and reveal a bounded document line without copying source."""
264
+
265
+ document = editor.document()
266
+ maximum = max(1, int(document.blockCount()))
267
+ current = min(
268
+ maximum,
269
+ max(1, int(editor.textCursor().blockNumber()) + 1),
270
+ )
271
+ line, accepted = QInputDialog.getInt(
272
+ owner or editor,
273
+ "Go to Line",
274
+ "Line:",
275
+ current,
276
+ 1,
277
+ maximum,
278
+ 1,
279
+ )
280
+ if not accepted:
281
+ return None
282
+ block = document.findBlockByNumber(line - 1)
283
+ if not block.isValid():
284
+ return None
285
+ cursor = editor.textCursor()
286
+ cursor.setPosition(block.position())
287
+ editor.setTextCursor(cursor)
288
+ editor.centerCursor()
289
+ editor.setFocus()
290
+ return line
291
+
292
+
293
+ __all__ = [
294
+ "CommandPaletteDialog",
295
+ "open_command_palette",
296
+ "open_go_to_line",
297
+ ]
@@ -0,0 +1,220 @@
1
+ """Headless-safe value and position contracts shared by the Qt workspace.
2
+
3
+ This module deliberately contains no direct PyQt imports. Keeping the
4
+ bounded settings readers' constants and source-position translations here
5
+ lets the desktop modules remain cohesive without weakening defensive
6
+ ``pycforge.ide.qt`` import safety if an installation is damaged.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from bisect import bisect_right
12
+ from typing import Any
13
+
14
+ from .editor import qt_position_length
15
+ from .positions import TextPositionIndex
16
+
17
+
18
+ SETTINGS_SCHEMA_VERSION = 1
19
+ MAX_SETTINGS_BLOB_BYTES = 1_048_576
20
+ MAX_SETTINGS_PATH_CHARS = 4096
21
+ MAX_RECENT_PATHS = 10
22
+ SETTINGS_ORGANIZATION = "PyCForge"
23
+ SETTINGS_APPLICATION = "PyCForge"
24
+ PRESENTATION_SETTING_KEYS = (
25
+ "window/geometry",
26
+ "window/state",
27
+ "splitter/workspace",
28
+ "splitter/editors",
29
+ "splitter/main",
30
+ "splitter/source",
31
+ "view/bundle",
32
+ "view/generated_c",
33
+ "view/details",
34
+ "view/source_split",
35
+ "view/whitespace",
36
+ "workspace/last_directory",
37
+ "workspace/recent_paths",
38
+ )
39
+
40
+
41
+ def coerce_settings_schema_version(value: Any) -> int | None:
42
+ """Return a bounded decimal settings version or ``None``."""
43
+
44
+ if isinstance(value, bool):
45
+ return None
46
+ if isinstance(value, int):
47
+ return value
48
+ if (
49
+ isinstance(value, str)
50
+ and len(value) <= 16
51
+ and value.isascii()
52
+ and value.isdigit()
53
+ ):
54
+ return int(value)
55
+ return None
56
+
57
+
58
+ def line_column_offset(
59
+ text: str,
60
+ line: int,
61
+ column: int,
62
+ index: TextPositionIndex | None = None,
63
+ ) -> int:
64
+ """Translate a one-based line and zero-based column to a character offset."""
65
+
66
+ if index is not None and index.text_length == len(text):
67
+ return index.character_offset(line, column)
68
+ if not isinstance(line, int) or not isinstance(column, int):
69
+ return 0
70
+ if line < 1:
71
+ return 0
72
+ lines = text.splitlines(keepends=True)
73
+ if not lines:
74
+ return 0
75
+ if line > len(lines):
76
+ return len(text)
77
+ prefix = sum(len(value) for value in lines[: line - 1])
78
+ return min(len(text), prefix + min(max(0, column), len(lines[line - 1])))
79
+
80
+
81
+ def diagnostic_character_range(
82
+ diagnostic: dict[str, Any],
83
+ text: str,
84
+ index: TextPositionIndex | None = None,
85
+ ) -> tuple[int, int]:
86
+ """Return a clipped character range for a serialized diagnostic."""
87
+
88
+ span = diagnostic.get("source_span") or {}
89
+ start_data = span.get("start") or {}
90
+ end_data = span.get("end") or {}
91
+ start = start_data.get("offset")
92
+ end = end_data.get("offset")
93
+ if not isinstance(start, int):
94
+ start = line_column_offset(
95
+ text,
96
+ start_data.get("line", 1),
97
+ start_data.get("column", 0),
98
+ index,
99
+ )
100
+ if not isinstance(end, int):
101
+ end = line_column_offset(
102
+ text,
103
+ end_data.get("line", start_data.get("line", 1)),
104
+ end_data.get("column", start_data.get("column", 0) + 1),
105
+ index,
106
+ )
107
+ start = min(len(text), max(0, start))
108
+ end = min(len(text), max(start, end))
109
+ if end == start and start < len(text):
110
+ end += 1
111
+ return start, end
112
+
113
+
114
+ def mapping_character_range(
115
+ mapping: dict[str, Any],
116
+ text: str,
117
+ index: TextPositionIndex | None = None,
118
+ ) -> tuple[int, int]:
119
+ """Return a renderer mapping range without confusing UTF-8 bytes and chars."""
120
+
121
+ start = line_column_offset(
122
+ text,
123
+ mapping.get("start_line", 1),
124
+ mapping.get("start_column", 0),
125
+ index,
126
+ )
127
+ end = line_column_offset(
128
+ text,
129
+ mapping.get("end_line", mapping.get("start_line", 1)),
130
+ mapping.get("end_column", mapping.get("start_column", 0)),
131
+ index,
132
+ )
133
+ if end == start and start < len(text):
134
+ end += 1
135
+ return start, end
136
+
137
+
138
+ def python_offset_to_qt_position(
139
+ text: str,
140
+ offset: int,
141
+ index: TextPositionIndex | None = None,
142
+ ) -> int:
143
+ """Convert a Python code-point offset to a Qt UTF-16 cursor position."""
144
+
145
+ if not isinstance(offset, int):
146
+ raise TypeError("source offset must be an integer")
147
+ clipped = min(len(text), max(0, offset))
148
+ if index is not None and index.text_length == len(text):
149
+ return index.qt_position(text, clipped)
150
+ return qt_position_length(text[:clipped])
151
+
152
+
153
+ def qt_position_to_python_offset(
154
+ text: str,
155
+ position: int,
156
+ index: TextPositionIndex | None = None,
157
+ ) -> int:
158
+ """Convert a clamped Qt UTF-16 position to a Python code-point offset."""
159
+
160
+ if not isinstance(position, int):
161
+ raise TypeError("Qt source position must be an integer")
162
+ target = max(0, position)
163
+ if index is not None and index.text_length == len(text):
164
+ if index.utf16_compatible:
165
+ return min(len(text), target)
166
+ line_number = max(
167
+ 0, bisect_right(index.utf16_line_starts, target) - 1
168
+ )
169
+ start = index.line_starts[line_number]
170
+ end = (
171
+ index.line_starts[line_number + 1]
172
+ if line_number + 1 < index.line_count
173
+ else len(text)
174
+ )
175
+ target -= index.utf16_line_starts[line_number]
176
+ else:
177
+ start, end = 0, len(text)
178
+ units = 0
179
+ offset = start
180
+ for character in text[start:end]:
181
+ width = 2 if ord(character) > 0xFFFF else 1
182
+ if units + width > target:
183
+ break
184
+ units += width
185
+ offset += 1
186
+ if units == target:
187
+ break
188
+ return offset
189
+
190
+
191
+ def qt_range(
192
+ text: str,
193
+ start: int,
194
+ end: int,
195
+ index: TextPositionIndex | None = None,
196
+ ) -> tuple[int, int]:
197
+ if index is not None and index.text_length == len(text):
198
+ return index.qt_range(text, start, end)
199
+ return (
200
+ python_offset_to_qt_position(text, start, index),
201
+ python_offset_to_qt_position(text, end, index),
202
+ )
203
+
204
+
205
+ __all__ = [
206
+ "MAX_RECENT_PATHS",
207
+ "MAX_SETTINGS_BLOB_BYTES",
208
+ "MAX_SETTINGS_PATH_CHARS",
209
+ "PRESENTATION_SETTING_KEYS",
210
+ "SETTINGS_APPLICATION",
211
+ "SETTINGS_ORGANIZATION",
212
+ "SETTINGS_SCHEMA_VERSION",
213
+ "coerce_settings_schema_version",
214
+ "diagnostic_character_range",
215
+ "line_column_offset",
216
+ "mapping_character_range",
217
+ "python_offset_to_qt_position",
218
+ "qt_position_to_python_offset",
219
+ "qt_range",
220
+ ]