server

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandXGoRenameResources = "xgo.renameResources"
	CommandSpxRenameResources = "spx.renameResources"
	CommandXGoGetInputSlots   = "xgo.getInputSlots"
	CommandSpxGetInputSlots   = "spx.getInputSlots"
)
View Source
const (
	SeverityError   = protocol.SeverityError
	SeverityWarning = protocol.SeverityWarning

	TextCompletion      = protocol.TextCompletion
	ClassCompletion     = protocol.ClassCompletion
	InterfaceCompletion = protocol.InterfaceCompletion
	StructCompletion    = protocol.StructCompletion
	VariableCompletion  = protocol.VariableCompletion
	ConstantCompletion  = protocol.ConstantCompletion
	KeywordCompletion   = protocol.KeywordCompletion
	FieldCompletion     = protocol.FieldCompletion
	MethodCompletion    = protocol.MethodCompletion
	FunctionCompletion  = protocol.FunctionCompletion
	ModuleCompletion    = protocol.ModuleCompletion

	DiagnosticFull = protocol.DiagnosticFull

	Markdown = protocol.Markdown
	Text     = protocol.Text

	Write = protocol.Write
	Read  = protocol.Read

	PlainTextTextFormat = protocol.PlainTextTextFormat
	SnippetTextFormat   = protocol.SnippetTextFormat

	NamespaceType = protocol.NamespaceType
	TypeType      = protocol.TypeType
	InterfaceType = protocol.InterfaceType
	StructType    = protocol.StructType
	EnumType      = protocol.EnumType
	EnumMember    = protocol.EnumMember
	VariableType  = protocol.VariableType
	ParameterType = protocol.ParameterType
	FunctionType  = protocol.FunctionType
	MethodType    = protocol.MethodType
	PropertyType  = protocol.PropertyType
	KeywordType   = protocol.KeywordType
	CommentType   = protocol.CommentType
	StringType    = protocol.StringType
	NumberType    = protocol.NumberType
	OperatorType  = protocol.OperatorType
	LabelType     = protocol.LabelType

	ModDeclaration    = protocol.ModDeclaration
	ModReadonly       = protocol.ModReadonly
	ModStatic         = protocol.ModStatic
	ModDefinition     = protocol.ModDefinition
	ModDefaultLibrary = protocol.ModDefaultLibrary

	Type      = protocol.Type
	Parameter = protocol.Parameter

	RequestCancelled = protocol.RequestCancelled
)
View Source
const (
	// Deprecated: use XGoInputSlotKindValue.
	SpxInputSlotKindValue = XGoInputSlotKindValue
	// Deprecated: use XGoInputSlotKindAddress.
	SpxInputSlotKindAddress = XGoInputSlotKindAddress
)
View Source
const (
	// Deprecated: use XGoInputKindInPlace.
	SpxInputKindInPlace = XGoInputKindInPlace

	// Deprecated: use XGoInputKindPredefined.
	SpxInputKindPredefined = XGoInputKindPredefined
)
View Source
const SpxPkgPath = "github.com/goplus/spx/v2"

SpxPkgPath is the path to the spx package.

Variables

