mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-24 01:37:15 +09:00
Shutdown lsp servers
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user