Repository navigation
Remove duplicated blocks from editor and LSP sources (2 of 4), fix a hang in LspEditorBridge - #32
Conversation
Second batch of the files left unformatted because the copy/paste detector rejects them. Each duplicated block becomes a helper; no suppression markers are used. - command_history.hpp: getPreviousCommand / getNextCommand share stepHistory(). - debugger_interface.cpp: one breakpoint lookup instead of four, and one report_step_outcome() for the three step functions. - editor_pane.cpp: makeStoreDocument(). - lsp_editor_bridge.cpp: the six request functions share getConnectedClientForOpenDocument(); documentChanged / documentClosed share lookupOpenDocument(); toEditorLocation() for the two location callbacks. Locks taken and their order are unchanged. - split_view_manager.cpp: createSplit() behind the horizontal and vertical entry points. - syntax_highlighter.cpp: tokenizeWithRules(). - tab_bar.cpp: findTabById / findTabByPath and activateAdjacentTab(). - src/bolt/lsp/lsp_client.cpp: makePositionParams() and parseLocation(). Four headers gain the private declarations for the new members. Three of these files are not part of any build target and did not compile before this change (src/bolt/lsp/lsp_client.cpp, src/bolt/editor/syntax_highlighter.cpp, and command_history.hpp on its own); they show the same errors as before and no new ones. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71
acceptCompletion, acceptDefinition, acceptReference and acceptSymbol each locked their mutex and then called the matching dismiss function, which locks the same non-recursive mutex. Accepting a completion, a definition, a reference or a symbol therefore hung the calling thread. Release the lock before calling the dismiss function. The selected value is copied while the lock is held, as before. Found while refactoring this file; no test covered these paths. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71
| std::string LspEditorBridge::acceptCompletion() { | ||
| std::lock_guard<std::mutex> lock(completionMutex_); | ||
| std::unique_lock<std::mutex> lock(completionMutex_); |
There was a problem hiding this comment.
🔍 Demo bypasses bridge acceptance
The demo completion popup passes insert text directly to its accept callback. None of the four bridge acceptance methods has an in-tree caller.
Was this helpful? React with 👍 or 👎 to provide feedback.
| // dismissCompletion() takes the same mutex, so release it first. | ||
| lock.unlock(); |
There was a problem hiding this comment.
|
|
||
| std::string insertText = completionState_.items[completionState_.selectedIndex].insertText; | ||
| // dismissCompletion() takes the same mutex, so release it first. | ||
| lock.unlock(); |
There was a problem hiding this comment.
🔍 Acceptance can discard newer results
A future caller of acceptCompletion can clear a newer result that arrives between selection and dismissal. The message processor runs response callbacks on another thread. The same gap exists for definitions, references, and symbols.
Was this helpful? React with 👍 or 👎 to provide feedback.
| // Takes documentsMutex_, looks up filePath in openDocuments_, stores its language id in languageId and then | ||
| // calls visit (if any) on the entry with the lock still held. Returns false if the document is not open. | ||
| bool lookupOpenDocument(const std::string& filePath, std::string& languageId, | ||
| const std::function<void(OpenDocumentIterator)>& visit = nullptr); | ||
| // Returns the connected client for an open document, or nullptr if it is not open or has no connected client. | ||
| // Takes and releases documentsMutex_ before the client lookup. | ||
| LspClient* getConnectedClientForOpenDocument(const std::string& filePath); |
There was a problem hiding this comment.
🔍 New helper comments omit Doxygen markup
lookupOpenDocument and getConnectedClientForOpenDocument use plain comments for their lock contracts. The other extracted helpers follow the same pattern despite the documentation rule.
Was this helpful? React with 👍 or 👎 to provide feedback.
| EditorDocument makeStoreDocument(const EditorPane::PaneState& state, const std::string& content) { | ||
| EditorDocument newDoc; | ||
| newDoc.value = content; | ||
| newDoc.filePath = state.documentPath; | ||
| newDoc.scroll = {static_cast<int>(state.scrollLine), static_cast<int>(state.scrollColumn)}; | ||
| newDoc.cursor = {static_cast<size_t>(state.cursorLine), std::nullopt}; | ||
| newDoc.foldingRanges = {}; |
There was a problem hiding this comment.
🔍 Conflicting indentation rules for contributors
The new helper bodies follow the formatter’s four-space setting. The contribution guide calls for two spaces.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
🟡 Changes recommended
Accepting an old LSP result can clear a newer completion, definition, references list, or symbol outline because selection and dismissal are not atomic.
4 open issues
What changed in this PR
This second cleanup batch continues the formatting work from #29 and #31 by removing duplicated logic from editor and LSP components. It also addresses the hang when accepting LSP results.
Changes:
- Extracts shared helpers for editor navigation, document handling, debugger stepping, tokenization, and LSP requests.
- Adds private helper declarations and formats the affected C++ files for lint compliance.
- Changes locking in four LSP acceptance paths to avoid relocking the same non-recursive mutex.
| File | Description |
|---|---|
src/bolt/lsp/lsp_client.cpp |
Shares position-parameter construction and location parsing. |
src/bolt/editor/tab_bar.cpp |
Shares tab lookups and adjacent-tab navigation. |
src/bolt/editor/syntax_highlighter.cpp |
Extracts shared rule-based tokenization. |
src/bolt/editor/split_view_manager.cpp |
Unifies horizontal and vertical split creation. |
src/bolt/editor/lsp_editor_bridge.cpp |
Shares document/client lookups and location conversion; changes acceptance locking. |
src/bolt/editor/editor_pane.cpp |
Shares editor-store document construction. |
src/bolt/editor/debugger_interface.cpp |
Shares breakpoint lookup and step-outcome reporting. |
include/bolt/editor/tab_bar.hpp |
Declares the adjacent-tab navigation helper. |
include/bolt/editor/split_view_manager.hpp |
Declares the common split-creation helper. |
include/bolt/editor/lsp_editor_bridge.hpp |
Declares document lookup and connected-client helpers. |
include/bolt/editor/debugger_interface.hpp |
Declares the step-outcome reporting helper. |
include/bolt/editor/command_history.hpp |
Shares history traversal and updates formatting and the header guard. |
Review effort: Balanced
| // dismissCompletion() takes the same mutex, so release it first. | ||
| lock.unlock(); | ||
| dismissCompletion(); |
| // dismissDefinition() takes the same mutex, so release it first. | ||
| lock.unlock(); | ||
| dismissDefinition(); |
| // dismissReferences() takes the same mutex, so release it first. | ||
| lock.unlock(); | ||
| dismissReferences(); |
| // dismissSymbolOutline() takes the same mutex, so release it first. | ||
| lock.unlock(); | ||
| dismissSymbolOutline(); |

Description
Second of four pull requests that refactor the files left unformatted because the linter's copy/paste detector rejects them (the first was #31). This batch covers eight editor and LSP files. It also fixes a hang found while reading one of them.
Two commits, meant to be read separately: the refactor (no behaviour change intended) and the bug fix (a deliberate behaviour change).
Type of Change
Related Issues
Related to #29 and #31
Changes Made
Refactor: duplicated blocks replaced by helpers, no suppression markers
command_history.hpp:getPreviousCommand/getNextCommandsharestepHistory().debugger_interface.cpp: one breakpoint lookup instead of four, and onereport_step_outcome()for the three step functions.editor_pane.cpp:makeStoreDocument().lsp_editor_bridge.cpp: the six request functions sharegetConnectedClientForOpenDocument();documentChanged/documentClosedsharelookupOpenDocument();toEditorLocation()for the two location callbacks.split_view_manager.cpp:createSplit()behind the horizontal and vertical entry points.syntax_highlighter.cpp:tokenizeWithRules().tab_bar.cpp:findTabById/findTabByPathandactivateAdjacentTab().src/bolt/lsp/lsp_client.cpp:makePositionParams()andparseLocation().Bug fix:
LspEditorBridgehung when accepting a resultacceptCompletion,acceptDefinition,acceptReferenceandacceptSymboleach locked a mutex and then called the matchingdismiss…function, which locks the same non-recursive mutex. Accepting a completion, definition, reference or symbol therefore hung the calling thread.dismiss…call; the selected value is still copied while the lock is held.Testing
All existing tests pass
Locally on Linux (GCC): 98/98 CTest tests;
scripts/smoke_test.shpasses.clang-format 15.0.7, cpplint 1.6.1 and jscpd 3.5.3 report nothing on the changed files.
Not covered by a test: the four
accept…paths. No existing test calls them (which is how the hang went unnoticed), and this PR does not add one. The fix is by inspection.Reviewer Notes
src/bolt/lsp/lsp_client.cpp,src/bolt/editor/syntax_highlighter.cpp, andcommand_history.hppwhen compiled on its own. They show the same errors as before and no new ones, so their refactoring is checked by the linters and by reading only. (The LSP client that is actually built issrc/bolt/editor/lsp_client.cpp, which this PR does not touch.)documentChangedthe language id is copied before the content is written rather than after; inupdateEditorStoreDocumentthe content is read before the new document's path is set; document lookups now run a callback while holdingdocumentsMutex_.Generated by Claude Code