Skip to content

docs - add guidance for handling disposables#290336

Merged
bpasero merged 1 commit intomainfrom
ben/alone-spoonbill
Jan 26, 2026
Merged

docs - add guidance for handling disposables#290336
bpasero merged 1 commit intomainfrom
ben/alone-spoonbill

Conversation

@bpasero
Copy link
Copy Markdown
Member

@bpasero bpasero commented Jan 26, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 26, 2026 08:24
@bpasero bpasero enabled auto-merge (squash) January 26, 2026 08:24
@bpasero bpasero self-assigned this Jan 26, 2026
@vs-code-engineering vs-code-engineering bot added this to the January 2026 milestone Jan 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds repository-wide Copilot guidance for handling IDisposable lifetimes to reduce the risk of leaking resources when creating disposables in frequently called code paths.

Changes:

  • Adds a new “Code Quality” bullet describing how to register and manage disposables (DisposableStore, MutableDisposable, DisposableMap), including guidance for repeatedly-called methods.

- When adding file watching, prefer correlated file watchers (via fileService.createWatcher) to shared ones.
- When adding tooltips to UI elements, prefer the use of IHoverService service.
- Do not duplicate code. Always look for existing utility functions, helpers, or patterns in the codebase before implementing new functionality. Reuse and extend existing code whenever possible.
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeadedly to avoid leaks. Instead, return a `IDisposable` from such method and let the caller register it.
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

Typo: "repeadedly" should be "repeatedly".

Suggested change
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeadedly to avoid leaks. Instead, return a `IDisposable` from such method and let the caller register it.
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeatedly to avoid leaks. Instead, return a `IDisposable` from such method and let the caller register it.

Copilot uses AI. Check for mistakes.
- When adding file watching, prefer correlated file watchers (via fileService.createWatcher) to shared ones.
- When adding tooltips to UI elements, prefer the use of IHoverService service.
- Do not duplicate code. Always look for existing utility functions, helpers, or patterns in the codebase before implementing new functionality. Reuse and extend existing code whenever possible.
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeadedly to avoid leaks. Instead, return a `IDisposable` from such method and let the caller register it.
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

Grammar: "return a IDisposable from such method" should use the correct article and read more naturally (e.g., "return an IDisposable from such a method").

Suggested change
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeadedly to avoid leaks. Instead, return a `IDisposable` from such method and let the caller register it.
- You MUST deal with disposables by registering them immediately after creation for later disposal. Use helpers such as `DisposableStore`, `MutableDisposable` or `DisposableMap`. Do NOT register a disposable to the containing class if the object is created within a method that is called repeadedly to avoid leaks. Instead, return an `IDisposable` from such a method and let the caller register it.

Copilot uses AI. Check for mistakes.
@bpasero bpasero merged commit 05e03af into main Jan 26, 2026
28 checks passed
@bpasero bpasero deleted the ben/alone-spoonbill branch January 26, 2026 08:51
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants