Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an LSP server command #3316

Merged
merged 25 commits into from
Sep 26, 2024
Merged

Add an LSP server command #3316

merged 25 commits into from
Sep 26, 2024

Conversation

mcy
Copy link
Member

@mcy mcy commented Sep 12, 2024

This PR adds a new command, buf beta lsp, which serves an LSP for Protobuf files.

Most of the code lives under buflsp. Currently, the LSP implements:

  • Parse and diagnose.
  • Format on save.
  • Go to definition, inc. go to definition of Buf dependencies.
  • Semantic highlighting.
  • Symbol tooltips.

Copy link
Contributor

github-actions bot commented Sep 12, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedSep 25, 2024, 4:46 PM

@mcy mcy changed the title Add an LSP server command. Add an LSP server command Sep 12, 2024
@mcy mcy marked this pull request as ready for review September 12, 2024 20:27
}

// newFiles creates a new file manager.
func newFiles(lsp *lsp) *fileManager {
Copy link
Member

Choose a reason for hiding this comment

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

newFileManager

private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/file.go Outdated Show resolved Hide resolved
@mcy mcy requested a review from doriable September 16, 2024 19:59
private/buf/buflsp/mutex.go Show resolved Hide resolved
private/buf/buflsp/mutex.go Outdated Show resolved Hide resolved
private/buf/buflsp/mutex.go Show resolved Hide resolved
private/buf/buflsp/mutex.go Outdated Show resolved Hide resolved
Copy link
Member

@bufdev bufdev left a comment

Choose a reason for hiding this comment

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

Oh my phone but don't forget changelog if we haven't done it


func (mu *mutex) storeWho(id uint64) {
for {
// This has to be a CAS loop to avoid races with a poisoning p.
Copy link
Contributor

@emcfarlane emcfarlane Sep 23, 2024

Choose a reason for hiding this comment

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

Not really. If you are unable to swap it's confirmed to be poisoned as the lock is always held.

if !mu.who.CompareAndSwap(0, id) {
	panic("buflsp/mutex.go: non-reentrant lock locked twice by the same request")
}

mu.storeWho(0)

mu.pool.check(id, mu, true)
mu.lock.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

The mu.lock.Unlock() should be deferred, as this never gets called on panic of storeWho. So go routines will still deadlock on line 150 as they wait for this Unlock. Although does this matter? Would only matter if using recovers.

Copy link
Member

Choose a reason for hiding this comment

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

@mcy can you check over all of your concurrency logic here before we merge?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah -- I think that's the crux of this, it seems to me that panic's are used under the assumption that we are crashing the program to avoid attempting to recover from bad code-patterns (and thus, hopefully, preventing us from merging bad patterns). That being said, deferring here to make the pattern with storeWho a little less fragile is probably a good thing.

// by the editor.
type fileManager struct {
lsp *lsp
table refcount.Map[protocol.URI, file]
Copy link
Member

Choose a reason for hiding this comment

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

@doriable can you do a pass on naming here? None of these names match our style

Copy link
Member

@doriable doriable left a comment

Choose a reason for hiding this comment

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

Add some comments around style/readability.

private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/buflsp.go Show resolved Hide resolved
private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/buflsp.go Outdated Show resolved Hide resolved
private/buf/buflsp/file.go Outdated Show resolved Hide resolved
private/buf/buflsp/file_manager.go Outdated Show resolved Hide resolved
private/buf/buflsp/mutex.go Outdated Show resolved Hide resolved
private/buf/buflsp/report.go Show resolved Hide resolved
private/buf/buflsp/report.go Outdated Show resolved Hide resolved
@mcy mcy merged commit 8c21639 into main Sep 26, 2024
11 checks passed
@mcy mcy deleted the mcy/lsp branch September 26, 2024 16:31
mcy added a commit that referenced this pull request Sep 26, 2024
@jpaju jpaju mentioned this pull request Oct 12, 2024
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