Skip to content

Conversation

liznear
Copy link
Contributor

@liznear liznear commented Aug 9, 2025

Describe your changes

Return a copy of lsp diagnostics in GetDiagnostics to avoid data race.

Previously, the internal map is returned directly. Other goroutines can read it without lock.

Related issue/discussion:

Checklist before requesting a review

If this is a feature

  • I have created a discussion
  • A project maintainer has approved this feature request. Link to comment:

@liznear liznear requested a review from kujtimiihoxha as a code owner August 9, 2025 08:10
@charmcli
Copy link
Contributor

charmcli commented Aug 9, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@liznear
Copy link
Contributor Author

liznear commented Aug 9, 2025

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@liznear liznear force-pushed the lsp-diagnostics-race branch from 60ff41f to a7d5428 Compare August 9, 2025 08:16
defer c.diagnosticsMu.RUnlock()

diagnostics := make(map[protocol.DocumentURI][]protocol.Diagnostic, len(c.diagnostics))
maps.Copy(diagnostics, c.diagnostics)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use maps.Clone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 5cc1a12

@liznear liznear requested a review from bbrodriges August 9, 2025 23:49
@caarlos0 caarlos0 merged commit f8da476 into charmbracelet:main Aug 14, 2025
10 checks passed
@caarlos0
Copy link
Member

Thanks!

scalabl3 pushed a commit to metaphori-ai/crush that referenced this pull request Aug 19, 2025
…racelet#681)

* fix(lsp): return a copy of lsp diagnostics to avoid data race

* Replace maps.Copy with maps.Clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fatal error: concurrent map iteration and map write
4 participants