mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/tliron/commonlog"
|
|
"github.com/tliron/glsp"
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
"github.com/tliron/glsp/server"
|
|
|
|
// Must include a backend implementation
|
|
// See CommonLog for other options: https://github.com/tliron/commonlog
|
|
_ "github.com/tliron/commonlog/simple"
|
|
)
|
|
|
|
const lsName = "my language"
|
|
|
|
var (
|
|
version string = "0.0.1"
|
|
handler protocol.Handler
|
|
)
|
|
|
|
func main() {
|
|
// This increases logging verbosity (optional)
|
|
commonlog.Configure(1, nil)
|
|
|
|
handler = protocol.Handler{
|
|
Initialize: initialize,
|
|
Initialized: initialized,
|
|
Shutdown: shutdown,
|
|
SetTrace: setTrace,
|
|
TextDocumentCompletion: TextDocumentCompletion,
|
|
}
|
|
|
|
server := server.NewServer(&handler, lsName, false)
|
|
|
|
server.RunStdio()
|
|
}
|
|
|
|
func initialize(context *glsp.Context, params *protocol.InitializeParams) (any, error) {
|
|
capabilities := handler.CreateServerCapabilities()
|
|
|
|
return protocol.InitializeResult{
|
|
Capabilities: capabilities,
|
|
ServerInfo: &protocol.InitializeResultServerInfo{
|
|
Name: lsName,
|
|
Version: &version,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func initialized(context *glsp.Context, params *protocol.InitializedParams) error {
|
|
return nil
|
|
}
|
|
|
|
func shutdown(context *glsp.Context) error {
|
|
protocol.SetTraceValue(protocol.TraceValueOff)
|
|
return nil
|
|
}
|
|
|
|
func setTrace(context *glsp.Context, params *protocol.SetTraceParams) error {
|
|
protocol.SetTraceValue(params.Value)
|
|
return nil
|
|
}
|
|
|
|
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (interface{}, error) {
|
|
var completions []protocol.CompletionItem
|
|
|
|
Label := "happyface"
|
|
text := "Hello World!"
|
|
|
|
completions = append(completions, protocol.CompletionItem{
|
|
Label: Label,
|
|
Detail: &text,
|
|
InsertText: &text,
|
|
})
|
|
|
|
return completions, nil
|
|
}
|
|
|