View Source
var (
	// GeneralSpxDefinitions are general spx definitions.
	GeneralSpxDefinitions = []SpxDefinition{
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("for_iterate")},
			Overview: "for v in arr {}",
			Detail:   "Iterate within given set",

			CompletionItemLabel:            "for",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "for ${1:v} in ${2:[]} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("for_iterate_with_index")},
			Overview: "for i, v in arr {}",
			Detail:   "Iterate with index within given set",

			CompletionItemLabel:            "for",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "for ${1:i}, ${2:v} in ${3:[]} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("for_loop_with_condition")},
			Overview: "for condition {}",
			Detail:   "Loop with condition",

			CompletionItemLabel:            "for",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "for ${1:true} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("for_loop_with_range")},
			Overview: "for i in start:end {}",
			Detail:   "Loop with range",

			CompletionItemLabel:            "for",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "for ${1:i} in ${2:1}:${3:5} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("if_statement")},
			Overview: "if condition {}",
			Detail:   "If statement",

			CompletionItemLabel:            "if",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "if ${1:true} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("if_else_statement")},
			Overview: "if condition {} else {}",
			Detail:   "If else statement",

			CompletionItemLabel:            "if",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "if ${1:true} {\n\t$2\n} else {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("var_declaration")},
			Overview: "var name type",
			Detail:   "Variable declaration, e.g., `var count int`",

			CompletionItemLabel:            "var",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "var ${1:name} $0",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
	}

	// FileScopeSpxDefinitions are spx definitions that are only available
	// in file scope.
	FileScopeSpxDefinitions = []SpxDefinition{
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("import_declaration")},
			Overview: "import \"package\"",
			Detail:   "Import package declaration, e.g., `import \"fmt\"`",

			CompletionItemLabel:            "import",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "import \"${1:package}\"$0",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
		{
			ID:       SpxDefinitionIdentifier{Name: ToPtr("func_declaration")},
			Overview: "func name(params) { ... }",
			Detail:   "Function declaration, e.g., `func add(a int, b int) int {}`",

			CompletionItemLabel:            "func",
			CompletionItemKind:             KeywordCompletion,
			CompletionItemInsertText:       "func ${1:name}(${2:params}) ${3:returnType} {\n\t$0\n}",
			CompletionItemInsertTextFormat: SnippetTextFormat,
		},
	}
)
View Source
var (
	// GetMathPkg returns the math package.
	GetMathPkg = sync.OnceValue(func() *types.Package {
		mathPkg, err := internal.Importer.Import("math")
		if err != nil {
			panic(fmt.Errorf("failed to import math package: %w", err))
		}
		return mathPkg
	})

	// GetMathPkgSpxDefinitions returns the spx definitions for the math package.
	GetMathPkgSpxDefinitions = sync.OnceValue(func() []SpxDefinition {
		mathPkg := GetMathPkg()
		mathPkgPath := xgoutil.PkgPath(mathPkg)
		mathPkgDoc, err := pkgdata.GetPkgDoc(mathPkgPath)
		if err != nil {
			panic(fmt.Errorf("failed to get math package doc: %w", err))
		}
		return GetSpxDefinitionsForPkg(mathPkg, mathPkgDoc)
	})
)
View Source
var (
	// GetSpxPkg returns the spx package.
	GetSpxPkg = sync.OnceValue(func() *types.Package {
		spxPkg, err := internal.Importer.Import(SpxPkgPath)
		if err != nil {
			panic(fmt.Errorf("failed to import spx package: %w", err))
		}
		return spxPkg
	})

	// GetSpxGameType returns the [spx.Game] type.
	GetSpxGameType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Game").Type().(*types.Named)
	})

	// GetSpxBackdropNameType returns the [spx.BackdropName] type.
	GetSpxBackdropNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("BackdropName").Type().(*types.Alias)
	})

	// GetSpxSpriteType returns the [spx.Sprite] type.
	GetSpxSpriteType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Sprite").Type().(*types.Named)
	})

	// GetSpxSpriteImplType returns the [spx.SpriteImpl] type.
	GetSpxSpriteImplType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("SpriteImpl").Type().(*types.Named)
	})

	// GetSpxSpriteNameType returns the [spx.SpriteName] type.
	GetSpxSpriteNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("SpriteName").Type().(*types.Alias)
	})

	// GetSpxSpriteCostumeNameType returns the [spx.SpriteCostumeName] type.
	GetSpxSpriteCostumeNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("SpriteCostumeName").Type().(*types.Alias)
	})

	// GetSpxSpriteAnimationNameType returns the [spx.SpriteAnimationName] type.
	GetSpxSpriteAnimationNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("SpriteAnimationName").Type().(*types.Alias)
	})

	// GetSpxSoundNameType returns the [spx.SoundName] type.
	GetSpxSoundNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("SoundName").Type().(*types.Alias)
	})

	// GetSpxWidgetNameType returns the [spx.WidgetName] type.
	GetSpxWidgetNameType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("WidgetName").Type().(*types.Alias)
	})

	// GetSpxDirectionType returns the [spx.Direction] type.
	GetSpxDirectionType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Direction").Type().(*types.Alias)
	})

	// GetSpxLayerActionType returns the [spx.LayerAction] type.
	GetSpxLayerActionType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("layerAction").Type().(*types.Named)
	})

	// GetSpxDirActionType returns the [spx.DirLayer] type.
	GetSpxDirActionType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("dirAction").Type().(*types.Named)
	})

	// GetSpxEffectKindType returns the [spx.EffectKind] type.
	GetSpxEffectKindType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("EffectKind").Type().(*types.Named)
	})

	// GetSpxKeyType returns the [spx.Key] type.
	GetSpxKeyType = sync.OnceValue(func() *types.Alias {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Key").Type().(*types.Alias)
	})

	// GetSpxSpecialObjType returns the [spx.SpecialObj] type.
	GetSpxSpecialObjType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Edge").Type().(*types.Named)
	})

	// GetSpxRotationStyleType returns the [spx.RotationStyle] type.
	GetSpxRotationStyleType = sync.OnceValue(func() *types.Named {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("RotationStyle").Type().(*types.Named)
	})

	// GetSpxPkgDefinitions returns the spx definitions for the spx package.
	GetSpxPkgDefinitions = sync.OnceValue(func() []SpxDefinition {
		spxPkg := GetSpxPkg()
		spxPkgPath := xgoutil.PkgPath(spxPkg)
		spxPkgDoc, err := pkgdata.GetPkgDoc(spxPkgPath)
		if err != nil {
			panic(fmt.Errorf("failed to get spx package doc: %w", err))
		}
		return GetSpxDefinitionsForPkg(spxPkg, spxPkgDoc)
	})

	// GetSpxHSBFunc returns the [spx.HSB] type.
	GetSpxHSBFunc = sync.OnceValue(func() *types.Func {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("HSB").(*types.Func)
	})

	// GetSpxHSBAFunc returns the [spx.HSBA] type.
	GetSpxHSBAFunc = sync.OnceValue(func() *types.Func {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("HSBA").(*types.Func)
	})

	// GetSpxGoptGameRunFunc returns the [spx.Gopt_Game_Run] type.
	GetSpxGoptGameRunFunc = sync.OnceValue(func() *types.Func {
		spxPkg := GetSpxPkg()
		return spxPkg.Scope().Lookup("Gopt_Game_Run").(*types.Func)
	})
)
View Source
var GetBuiltinSpxDefinitions = sync.OnceValue(func() []SpxDefinition {
	names := types.Universe.Names()
	defs := make([]SpxDefinition, 0, len(names)+len(xgoBuiltinAliases))
	for _, name := range names {
		if _, ok := xgoBuiltinAliases[name]; ok {
			continue
		}
		if obj := types.Universe.Lookup(name); obj != nil && obj.Pkg() == nil {
			defs = append(defs, GetSpxDefinitionForBuiltinObj(obj))
		}
	}
	for alias := range xgoBuiltinAliases {
		def, err := getSpxDefinitionForXGoBuiltinAlias(alias)
		if err != nil {
			panic(fmt.Errorf("failed to get spx definition for xgo builtin alias %q: %w", alias, err))
		}
		defs = append(defs, def)
	}
	return slices.Clip(defs)
})

GetBuiltinSpxDefinitions returns the builtin spx definitions.

Functions

func FromPtr

func FromPtr[T any](p *T) T

FromPtr returns the value from a pointer. It returns the zero value of type T if the pointer is nil.

func GetSimplifiedTypeString

func GetSimplifiedTypeString(typ types.Type) string

GetSimplifiedTypeString returns the string representation of the given type, with the spx package name omitted while other packages use their short names.

func HasSpxResourceNameTypeParams added in v0.10.0

func HasSpxResourceNameTypeParams(fun *types.Func) (has bool)

HasSpxResourceNameTypeParams reports if a function has parameters of spx resource name types.

func IsInSpxPkg

func IsInSpxPkg(obj types.Object) bool

IsInSpxPkg reports whether the given object is defined in the spx package.

func IsRangesOverlap

func IsRangesOverlap(a, b Range) bool

IsRangesOverlap reports whether two ranges overlap.

func IsSpxEventHandlerFuncName

func IsSpxEventHandlerFuncName(name string) bool

IsSpxEventHandlerFuncName reports whether the given function name is an spx event handler function name.

func IsSpxResourceNameType added in v0.13.0

func IsSpxResourceNameType(typ types.Type) bool

IsSpxResourceNameType reports whether the given type is a spx resource name type.

func PosAt

func PosAt(proj *xgo.Project, astFile *xgoast.File, position Position) xgotoken.Pos

PosAt returns the xgotoken.Pos of the given position in the given AST file.

func PositionOffset

func PositionOffset(content []byte, position Position) int

PositionOffset converts an LSP position (line, character) to a byte offset in the document. It calculates the offset by:

  1. Finding the starting byte offset of the requested line
  2. Adding the character offset within that line, converting from UTF-16 to UTF-8 if needed

Parameters:

  • content: The file content as a byte array
  • position: The LSP position with line and character numbers (0-based)

Returns the byte offset from the beginning of the document

func SelectorTypeNameForIdent

func SelectorTypeNameForIdent(proj *xgo.Project, ident *xgoast.Ident) string

SelectorTypeNameForIdent returns the selector type name for the given identifier. It returns empty string if no selector can be inferred.

func ToPosition

func ToPosition(proj *xgo.Project, astFile *xgoast.File, position Position) xgotoken.Position

ToPosition converts a Position to a xgotoken.Position.

func ToPtr

func ToPtr[T any](v T) *T

ToPtr returns a pointer to the value.

func UTF16Len

func UTF16Len(s string) int

UTF16Len calculates the UTF-16 length of the given string.

func UTF16PosToUTF8Offset

func UTF16PosToUTF8Offset(s string, utf16Pos int) int

UTF16PosToUTF8Offset converts a UTF-16 code unit position to a UTF-8 byte offset in the given string.

func UnmarshalJSON

func UnmarshalJSON(msg json.RawMessage, v any) error

UnmarshalJSON unmarshals msg into the variable pointed to by params. In JSONRPC, optional messages may be "null", in which case it is a no-op.

Types

type CancelParams added in v0.7.0

type CancelParams = protocol.CancelParams

type CompletionItem

type CompletionItem = protocol.CompletionItem

type CompletionItemData deprecated

type CompletionItemData = XGoCompletionItemData

Deprecated: use XGoCompletionItemData.

type CompletionItemKind

type CompletionItemKind = protocol.CompletionItemKind

type CompletionParams

type CompletionParams = protocol.CompletionParams

type DeclarationParams

type DeclarationParams = protocol.DeclarationParams

type DefinitionParams

type DefinitionParams = protocol.DefinitionParams

type Diagnostic

type Diagnostic = protocol.Diagnostic

type DidChangeTextDocumentParams

type DidChangeTextDocumentParams = protocol.DidChangeTextDocumentParams

type DidCloseTextDocumentParams

type DidCloseTextDocumentParams = protocol.DidCloseTextDocumentParams

type DidOpenTextDocumentParams

type DidOpenTextDocumentParams = protocol.DidOpenTextDocumentParams

type DidSaveTextDocumentParams

type DidSaveTextDocumentParams = protocol.DidSaveTextDocumentParams

type DocumentDiagnosticParams

type DocumentDiagnosticParams = protocol.DocumentDiagnosticParams

type DocumentDiagnosticReport

type DocumentDiagnosticReport = protocol.DocumentDiagnosticReport

type DocumentFormattingParams

type DocumentFormattingParams = protocol.DocumentFormattingParams

type DocumentHighlight

type DocumentHighlight = protocol.DocumentHighlight

type DocumentHighlightParams

type DocumentHighlightParams = protocol.DocumentHighlightParams
type DocumentLink = protocol.DocumentLink

type DocumentLinkParams

type DocumentLinkParams = protocol.DocumentLinkParams

type DocumentURI

type DocumentURI = protocol.DocumentURI

type ExecuteCommandParams

type ExecuteCommandParams = protocol.ExecuteCommandParams

type FileChange

type FileChange struct {
	Path    string
	Content []byte
	Version int // Version is timestamp in milliseconds
}

FileChange represents a file change.

type FileMapGetter

type FileMapGetter func() map[string]*xgo.File

FileMapGetter is a function that returns a map of file names to [xgo.File]s.

type FullDocumentDiagnosticReport

type FullDocumentDiagnosticReport = protocol.FullDocumentDiagnosticReport

type Hover

type Hover = protocol.Hover

type HoverParams

type HoverParams = protocol.HoverParams

type ImplementationParams

type ImplementationParams = protocol.ImplementationParams

type InitializeParams

type InitializeParams = protocol.InitializeParams

type InitializeResult added in v0.12.0

type InitializeResult = protocol.InitializeResult

type InitializedParams

type InitializedParams = protocol.InitializedParams

type InlayHint

type InlayHint = protocol.InlayHint

type InlayHintKind

type InlayHintKind = protocol.InlayHintKind

type InlayHintParams

type InlayHintParams = protocol.InlayHintParams

type InsertTextFormat

type InsertTextFormat = protocol.InsertTextFormat

type Location

type Location = protocol.Location

func DedupeLocations

func DedupeLocations(locations []Location) []Location

DedupeLocations deduplicates locations.

type MarkupContent

type MarkupContent = protocol.MarkupContent

type MessageReplier

type MessageReplier interface {
	// ReplyMessage sends a message back to the client.
	//
	// The message can be one of:
	//   - [jsonrpc2.Response]: sent in response to a call.
	//   - [jsonrpc2.Notification]: sent for server-initiated notifications.
	ReplyMessage(m jsonrpc2.Message) error
}

MessageReplier is an interface for sending messages back to the client.

type Or_CompletionItem_documentation

type Or_CompletionItem_documentation = protocol.Or_CompletionItem_documentation

type ParameterInformation

type ParameterInformation = protocol.ParameterInformation

type Position

type Position = protocol.Position

func FromPosition

func FromPosition(proj *xgo.Project, astFile *xgoast.File, position xgotoken.Position) Position

FromPosition converts a xgotoken.Position to a Position.

type PrepareRenameParams

type PrepareRenameParams = protocol.PrepareRenameParams

type PublishDiagnosticsParams

type PublishDiagnosticsParams = protocol.PublishDiagnosticsParams

type Range

type Range = protocol.Range

func RangeForASTFileNode

func RangeForASTFileNode(proj *xgo.Project, astFile *xgoast.File, node xgoast.Node) Range

RangeForASTFileNode returns the Range for the given node in the given AST file.

func RangeForASTFilePosition

func RangeForASTFilePosition(proj *xgo.Project, astFile *xgoast.File, position xgotoken.Position) Range

RangeForASTFilePosition returns a Range for the given xgotoken.Position in the given AST file.

func RangeForNode

func RangeForNode(proj *xgo.Project, node xgoast.Node) Range

RangeForNode returns the Range for the given node.

func RangeForPos

func RangeForPos(proj *xgo.Project, pos xgotoken.Pos) Range

RangeForPos returns the Range for the given position.

func RangeForPosEnd

func RangeForPosEnd(proj *xgo.Project, pos, end xgotoken.Pos) Range

RangeForPosEnd returns the Range for the given pos and end positions.

type ReferenceContext

type ReferenceContext = protocol.ReferenceContext

type ReferenceParams

type ReferenceParams = protocol.ReferenceParams

type RenameParams

type RenameParams = protocol.RenameParams

type Scheduler added in v0.7.0

type Scheduler interface {
	// Sched yields the processor, allowing other routines to run.
	// "routines" here refers to not just goroutines, but also other tasks, for example, Javascript event loop in browsers.
	Sched()
}

Scheduler is an interface for task scheduling.

type SemanticTokenModifiers

type SemanticTokenModifiers = protocol.SemanticTokenModifiers

type SemanticTokenTypes

type SemanticTokenTypes = protocol.SemanticTokenTypes

type SemanticTokens

type SemanticTokens = protocol.SemanticTokens

type SemanticTokensParams

type SemanticTokensParams = protocol.SemanticTokensParams

type Server

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

Server is the core language server implementation that handles LSP messages.

func New

func New(proj *xgo.Project, replier MessageReplier, fileMapGetter FileMapGetter, scheduler Scheduler) *Server

New creates a new Server instance.

func (*Server) HandleMessage

func (s *Server) HandleMessage(m jsonrpc2.Message) error

HandleMessage handles an incoming LSP message.

func (*Server) ModifyFiles

func (s *Server) ModifyFiles(changes []FileChange)

ModifyFiles modifies files in the project.

type ServerCapabilities added in v0.12.0

type ServerCapabilities = protocol.ServerCapabilities

type ServerInfo added in v0.12.0

type ServerInfo = protocol.ServerInfo

type SignatureHelp

type SignatureHelp = protocol.SignatureHelp

type SignatureHelpParams

type SignatureHelpParams = protocol.SignatureHelpParams

type SignatureInformation

type SignatureInformation = protocol.SignatureInformation

type SpxBackdropResource

type SpxBackdropResource struct {
	ID   SpxBackdropResourceID `json:"-"`
	Name string                `json:"name"`
	Path string                `json:"path"`
}

SpxBackdropResource represents a backdrop resource in spx.

type SpxBackdropResourceID

type SpxBackdropResourceID struct {
	BackdropName string
}

SpxBackdropResourceID is the ID of an spx backdrop resource.

func (SpxBackdropResourceID) ContextURI

ContextURI implements SpxResourceID.

func (SpxBackdropResourceID) Name

func (id SpxBackdropResourceID) Name() string

Name implements SpxResourceID.

func (SpxBackdropResourceID) URI

URI implements SpxResourceID.

type SpxColorInputValue deprecated

type SpxColorInputValue = XGoInputSpxColorValue

Deprecated: use XGoInputSpxColorValue.

type SpxDefinition

type SpxDefinition struct {
	// TypeHint represents a type hint for this definition. It may be nil if
	// the definition has no associated type.
	TypeHint types.Type

	ID       SpxDefinitionIdentifier
	Overview string
	Detail   string

	CompletionItemLabel            string
	CompletionItemKind             CompletionItemKind
	CompletionItemInsertText       string
	CompletionItemInsertTextFormat InsertTextFormat
}

SpxDefinition represents an spx definition.

func GetSpxDefinitionForBuiltinObj

func GetSpxDefinitionForBuiltinObj(obj types.Object) SpxDefinition

GetSpxDefinitionForBuiltinObj returns the spx definition for the given object.

func GetSpxDefinitionForConst

func GetSpxDefinitionForConst(c *types.Const, pkgDoc *pkgdoc.PkgDoc) (def SpxDefinition)

GetSpxDefinitionForConst returns the spx definition for the provided constant.

func GetSpxDefinitionForFunc

func GetSpxDefinitionForFunc(fun *types.Func, recvTypeName string, pkgDoc *pkgdoc.PkgDoc) (def SpxDefinition)

GetSpxDefinitionForFunc returns the spx definition for the provided function.

func GetSpxDefinitionForPkg

func GetSpxDefinitionForPkg(pkgName *types.PkgName, pkgDoc *pkgdoc.PkgDoc) (def SpxDefinition)

GetSpxDefinitionForPkg returns the spx definition for the provided package.

func GetSpxDefinitionForType

func GetSpxDefinitionForType(typeName *types.TypeName, pkgDoc *pkgdoc.PkgDoc) (def SpxDefinition)

GetSpxDefinitionForType returns the spx definition for the provided type.

func GetSpxDefinitionForVar

func GetSpxDefinitionForVar(v *types.Var, selectorTypeName string, forceVar bool, pkgDoc *pkgdoc.PkgDoc) (def SpxDefinition)

GetSpxDefinitionForVar returns the spx definition for the provided variable.

func GetSpxDefinitionsForPkg

func GetSpxDefinitionsForPkg(pkg *types.Package, pkgDoc *pkgdoc.PkgDoc) (defs []SpxDefinition)

GetSpxDefinitionsForPkg returns the spx definitions for the given package.

func (SpxDefinition) CompletionItem

func (def SpxDefinition) CompletionItem() CompletionItem

CompletionItem constructs a CompletionItem from the definition.

func (SpxDefinition) HTML

func (def SpxDefinition) HTML() string

HTML returns the HTML representation of the definition.

type SpxDefinitionIdentifier deprecated

type SpxDefinitionIdentifier = XGoDefinitionIdentifier

Deprecated: use XGoDefinitionIdentifier.

type SpxGetDefinitionsParams deprecated

type SpxGetDefinitionsParams = XGoGetDefinitionsParams

Deprecated: use XGoGetDefinitionsParams.

type SpxGetInputSlotsParams deprecated

type SpxGetInputSlotsParams = XGoGetInputSlotsParams

Deprecated: use XGoGetInputSlotsParams.

type SpxInput deprecated

type SpxInput = XGoInput

Deprecated: use XGoInput.

type SpxInputKind deprecated

type SpxInputKind = XGoInputKind

Deprecated: use XGoInputKind.

type SpxInputSlot deprecated

type SpxInputSlot = XGoInputSlot

Deprecated: use XGoInputSlot.

type SpxInputSlotAccept deprecated

type SpxInputSlotAccept = XGoInputSlotAccept

Deprecated: use XGoInputSlotAccept.

type SpxInputSlotKind deprecated

type SpxInputSlotKind = XGoInputSlotKind

Deprecated: use XGoInputSlotKind.

type SpxInputType deprecated

type SpxInputType = XGoInputType

Deprecated: use XGoInputType.

const (
	SpxInputTypeString        SpxInputType = XGoInputTypeString
	SpxInputTypeInteger       SpxInputType = XGoInputTypeInteger
	SpxInputTypeDecimal       SpxInputType = XGoInputTypeDecimal
	SpxInputTypeBoolean       SpxInputType = XGoInputTypeBoolean
	SpxInputTypeUnknown       SpxInputType = XGoInputTypeUnknown
	SpxInputTypeResourceName  SpxInputType = XGoInputTypeSpxResourceName
	SpxInputTypeDirection     SpxInputType = XGoInputTypeSpxDirection
	SpxInputTypeLayerAction   SpxInputType = XGoInputTypeSpxLayerAction
	SpxInputTypeDirAction     SpxInputType = XGoInputTypeSpxDirAction
	SpxInputTypeColor         SpxInputType = XGoInputTypeSpxColor
	SpxInputTypeEffectKind    SpxInputType = XGoInputTypeSpxEffectKind
	SpxInputTypeKey           SpxInputType = XGoInputTypeSpxKey
	SpxInputTypeSpecialObj    SpxInputType = XGoInputTypeSpxSpecialObj
	SpxInputTypeRotationStyle SpxInputType = XGoInputTypeSpxRotationStyle
)

Deprecated: use XGoInputType*.

type SpxInputTypeSpxColorConstructor deprecated

type SpxInputTypeSpxColorConstructor = XGoInputTypeSpxColorConstructor

Deprecated: use XGoInputTypeSpxColorConstructor.

const (
	SpxInputTypeSpxColorConstructorHSB  SpxInputTypeSpxColorConstructor = XGoInputTypeSpxColorConstructorHSB
	SpxInputTypeSpxColorConstructorHSBA SpxInputTypeSpxColorConstructor = XGoInputTypeSpxColorConstructorHSBA
)

Deprecated: use XGoInputTypeSpxColorConstructor*.

type SpxReferencePkg

type SpxReferencePkg struct {
	PkgPath string
	Pkg     *pkgdoc.PkgDoc
	Node    *xgoast.ImportSpec
}

SpxReferencePkg is a reference to an imported package.

type SpxRenameResourceParams deprecated

type SpxRenameResourceParams = XGoRenameResourceParams

Deprecated: use XGoRenameResourceParams.

type SpxResourceContextURI deprecated

type SpxResourceContextURI = XGoResourceContextURI

Deprecated: use XGoResourceContextURI.

const SpxBackdropResourceContextURI SpxResourceContextURI = "spx://resources/backdrops"

SpxBackdropResourceContextURI is the SpxResourceContextURI of SpxBackdropResource.

const SpxSoundResourceContextURI SpxResourceContextURI = "spx://resources/sounds"

SpxSoundResourceContextURI is the SpxResourceContextURI of SpxSoundResource.

const SpxSpriteResourceContextURI SpxResourceContextURI = "spx://resources/sprites"

SpxSpriteResourceContextURI is the SpxResourceContextURI of SpxSpriteResource.

const SpxWidgetResourceContextURI SpxResourceContextURI = "spx://resources/widgets"

SpxWidgetResourceContextURI is the SpxResourceContextURI of SpxWidgetResource.

func FormatSpxSpriteAnimationResourceContextURI

func FormatSpxSpriteAnimationResourceContextURI(spriteName string) SpxResourceContextURI

FormatSpxSpriteAnimationResourceContextURI formats the SpxResourceContextURI for a sprite's animation resources.

func FormatSpxSpriteCostumeResourceContextURI

func FormatSpxSpriteCostumeResourceContextURI(spriteName string) SpxResourceContextURI

FormatSpxSpriteCostumeResourceContextURI formats the SpxResourceContextURI for a sprite's costume resources.

type SpxResourceID

type SpxResourceID interface {
	Name() string
	URI() SpxResourceURI
	ContextURI() SpxResourceContextURI
}

SpxResourceID is the ID of an spx resource.

func ParseSpxResourceURI

func ParseSpxResourceURI(uri SpxResourceURI) (SpxResourceID, error)

ParseSpxResourceURI parses an spx resource URI and returns the corresponding spx resource ID.

type SpxResourceIdentifier deprecated

type SpxResourceIdentifier = XGoResourceIdentifier

Deprecated: use XGoResourceIdentifier.

type SpxResourceRef

type SpxResourceRef struct {
	ID   SpxResourceID
	Kind SpxResourceRefKind
	Node xgoast.Node
}

SpxResourceRef is a reference to an spx resource.

type SpxResourceRefDocumentLinkData deprecated

type SpxResourceRefDocumentLinkData = XGoResourceRefDocumentLinkData

Deprecated: use XGoResourceRefDocumentLinkData.

type SpxResourceRefKind

type SpxResourceRefKind string

SpxResourceRefKind is the kind of an spx resource reference.

const (
	SpxResourceRefKindStringLiteral        SpxResourceRefKind = "stringLiteral"
	SpxResourceRefKindAutoBindingReference SpxResourceRefKind = "autoBindingReference"
	SpxResourceRefKindConstantReference    SpxResourceRefKind = "constantReference"
)

type SpxResourceSet

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

SpxResourceSet is a set of spx resources.

func NewSpxResourceSet

func NewSpxResourceSet(proj *xgo.Project, rootDir string) (*SpxResourceSet, error)

NewSpxResourceSet creates a new spx resource set.

func (*SpxResourceSet) Backdrop

func (set *SpxResourceSet) Backdrop(name string) *SpxBackdropResource

Backdrop returns the backdrop with the given name. It returns nil if not found.

func (*SpxResourceSet) Sound

func (set *SpxResourceSet) Sound(name string) *SpxSoundResource

Sound returns the sound with the given name. It returns nil if not found.

func (*SpxResourceSet) Sprite

func (set *SpxResourceSet) Sprite(name string) *SpxSpriteResource

Sprite returns the sprite with the given name. It returns nil if not found.

func (*SpxResourceSet) Widget

func (set *SpxResourceSet) Widget(name string) *SpxWidgetResource

Widget returns the widget with the given name. It returns nil if not found.

type SpxResourceURI deprecated

type SpxResourceURI = XGoResourceURI

Deprecated: use XGoResourceURI.

type SpxSoundResource

type SpxSoundResource struct {
	ID   SpxSoundResourceID `json:"-"`
	Name string             `json:"name"`
	Path string             `json:"path"`
}

SpxSoundResource represents a sound resource in spx.

type SpxSoundResourceID

type SpxSoundResourceID struct {
	SoundName string
}

SpxSoundResourceID is the ID of an spx sound resource.

func (SpxSoundResourceID) ContextURI

func (id SpxSoundResourceID) ContextURI() SpxResourceContextURI

ContextURI implements SpxResourceID.

func (SpxSoundResourceID) Name

func (id SpxSoundResourceID) Name() string

Name implements SpxResourceID.

func (SpxSoundResourceID) URI

URI implements SpxResourceID.

type SpxSpriteAnimationResource

type SpxSpriteAnimationResource struct {
	ID        SpxSpriteAnimationResourceID `json:"-"`
	Name      string                       `json:"name"`
	FromIndex *int                         `json:"-"`
	ToIndex   *int                         `json:"-"`
}

SpxSpriteAnimationResource represents an spx sprite animation resource.

type SpxSpriteAnimationResourceID

type SpxSpriteAnimationResourceID struct {
	SpriteName    string
	AnimationName string
}

SpxSpriteAnimationResourceID is the ID of an spx sprite animation resource.

func (SpxSpriteAnimationResourceID) ContextURI

ContextURI implements SpxResourceID.

func (SpxSpriteAnimationResourceID) Name

Name implements SpxResourceID.

func (SpxSpriteAnimationResourceID) URI

URI implements SpxResourceID.

type SpxSpriteCostumeResource

type SpxSpriteCostumeResource struct {
	ID   SpxSpriteCostumeResourceID `json:"-"`
	Name string                     `json:"name"`
	Path string                     `json:"path"`
}

SpxSpriteCostumeResource represents an spx sprite costume resource.

type SpxSpriteCostumeResourceID

type SpxSpriteCostumeResourceID struct {
	SpriteName  string
	CostumeName string
}

SpxSpriteCostumeResourceID is the ID of an spx sprite costume resource.

func (SpxSpriteCostumeResourceID) ContextURI

ContextURI implements SpxResourceID.

func (SpxSpriteCostumeResourceID) Name

Name implements SpxResourceID.

func (SpxSpriteCostumeResourceID) URI

URI implements SpxResourceID.

type SpxSpriteResource

type SpxSpriteResource struct {
	ID       SpxSpriteResourceID        `json:"-"`
	Name     string                     `json:"name"`
	Costumes []SpxSpriteCostumeResource `json:"costumes"`
	// NormalCostumes includes all costumes except animation costumes.
	NormalCostumes   []SpxSpriteCostumeResource     `json:"-"`
	CostumeIndex     int                            `json:"costumeIndex"`
	FAnimations      map[string]spxSpriteFAnimation `json:"fAnimations"`
	Animations       []SpxSpriteAnimationResource   `json:"-"`
	DefaultAnimation string                         `json:"defaultAnimation"`
}

SpxSpriteResource represents an spx sprite resource.

func (*SpxSpriteResource) Animation

func (sprite *SpxSpriteResource) Animation(name string) *SpxSpriteAnimationResource

Animation returns the animation with the given name. It returns nil if not found.

func (*SpxSpriteResource) Costume

func (sprite *SpxSpriteResource) Costume(name string) *SpxSpriteCostumeResource

Costume returns the costume with the given name. It returns nil if not found.

type SpxSpriteResourceID

type SpxSpriteResourceID struct {
	SpriteName string
}

SpxSpriteResourceID is the ID of an spx sprite resource.

func (SpxSpriteResourceID) ContextURI

ContextURI implements SpxResourceID.

func (SpxSpriteResourceID) Name

func (id SpxSpriteResourceID) Name() string

Name implements SpxResourceID.

func (SpxSpriteResourceID) URI

URI implements SpxResourceID.

type SpxWidgetResource

type SpxWidgetResource struct {
	ID    SpxWidgetResourceID `json:"-"`
	Name  string              `json:"name"`
	Type  string              `json:"type"`
	Label string              `json:"label"`
	Val   string              `json:"val"`
}

SpxWidgetResource represents a widget resource in spx.

type SpxWidgetResourceID

type SpxWidgetResourceID struct {
	WidgetName string
}

SpxWidgetResourceID is the ID of an spx widget resource.

func (SpxWidgetResourceID) ContextURI

ContextURI implements SpxResourceID.

func (SpxWidgetResourceID) Name

func (id SpxWidgetResourceID) Name() string

Name implements SpxResourceID.

func (SpxWidgetResourceID) URI

URI implements SpxResourceID.

type TextDocumentIdentifier

type TextDocumentIdentifier = protocol.TextDocumentIdentifier

type TextDocumentPositionParams

type TextDocumentPositionParams = protocol.TextDocumentPositionParams

type TextEdit

type TextEdit = protocol.TextEdit

type TypeDefinitionParams

type TypeDefinitionParams = protocol.TypeDefinitionParams

type URI

type URI = protocol.URI

type WorkspaceDiagnosticParams

type WorkspaceDiagnosticParams = protocol.WorkspaceDiagnosticParams

type WorkspaceDiagnosticReport

type WorkspaceDiagnosticReport = protocol.WorkspaceDiagnosticReport

type WorkspaceDocumentDiagnosticReport

type WorkspaceDocumentDiagnosticReport = protocol.WorkspaceDocumentDiagnosticReport

type WorkspaceEdit

type WorkspaceEdit = protocol.WorkspaceEdit

type XGoCompletionItemData added in v0.15.0

type XGoCompletionItemData struct {
	// The corresponding definition of the completion item.
	Definition *XGoDefinitionIdentifier `json:"definition,omitempty"`
}

XGoCompletionItemData represents data in a completion item.

type XGoDefinitionIdentifier added in v0.15.0

type XGoDefinitionIdentifier struct {
	// Full name of source package.
	// If not provided, it's assumed to be kind-statement.
	// If `main`, it's the current user package.
	// Examples:
	// - `fmt`
	// - `github.com/goplus/spx/v2`
	// - `main`
	Package *string `json:"package,omitempty"`

	// Exported name of the definition.
	// If not provided, it's assumed to be kind-package.
	// Examples:
	// - `Println`
	// - `Sprite`
	// - `Sprite.turn`
	// - `for_statement_with_single_condition`
	Name *string `json:"name,omitempty"`

	// Overload Identifier.
	OverloadID *string `json:"overloadId,omitempty"`
}

XGoDefinitionIdentifier identifies an XGo definition.

func (XGoDefinitionIdentifier) String added in v0.15.0

func (id XGoDefinitionIdentifier) String() string

String implements fmt.Stringer.

type XGoGetDefinitionsParams added in v0.15.0

type XGoGetDefinitionsParams struct {
	// The text document position params.
	protocol.TextDocumentPositionParams
}

XGoGetDefinitionsParams represents parameters to get definitions at a specific position in a document.

type XGoGetInputSlotsParams added in v0.15.0

type XGoGetInputSlotsParams struct {
	// The text document.
	TextDocument protocol.TextDocumentIdentifier `json:"textDocument"`
}

XGoGetInputSlotsParams holds parameters to get XGo input slots for a specific document.

type XGoInput added in v0.15.0

