this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lsp/server: remove mutex

In https://cue.gerrithub.io/c/cue-lang/cue/+/1232174 or
08f7d61dd8b03080fc31be8f5b4e726df5b8d299 we added a mutex to protect
server state, in recognition that we would soon have multiple
concurrent go-routines working the LSP server.

That approach with a mutex is poor; in practice, although safe, it
doesn't interact with some editors particularly nicely. Better is
possible, so here we mainly revert the above commit, and remove the
mutex.

Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: Ibd1be55cfd4b350ee18abf1cec179853cc9c3346
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1233639
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

-68
-3
internal/lsp/server/codeaction.go
··· 33 33 } 34 34 35 35 func (s *server) CodeAction(ctx context.Context, params *protocol.CodeActionParams) ([]protocol.CodeAction, error) { 36 - s.lock.Lock() 37 - defer s.lock.Unlock() 38 - 39 36 var codeActions []protocol.CodeAction 40 37 41 38 convertToStructEdit, err := s.workspace.CodeActionConvertToStruct(ctx, params)
-18
internal/lsp/server/eval.go
··· 22 22 ) 23 23 24 24 func (s *server) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) { 25 - s.lock.Lock() 26 - defer s.lock.Unlock() 27 - 28 25 uri := params.TextDocument.URI 29 26 w := s.workspace 30 27 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadNothing) ··· 35 32 } 36 33 37 34 func (s *server) Completion(ctx context.Context, params *protocol.CompletionParams) (*protocol.CompletionList, error) { 38 - s.lock.Lock() 39 - defer s.lock.Unlock() 40 - 41 35 uri := params.TextDocument.URI 42 36 w := s.workspace 43 37 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadAllIfNonCue) ··· 48 42 } 49 43 50 44 func (s *server) Hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) { 51 - s.lock.Lock() 52 - defer s.lock.Unlock() 53 - 54 45 uri := params.TextDocument.URI 55 46 w := s.workspace 56 47 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadAllIfNonCue) ··· 61 52 } 62 53 63 54 func (s *server) References(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, error) { 64 - s.lock.Lock() 65 - defer s.lock.Unlock() 66 - 67 55 uri := params.TextDocument.URI 68 56 w := s.workspace 69 57 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadAll) ··· 74 62 } 75 63 76 64 func (s *server) Rename(ctx context.Context, params *protocol.RenameParams) (*protocol.WorkspaceEdit, error) { 77 - s.lock.Lock() 78 - defer s.lock.Unlock() 79 - 80 65 uri := params.TextDocument.URI 81 66 w := s.workspace 82 67 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadAll) ··· 87 72 } 88 73 89 74 func (s *server) PrepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (*protocol.PrepareRenamePlaceholder, error) { 90 - s.lock.Lock() 91 - defer s.lock.Unlock() 92 - 93 75 uri := params.TextDocument.URI 94 76 w := s.workspace 95 77 file, fe, srcMapper, err := w.FileEvaluatorForURI(uri, cache.LoadAll)
-3
internal/lsp/server/file.go
··· 21 21 ) 22 22 23 23 func (s *server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]any, error) { 24 - s.lock.Lock() 25 - defer s.lock.Unlock() 26 - 27 24 root := s.workspace.DocumentSymbols(params.TextDocument.URI) 28 25 if len(root) == 0 { 29 26 return nil, nil
-3
internal/lsp/server/format.go
··· 25 25 // 26 26 // Formatting implements [protocol.Server] 27 27 func (s *server) Formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error) { 28 - s.lock.Lock() 29 - defer s.lock.Unlock() 30 - 31 28 _, done := event.Start(ctx, "lsp.Server.formatting", tag.URI.Of(params.TextDocument.URI)) 32 29 defer done() 33 30
-6
internal/lsp/server/initialize.go
··· 50 50 // 51 51 // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize 52 52 func (s *server) Initialize(ctx context.Context, params *protocol.ParamInitialize) (*protocol.InitializeResult, error) { 53 - s.lock.Lock() 54 - defer s.lock.Unlock() 55 - 56 53 ctx, done := event.Start(ctx, "lsp.Server.initialize") 57 54 defer done() 58 55 ··· 150 147 // 151 148 // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialized 152 149 func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error { 153 - s.lock.Lock() 154 - defer s.lock.Unlock() 155 - 156 150 ctx, done := event.Start(ctx, "lsp.Server.initialized") 157 151 defer done() 158 152
-14
internal/lsp/server/server.go
··· 11 11 "fmt" 12 12 "os" 13 13 "strconv" 14 - "sync" 15 14 "sync/atomic" 16 15 17 16 "cuelang.org/go/internal/golangorgx/gopls/progress" ··· 80 79 type server struct { 81 80 id string 82 81 83 - // lock must be held for every public API method, and protects all 84 - // state within the server. 85 - lock sync.Mutex 86 - 87 82 client protocol.ClientCloser 88 83 cache *cache.Cache 89 84 workspace *cache.Workspace ··· 118 113 // sent, instead it should wait for an exit message, which is 119 114 // asynchronous. 120 115 func (s *server) Shutdown(ctx context.Context) error { 121 - s.lock.Lock() 122 - defer s.lock.Unlock() 123 - 124 116 ctx, done := event.Start(ctx, "lsp.Server.shutdown") 125 117 defer done() 126 118 ··· 147 139 // 148 140 // This is asynchronous - it does not get a response. 149 141 func (s *server) Exit(ctx context.Context) error { 150 - s.lock.Lock() 151 - defer s.lock.Unlock() 152 - 153 142 _, done := event.Start(ctx, "lsp.Server.exit") 154 143 defer done() 155 144 ··· 167 156 // WorkDoneProgressCancel is a message from the editor/client 168 157 // requesting the cancellation of a long-running process. 169 158 func (s *server) WorkDoneProgressCancel(ctx context.Context, params *protocol.WorkDoneProgressCancelParams) error { 170 - s.lock.Lock() 171 - defer s.lock.Unlock() 172 - 173 159 ctx, done := event.Start(ctx, "lsp.Server.workDoneProgressCancel") 174 160 defer done() 175 161
-15
internal/lsp/server/text_synchronization.go
··· 83 83 } 84 84 85 85 func (s *server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error { 86 - s.lock.Lock() 87 - defer s.lock.Unlock() 88 - 89 86 ctx, done := event.Start(ctx, "lsp.Server.didOpen", tag.URI.Of(params.TextDocument.URI)) 90 87 defer done() 91 88 ··· 107 104 } 108 105 109 106 func (s *server) DidChange(ctx context.Context, params *protocol.DidChangeTextDocumentParams) error { 110 - s.lock.Lock() 111 - defer s.lock.Unlock() 112 - 113 107 ctx, done := event.Start(ctx, "lsp.Server.didChange", tag.URI.Of(params.TextDocument.URI)) 114 108 defer done() 115 109 ··· 123 117 } 124 118 125 119 func (s *server) DidChangeWatchedFiles(ctx context.Context, params *protocol.DidChangeWatchedFilesParams) error { 126 - s.lock.Lock() 127 - defer s.lock.Unlock() 128 - 129 120 ctx, done := event.Start(ctx, "lsp.Server.didChangeWatchedFiles") 130 121 defer done() 131 122 ··· 141 132 } 142 133 143 134 func (s *server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error { 144 - s.lock.Lock() 145 - defer s.lock.Unlock() 146 - 147 135 ctx, done := event.Start(ctx, "lsp.Server.didClose", tag.URI.Of(params.TextDocument.URI)) 148 136 defer done() 149 137 ··· 155 143 } 156 144 157 145 func (s *server) DidSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error { 158 - s.lock.Lock() 159 - defer s.lock.Unlock() 160 - 161 146 ctx, done := event.Start(ctx, "lsp.Server.didSave", tag.URI.Of(params.TextDocument.URI)) 162 147 defer done() 163 148
-6
internal/lsp/server/workspace.go
··· 54 54 } 55 55 56 56 func (s *server) DidChangeWorkspaceFolders(ctx context.Context, params *protocol.DidChangeWorkspaceFoldersParams) error { 57 - s.lock.Lock() 58 - defer s.lock.Unlock() 59 - 60 57 for _, folder := range params.Event.Removed { 61 58 dir, err := protocol.ParseDocumentURI(folder.URI) 62 59 if err != nil { ··· 77 74 } 78 75 79 76 func (s *server) DidChangeConfiguration(ctx context.Context, _ *protocol.DidChangeConfigurationParams) error { 80 - s.lock.Lock() 81 - defer s.lock.Unlock() 82 - 83 77 ctx, done := event.Start(ctx, "lsp.Server.didChangeConfiguration") 84 78 defer done() 85 79