langserver

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexFileName    = "index.html"
	NotFoundFileName = "404.html"
)
View Source
const (
	VersionCacheTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func NewFileServerWithStatus

func NewFileServerWithStatus(name string, code int) http.HandlerFunc

NewFileServerWithStatus returns http.Handler which serves specified file with desired HTTP status

func ServeFileWithStatus

func ServeFileWithStatus(rw http.ResponseWriter, r *http.Request, name string, code int)

ServeFileWithStatus serves file in HTTP response with specified HTTP status.

func ValidateContentLength

func ValidateContentLength(r *http.Request) error

ValidateContentLength validates Go code snippet size

func WrapHandler

func WrapHandler(h HandlerFunc, guards ...GuardFn) http.HandlerFunc

WrapHandler wraps handler

func WriteJSON

func WriteJSON(w http.ResponseWriter, i interface{})

WriteJSON encodes object as JSON and writes it to stdout

Types

type BackendVersionProvider

type BackendVersionProvider interface {
	GetVersions(ctx context.Context) (*VersionsInformation, error)
}

type BackendVersionService

type BackendVersionService struct {
	// contains filtered or unexported fields
}

BackendVersionService provides information about used Go versions for all backends.

func NewBackendVersionService

func NewBackendVersionService(logger *zap.Logger, client *goplay.Client, cacheTTL time.Duration) *BackendVersionService

func (*BackendVersionService) GetVersions

GetVersions provides Go version information for all backends.

type BuildResponse

type BuildResponse struct {
	// Formatted contains goimport'ed code
	Formatted string `json:"formatted,omitempty"`

	// FileName is file name
	FileName string `json:"fileName,omitempty"`
}

BuildResponse is code complile response

type ErrorResponse

type ErrorResponse struct {

	// Error is error message
	Error string `json:"error"`
	// contains filtered or unexported fields
}

ErrorResponse is error response

func NewErrorResponse

func NewErrorResponse(err error) *ErrorResponse

NewErrorResponse is ErrorResponse constructor

func (*ErrorResponse) Write

Write writes error to response

type GuardFn

type GuardFn func(r *http.Request) error

GuardFn is guard middleware handler

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

HTTPError is HTTP response error

func Errorf

func Errorf(code int, format string, args ...interface{}) *HTTPError

Errorf returns new formatted error

func NewHTTPError

func NewHTTPError(code int, err error) *HTTPError

NewHTTPError constructs a new error

func (*HTTPError) Error

func (err *HTTPError) Error() string

Error implements error

func (*HTTPError) Unwrap

func (err *HTTPError) Unwrap() error

Unwrap implements error

func (*HTTPError) WriteResponse

func (err *HTTPError) WriteResponse(rw http.ResponseWriter)

WriteResponse writes error to response

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

HandlerFunc is langserver request handler

type PlaygroundVersions

type PlaygroundVersions struct {
	// GoCurrent is a current Go version on Go playground.
	GoCurrent string `json:"current"`

	// GoPrevious is a previous Go version on Go playground.
	GoPrevious string `json:"goprev"`

	// GoTip is a dev branch Go version on Go playground.
	GoTip string `json:"gotip"`
}

PlaygroundVersions contains information about playground Go versions.

func (*PlaygroundVersions) SetBackendVersion

func (vers *PlaygroundVersions) SetBackendVersion(backend goplay.Backend, version string)

type RunResponse

type RunResponse struct {
	// Formatted contains goimport'ed code
	Formatted string `json:"formatted,omitempty"`

	// Events is list of code execution outputs
	Events []*goplay.CompileEvent `json:"events,omitempty"`
}

RunResponse is code run response

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is language server service

func New

func New(cfg ServiceConfig, client *goplay.Client, packages []*analyzer.Package, builder compiler.BuildService) *Service

New is Service constructor

func (*Service) HandleArtifactRequest

func (s *Service) HandleArtifactRequest(w http.ResponseWriter, r *http.Request) error

HandleArtifactRequest handles WASM build artifact request

func (*Service) HandleCompile

func (s *Service) HandleCompile(w http.ResponseWriter, r *http.Request) error

HandleCompile handles WASM build request

func (*Service) HandleFormatCode

func (s *Service) HandleFormatCode(w http.ResponseWriter, r *http.Request) error

HandleFormatCode handles goimports action

func (*Service) HandleGetSnippet

func (s *Service) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error

HandleGetSnippet handles snippet load

func (*Service) HandleGetSuggestion

func (s *Service) HandleGetSuggestion(w http.ResponseWriter, r *http.Request) error

HandleGetSuggestion handles code suggestion

func (*Service) HandleGetVersion

func (s *Service) HandleGetVersion(w http.ResponseWriter, _ *http.Request) error

HandleGetVersion handles /api/version

func (*Service) HandleGetVersions

func (s *Service) HandleGetVersions(w http.ResponseWriter, r *http.Request) error

func (*Service) HandleRunCode

func (s *Service) HandleRunCode(w http.ResponseWriter, r *http.Request) error

HandleRunCode handles code run

func (*Service) HandleShare

func (s *Service) HandleShare(w http.ResponseWriter, r *http.Request) error

HandleShare handles snippet share

func (*Service) Mount

func (s *Service) Mount(r *mux.Router)

Mount mounts service on route

type ServiceConfig

type ServiceConfig struct {
	Version string
}

type ShareResponse

type ShareResponse struct {
	// SnippetID is definitely not a snippet id (sarcasm)
	SnippetID string `json:"snippetID"`
}

ShareResponse is snippet share response

type SnippetResponse

type SnippetResponse struct {
	// FileName is snippet file name
	FileName string `json:"fileName"`

	// Code is snippet source
	Code string `json:"code"`
}

SnippetResponse is snippet response

type SpaFileServer

type SpaFileServer struct {
	NotFoundHandler http.Handler
	// contains filtered or unexported fields
}

SpaFileServer is a wrapper around http.FileServer for serving SPA contents.

func NewSpaFileServer

func NewSpaFileServer(root string, tplVars TemplateArguments) *SpaFileServer

NewSpaFileServer returns SPA handler

func (*SpaFileServer) ServeHTTP

func (fs *SpaFileServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type SuggestionRequest

type SuggestionRequest struct {
	PackageName string `json:"packageName"`
	Value       string `json:"value"`
}

SuggestionRequest is code completion suggestion request

func (SuggestionRequest) Trim

Trim trims request payload

type SuggestionsResponse

type SuggestionsResponse struct {
	// Suggestions are list of suggestions for monaco
	Suggestions []*analyzer.CompletionItem `json:"suggestions"`
}

SuggestionsResponse is code completion response

func (SuggestionsResponse) Write

Write writes data to response

type TemplateArguments

type TemplateArguments struct {
	GoogleTagID string
}

type TemplateFileServer

type TemplateFileServer struct {
	// contains filtered or unexported fields
}

func NewTemplateFileServer

func NewTemplateFileServer(logger *zap.Logger, filePath string, tplVars TemplateArguments) *TemplateFileServer

NewTemplateFileServer returns handler which compiles and serves HTML page template.

func (*TemplateFileServer) ServeHTTP

func (fs *TemplateFileServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type VersionResponse

type VersionResponse struct {
	// Version is server version
	Version string `json:"version"`
}

VersionResponse is version response

func (VersionResponse) Write

func (r VersionResponse) Write(w http.ResponseWriter)

Write writes data to response

type VersionsInformation

type VersionsInformation struct {
	// Playground contains information about Go versions on Go Playground server.
	Playground *PlaygroundVersions `json:"playground"`

	// WebAssembly is host Go version used for building WebAssembly Go files.
	WebAssembly string `json:"wasm"`
}

VersionsInformation contains Go version for different run targets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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