glsp

package module
v0.0.0-...-8b29be5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

This is an early release. Some features are not yet fully implemented.

copy from github.com/tliron/glsp commit d103e570103611226647f6a13e30f0c58a6a2a8c

GLSP

License Latest Release Go Report Card

Language Server Protocol SDK for Go.

It enables you to more easily implement language servers by writing them in Go. GLSP contains:

  1. all the message structures for easy serialization,
  2. a handler for all client methods, and
  3. a ready-to-run JSON-RPC 2.0 server supporting stdio, TCP, WebSockets, and Node.js IPC.

All you need to do, then, is provide the features for the language you want to support.

Projects using GLSP:

References

  • go-lsp is another implementation with reduced coverage of the protocol

Minimal Example

package main

import (
	"github.com/tliron/glsp"
	protocol "github.com/tliron/glsp/protocol_3_16"
	"github.com/tliron/glsp/server"
	"github.com/tliron/kutil/logging"

	// Must include a backend implementation. See kutil's logging/ for other options.
	_ "github.com/tliron/kutil/logging/simple"
)

const lsName = "my language"

var version string = "0.0.1"
var handler protocol.Handler

func main() {
	// Must configure logging before using server. Note that the import of a backend
	// is required as well.
	// See kutil's logging.Backend for Configure() param details.
	logging.Configure(1, nil)

	handler = protocol.Handler{
		Initialize:  initialize,
		Initialized: initialized,
		Shutdown:    shutdown,
		SetTrace:    setTrace,
	}

	server := server.NewServer(&handler, lsName, false)

	server.RunStdio()
}

func initialize(context *glsp.Context, params *protocol.InitializeParams) (interface{}, 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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallFunc

type CallFunc func(method string, params interface{}, result interface{})

type Context

type Context struct {
	Method string
	Params json.RawMessage
	Notify NotifyFunc
	Call   CallFunc
}

type Handler

type Handler interface {
	Handle(context *Context) (r interface{}, validMethod bool, validParams bool, err error)
}

type NotifyFunc

type NotifyFunc func(method string, params interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL