Shutdown lsp servers

This commit is contained in:
Zachary Yedidia
2020-08-12 21:15:17 -04:00
parent eb5c123674
commit c822a16596
3 changed files with 22 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ import (
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/clipboard"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/lsp"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/shell"
@@ -218,6 +219,8 @@ func LoadInput(args []string) []*buffer.Buffer {
func main() {
defer func() {
lsp.ShutdownAllServers()
if util.Stdout.Len() > 0 {
fmt.Fprint(os.Stdout, util.Stdout.String())
}

View File

@@ -17,7 +17,7 @@ func (s *Server) DidOpen(filename, language, text string, version *uint64) {
TextDocument: doc,
}
go s.sendNotification("textDocument/didOpen", params)
go s.sendNotification(lsp.MethodTextDocumentDidOpen, params)
}
func (s *Server) DidSave(filename string) {
@@ -28,7 +28,7 @@ func (s *Server) DidSave(filename string) {
params := lsp.DidSaveTextDocumentParams{
TextDocument: doc,
}
go s.sendNotification("textDocument/didSave", params)
go s.sendNotification(lsp.MethodTextDocumentDidSave, params)
}
func (s *Server) DidChange(filename string, version *uint64, changes []lsp.TextDocumentContentChangeEvent) {
@@ -43,7 +43,7 @@ func (s *Server) DidChange(filename string, version *uint64, changes []lsp.TextD
TextDocument: doc,
ContentChanges: changes,
}
go s.sendNotification("textDocument/didChange", params)
go s.sendNotification(lsp.MethodTextDocumentDidChange, params)
}
func (s *Server) DidClose(filename string) {
@@ -54,5 +54,5 @@ func (s *Server) DidClose(filename string) {
params := lsp.DidCloseTextDocumentParams{
TextDocument: doc,
}
go s.sendNotification("textDocument/didClose", params)
go s.sendNotification(lsp.MethodTextDocumentDidClose, params)
}

View File

@@ -28,6 +28,12 @@ func GetServer(l Language, dir string) *Server {
return activeServers[l.Command+"-"+dir]
}
func ShutdownAllServers() {
for _, s := range activeServers {
s.Shutdown()
}
}
type Server struct {
cmd *exec.Cmd
stdin io.WriteCloser
@@ -145,7 +151,7 @@ func (s *Server) Initialize(directory string) {
s.lock.Lock()
go func() {
resp, err := s.sendRequest("initialize", params)
resp, err := s.sendRequest(lsp.MethodInitialize, params)
if err != nil {
log.Println("[micro-lsp]", err)
s.Active = false
@@ -160,7 +166,7 @@ func (s *Server) Initialize(directory string) {
json.Unmarshal(resp, &r)
s.lock.Unlock()
err = s.sendNotification("initialized", struct{}{})
err = s.sendNotification(lsp.MethodInitialized, struct{}{})
if err != nil {
log.Println("[micro-lsp]", err)
}
@@ -169,6 +175,11 @@ func (s *Server) Initialize(directory string) {
}()
}
func (s *Server) Shutdown() {
s.sendRequest(lsp.MethodShutdown, nil)
s.sendNotification(lsp.MethodExit, nil)
}
func (s *Server) receive() {
for s.Active {
resp, err := s.receiveMessage()
@@ -191,9 +202,9 @@ func (s *Server) receive() {
}
switch r.Method {
case "window/logMessage":
case lsp.MethodWindowLogMessage:
// TODO
case "textDocument/publishDiagnostics":
case lsp.MethodTextDocumentPublishDiagnostics:
// TODO
case "":
// Response