Skip to content

[FIX] Make code lock more resilient - #142

Closed
samuel-olivier wants to merge 3 commits into
mainfrom
fix-make-error-lock-more-resilient
Closed

[FIX] Make code lock more resilient#142
samuel-olivier wants to merge 3 commits into
mainfrom
fix-make-error-lock-more-resilient

Conversation

@samuel-olivier

Copy link
Copy Markdown
Contributor

Locked-code edits are rejected by returning no operations. Displaying the read-only tooltip (MessageController.showMessage) or a custom onError could throw instead — for example when editor contributions are already disposed. That exception aborted pushEditOperations, so typing failed even outside locked ranges.

This change:

  • Ignores a missing or disposed MessageController
  • Catches onError failures so the lock still returns [] without throwing
    Forbidden ranges stay read-only. The tooltip is skipped if it cannot be shown.

samuel-olivier and others added 3 commits September 2, 2026 15:25
…ions

MessageController can be missing or already disposed. Throwing from
showMessage aborted pushEditOperations and blocked typing.

Co-authored-by: Cursor <cursoragent@cursor.com>
A throwing custom onError aborted pushEditOperations. Catch it so
forbidden edits are still rejected without blocking the editor.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
expect(onDidChangeContent).not.toHaveBeenCalled()
})

test('Missing message contribution still rejects the locked edit without failing executeEdits', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what are we talking about exactly? 🤔

Comment thread src/tools.ts
messageContribution?.showMessage(errorMessage, operation.range.getStartPosition())
} catch {
// Contributions can be missing or already disposed (e.g. InstantiationService has been
// disposed). Never throw from onError: that aborts pushEditOperations and blocks typing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how can it be disposed?

Comment thread src/tools.ts
try {
const messageContribution = editor.getContribution('editor.contrib.messageController') as {
showMessage(message: string, position: monaco.IPosition): void
} | null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can even import the proper type from @codingame/monaco-vscode-api/vscode/vs/editor/contrib/message/browser/messageController I guess

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or event do MessageController.get(editor)

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.

2 participants