type XGoInput struct {
	Kind  XGoInputKind `json:"kind"`
	Type  XGoInputType `json:"type"`
	Value any          `json:"value,omitempty"` // For InPlace kind
	Name  string       `json:"name,omitempty"`  // For Predefined kind
}

XGoInput represents the current input in a slot.

type XGoInputKind added in v0.15.0

type XGoInputKind string

XGoInputKind represents the kind of input.

const (
	// XGoInputKindInPlace in-place value like "hello world", 123, true, etc.
	XGoInputKindInPlace XGoInputKind = "in-place"

	// XGoInputKindPredefined reference to user predefined identifier.
	XGoInputKindPredefined XGoInputKind = "predefined"
)

XGoInputKind constants.

type XGoInputSlot added in v0.15.0

type XGoInputSlot struct {
	Range           Range              `json:"range"`
	Kind            XGoInputSlotKind   `json:"kind"`
	Accept          XGoInputSlotAccept `json:"accept"`
	Input           XGoInput           `json:"input"`
	PredefinedNames []string           `json:"predefinedNames"`
}

XGoInputSlot describes a modifiable item in code.

type XGoInputSlotAccept added in v0.15.0

type XGoInputSlotAccept struct {
	// Type of input accepted by the slot.
	Type XGoInputType `json:"type"`

	// Resource context for XGoInputTypeSpxResourceName.
	// Only valid when Type is XGoInputTypeSpxResourceName.
	ResourceContext *XGoResourceContextURI `json:"resourceContext,omitempty"`
}

XGoInputSlotAccept represents info about what inputs are accepted by a slot.

type XGoInputSlotKind added in v0.15.0

type XGoInputSlotKind string

XGoInputSlotKind enumerates kinds of XGo input slots.

const (
	// XGoInputSlotKindValue slot accepts value, which may be an in-place value or a predefined identifier.
	XGoInputSlotKindValue XGoInputSlotKind = "value"

	// XGoInputSlotKindAddress slot accepts address, which must be a predefined identifier.
	XGoInputSlotKindAddress XGoInputSlotKind = "address"
)

XGoInputSlotKind constants.

type XGoInputSpxColorValue added in v0.15.0

type XGoInputSpxColorValue struct {
	Constructor XGoInputTypeSpxColorConstructor `json:"constructor"`
	Args        []float64                       `json:"args"`
}

XGoInputSpxColorValue represents the value structure for an XGoInput when its type is XGoInputTypeSpxColor and kind is XGoInputKindInPlace.

type XGoInputType added in v0.15.0

type XGoInputType string

XGoInputType represents the type of input for a slot.

const (
	XGoInputTypeString           XGoInputType = "string"
	XGoInputTypeInteger          XGoInputType = "integer"
	XGoInputTypeDecimal          XGoInputType = "decimal"
	XGoInputTypeBoolean          XGoInputType = "boolean"
	XGoInputTypeUnknown          XGoInputType = "unknown"
	XGoInputTypeSpxResourceName  XGoInputType = "spx-resource-name"
	XGoInputTypeSpxDirection     XGoInputType = "spx-direction"
	XGoInputTypeSpxLayerAction   XGoInputType = "spx-layer-action"
	XGoInputTypeSpxDirAction     XGoInputType = "spx-dir-action"
	XGoInputTypeSpxColor         XGoInputType = "spx-color"
	XGoInputTypeSpxEffectKind    XGoInputType = "spx-effect-kind"
	XGoInputTypeSpxKey           XGoInputType = "spx-key"
	XGoInputTypeSpxSpecialObj    XGoInputType = "spx-special-obj"
	XGoInputTypeSpxRotationStyle XGoInputType = "spx-rotation-style"
)

XGoInputType constants.

type XGoInputTypeSpxColorConstructor added in v0.15.0

type XGoInputTypeSpxColorConstructor string

XGoInputTypeSpxColorConstructor represents the name for color constructors.

const (
	XGoInputTypeSpxColorConstructorHSB  XGoInputTypeSpxColorConstructor = "HSB"
	XGoInputTypeSpxColorConstructorHSBA XGoInputTypeSpxColorConstructor = "HSBA"
)

XGoInputTypeSpxColorConstructor constants.

type XGoRenameResourceParams added in v0.15.0

type XGoRenameResourceParams struct {
	// The XGo resource to rename.
	Resource XGoResourceIdentifier `json:"resource"`

	// The new name of the XGo resource.
	NewName string `json:"newName"`
}

XGoRenameResourceParams represents parameters to rename an XGo resource in the workspace.

type XGoResourceContextURI added in v0.15.0

type XGoResourceContextURI string

XGoResourceContextURI represents a URI for XGo resource context. Examples: - `spx://resources/sprites` - `spx://resources/sounds` - `spx://resources/sprites/<sName>/costumes`

type XGoResourceIdentifier added in v0.15.0

type XGoResourceIdentifier struct {
	// The XGo resource URI.
	URI XGoResourceURI `json:"uri"`
}

XGoResourceIdentifier identifies an XGo resource.

type XGoResourceRefDocumentLinkData added in v0.15.0

type XGoResourceRefDocumentLinkData struct {
	// The kind of the XGo resource reference.
	Kind SpxResourceRefKind `json:"kind"`
}

XGoResourceRefDocumentLinkData represents data for an XGo resource reference document link.

type XGoResourceURI added in v0.15.0

type XGoResourceURI string

XGoResourceURI represents a URI string for an XGo resource.

func (XGoResourceURI) HTML added in v0.15.0

func (u XGoResourceURI) HTML() string

HTML returns the HTML representation of the XGo resource URI.

Jump to

Keyboard shortcuts

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