Skip to content

Remove duplicated blocks from editor and LSP sources (2 of 4), fix a hang in LspEditorBridge - #32

Merged
drzo merged 2 commits into
mainfrom
claude/loving-archimedes-r7fcwy
Nov 21, 2026
Merged

drzo merged 2 commits into
mainfrom
claude/loving-archimedes-r7fcwy

Conversation

@drzo

@drzo drzo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)
  • Code refactoring

Related Issues

Related to #29 and #31

Changes Made

Refactor: duplicated blocks replaced by helpers, no suppression markers

  • 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.
  • 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.
  • The eight files are then formatted and made cpplint-clean.

Bug fix: LspEditorBridge hung when accepting a result

  • acceptCompletion, acceptDefinition, acceptReference and acceptSymbol each locked a mutex and then called the matching dismiss… function, which locks the same non-recursive mutex. Accepting a completion, definition, reference or symbol therefore hung the calling thread.
  • The lock is now released before the 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.sh passes.

  • 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

  • Three of the eight 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 when 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 is src/bolt/editor/lsp_client.cpp, which this PR does not touch.)
  • In the refactor, locks taken and their order are unchanged. Small reorderings that should not be observable: in documentChanged the language id is copied before the content is written rather than after; in updateEditorStoreDocument the content is read before the new document's path is set; document lookups now run a callback while holding documentsMutex_.

Generated by Claude Code

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
@drzo
drzo marked this pull request as ready for review November 21, 2026 18:12
Copilot AI balanced review requested due to automatic review settings November 21, 2026 18:12
@drzo
drzo merged commit 6833e38 into main Nov 21, 2026
53 of 54 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 5 potential issues.

Devin Review

std::string LspEditorBridge::acceptCompletion() {
std::lock_guard<std::mutex> lock(completionMutex_);
std::unique_lock<std::mutex> lock(completionMutex_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +357 to +358
// dismissCompletion() takes the same mutex, so release it first.
lock.unlock();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Missing tests for result acceptance

An empty popup never reaches dismissal. Regression coverage needs visible results for completions, definitions, references, and symbols, with assertions for the returned selection and cleared state.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


std::string insertText = completionState_.items[completionState_.selectedIndex].insertText;
// dismissCompletion() takes the same mutex, so release it first.
lock.unlock();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +488 to +494
// 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +14 to +20
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 = {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Conflicting indentation rules for contributors

The new helper bodies follow the formatter’s four-space setting. The contribution guide calls for two spaces.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +357 to 359
// dismissCompletion() takes the same mutex, so release it first.
lock.unlock();
dismissCompletion();
Comment on lines +674 to 676
// dismissDefinition() takes the same mutex, so release it first.
lock.unlock();
dismissDefinition();
Comment on lines +729 to 731
// dismissReferences() takes the same mutex, so release it first.
lock.unlock();
dismissReferences();
Comment on lines +853 to 855
// dismissSymbolOutline() takes the same mutex, so release it first.
lock.unlock();
dismissSymbolOutline();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants