From fc669b13a25123bb170739b5f6ce957009fc3ed8 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 21 Jan 2020 15:36:50 -0500 Subject: [PATCH] internal/lsp: eliminate getFileLocked function Apparently, the convention is to name something "Locked" if the implementation is mutex is already locked when the function is called. Turns out there were no callers of getFileLocked anyway, so just delete that function and rename to getFile. Change-Id: Ia7a9a620c3eb8eb0ce6b0a44ddb2ed62a604484d Reviewed-on: https://go-review.googlesource.com/c/tools/+/215737 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/cache/session.go | 2 +- internal/lsp/cache/snapshot.go | 2 +- internal/lsp/cache/view.go | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index aece595d2c..d421b34fcf 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -279,7 +279,7 @@ func (s *session) DidModifyFile(ctx context.Context, c source.FileModification) } } // Make sure that the file is added to the view. - f, err := view.getFileLocked(c.URI) + f, err := view.getFile(c.URI) if err != nil { return nil, err } diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index d24c9bc720..f2d660203d 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -533,7 +533,7 @@ func (s *snapshot) getFileURIs() []span.URI { // GetFile returns a File for the given URI. It will always succeed because it // adds the file to the managed set if needed. func (s *snapshot) GetFile(uri span.URI) (source.FileHandle, error) { - f, err := s.view.getFileLocked(uri) + f, err := s.view.getFile(uri) if err != nil { return nil, err } diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index c43d986cf0..1bb84c8f49 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -403,17 +403,12 @@ func (v *view) knownFile(uri span.URI) bool { return f != nil && err == nil } -// getFileLocked returns a File for the given URI. It will always succeed because it +// getFile returns a file for the given URI. It will always succeed because it // adds the file to the managed set if needed. -func (v *view) getFileLocked(uri span.URI) (*fileBase, error) { +func (v *view) getFile(uri span.URI) (*fileBase, error) { v.mu.Lock() defer v.mu.Unlock() - return v.getFile(uri) -} - -// getFile is the unlocked internal implementation of GetFile. -func (v *view) getFile(uri span.URI) (*fileBase, error) { f, err := v.findFile(uri) if err != nil { return nil, err