mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-18 23:07:13 +09:00
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package lsp
|
|
|
|
import (
|
|
lsp "go.lsp.dev/protocol"
|
|
"go.lsp.dev/uri"
|
|
)
|
|
|
|
func (s *Server) DidOpen(filename, language, text string, version uint64) {
|
|
doc := lsp.TextDocumentItem{
|
|
URI: uri.File(filename),
|
|
LanguageID: lsp.LanguageIdentifier(language),
|
|
Version: float64(version), // not sure why this is a float on go.lsp.dev
|
|
Text: text,
|
|
}
|
|
|
|
params := lsp.DidOpenTextDocumentParams{
|
|
TextDocument: doc,
|
|
}
|
|
|
|
go s.sendNotification(lsp.MethodTextDocumentDidOpen, params)
|
|
}
|
|
|
|
func (s *Server) DidSave(filename string) {
|
|
doc := lsp.TextDocumentIdentifier{
|
|
URI: uri.File(filename),
|
|
}
|
|
|
|
params := lsp.DidSaveTextDocumentParams{
|
|
TextDocument: doc,
|
|
}
|
|
go s.sendNotification(lsp.MethodTextDocumentDidSave, params)
|
|
}
|
|
|
|
func (s *Server) DidChange(filename string, version uint64, changes []lsp.TextDocumentContentChangeEvent) {
|
|
doc := lsp.VersionedTextDocumentIdentifier{
|
|
TextDocumentIdentifier: lsp.TextDocumentIdentifier{
|
|
URI: uri.File(filename),
|
|
},
|
|
Version: &version,
|
|
}
|
|
|
|
params := lsp.DidChangeTextDocumentParams{
|
|
TextDocument: doc,
|
|
ContentChanges: changes,
|
|
}
|
|
go s.sendNotification(lsp.MethodTextDocumentDidChange, params)
|
|
}
|
|
|
|
func (s *Server) DidClose(filename string) {
|
|
doc := lsp.TextDocumentIdentifier{
|
|
URI: uri.File(filename),
|
|
}
|
|
|
|
params := lsp.DidCloseTextDocumentParams{
|
|
TextDocument: doc,
|
|
}
|
|
go s.sendNotification(lsp.MethodTextDocumentDidClose, params)
|
|
}
|