lsp

package
v0.0.0-...-e6c4605 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package lsp implements a Language Server Protocol server for LeapSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathToURI

func PathToURI(path string) string

PathToURI converts a file system path to a file:// URI.

func URIToPath

func URIToPath(uri string) string

URIToPath converts a file:// URI to a file system path.

Types

type CodeAction

type CodeAction struct {
	Title       string         `json:"title"`
	Kind        CodeActionKind `json:"kind,omitempty"`
	Diagnostics []Diagnostic   `json:"diagnostics,omitempty"`
	IsPreferred bool           `json:"isPreferred,omitempty"`
	Edit        *WorkspaceEdit `json:"edit,omitempty"`
	Command     *Command       `json:"command,omitempty"`
}

CodeAction represents a code action (Quick Fix, refactoring, etc.).

type CodeActionContext

type CodeActionContext struct {
	Diagnostics []Diagnostic     `json:"diagnostics"`
	Only        []CodeActionKind `json:"only,omitempty"`
}

CodeActionContext contains additional diagnostic information.

type CodeActionKind

type CodeActionKind string

CodeActionKind defines the kind of a code action.

const (
	CodeActionKindEmpty                 CodeActionKind = ""
	CodeActionKindQuickFix              CodeActionKind = "quickfix"
	CodeActionKindRefactor              CodeActionKind = "refactor"
	CodeActionKindRefactorExtract       CodeActionKind = "refactor.extract"
	CodeActionKindRefactorInline        CodeActionKind = "refactor.inline"
	CodeActionKindRefactorRewrite       CodeActionKind = "refactor.rewrite"
	CodeActionKindSource                CodeActionKind = "source"
	CodeActionKindSourceOrganizeImports CodeActionKind = "source.organizeImports"
	CodeActionKindSourceFixAll          CodeActionKind = "source.fixAll"
)

CodeActionKind constants.

type CodeActionOptions

type CodeActionOptions struct {
	CodeActionKinds []CodeActionKind `json:"codeActionKinds,omitempty"`
}

CodeActionOptions are options for the code action provider.

type CodeActionParams

type CodeActionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Range        Range                  `json:"range"`
	Context      CodeActionContext      `json:"context"`
}

CodeActionParams is the request parameters for textDocument/codeAction.

type CodeDescription

type CodeDescription struct {
	Href string `json:"href"`
}

CodeDescription provides a URL with more information about a diagnostic code.

type Command

type Command struct {
	Title     string `json:"title"`
	Command   string `json:"command"`
	Arguments []any  `json:"arguments,omitempty"`
}

Command represents a reference to a command.

type CompletionContext

type CompletionContext struct {
	TriggerKind      int    `json:"triggerKind"`
	TriggerCharacter string `json:"triggerCharacter,omitempty"`
}

CompletionContext contains additional information about the context.

type CompletionContextType

type CompletionContextType int

CompletionContextType describes what kind of completion context we're in.

const (
	ContextUnknown CompletionContextType = iota
	ContextSelectClause
	ContextFromClause
	ContextWhereClause
	ContextColumnAccess // After "table."
	ContextFunctionArgs // Inside "func("
	ContextStarlarkRoot // Inside {{ }} at root level
	ContextMacroAccess  // Inside {{ namespace. }}
	ContextConfigAccess // Inside config. or config["
)

Completion context type constants.

type CompletionItem

type CompletionItem struct {
	Label               string             `json:"label"`
	Kind                CompletionItemKind `json:"kind,omitempty"`
	Detail              string             `json:"detail,omitempty"`
	Documentation       string             `json:"documentation,omitempty"`
	Deprecated          bool               `json:"deprecated,omitempty"`
	Preselect           bool               `json:"preselect,omitempty"`
	SortText            string             `json:"sortText,omitempty"`
	FilterText          string             `json:"filterText,omitempty"`
	InsertText          string             `json:"insertText,omitempty"`
	InsertTextFormat    InsertTextFormat   `json:"insertTextFormat,omitempty"`
	TextEdit            *TextEdit          `json:"textEdit,omitempty"`
	AdditionalTextEdits []TextEdit         `json:"additionalTextEdits,omitempty"`
}

CompletionItem represents a completion item.

type CompletionItemKind

type CompletionItemKind int

CompletionItemKind indicates the kind of a completion entry.

const (
	CompletionItemKindText          CompletionItemKind = 1
	CompletionItemKindMethod        CompletionItemKind = 2
	CompletionItemKindFunction      CompletionItemKind = 3
	CompletionItemKindConstructor   CompletionItemKind = 4
	CompletionItemKindField         CompletionItemKind = 5
	CompletionItemKindVariable      CompletionItemKind = 6
	CompletionItemKindClass         CompletionItemKind = 7
	CompletionItemKindInterface     CompletionItemKind = 8
	CompletionItemKindModule        CompletionItemKind = 9
	CompletionItemKindProperty      CompletionItemKind = 10
	CompletionItemKindUnit          CompletionItemKind = 11
	CompletionItemKindValue         CompletionItemKind = 12
	CompletionItemKindEnum          CompletionItemKind = 13
	CompletionItemKindKeyword       CompletionItemKind = 14
	CompletionItemKindSnippet       CompletionItemKind = 15
	CompletionItemKindColor         CompletionItemKind = 16
	CompletionItemKindFile          CompletionItemKind = 17
	CompletionItemKindReference     CompletionItemKind = 18
	CompletionItemKindFolder        CompletionItemKind = 19
	CompletionItemKindEnumMember    CompletionItemKind = 20
	CompletionItemKindConstant      CompletionItemKind = 21
	CompletionItemKindStruct        CompletionItemKind = 22
	CompletionItemKindEvent         CompletionItemKind = 23
	CompletionItemKindOperator      CompletionItemKind = 24
	CompletionItemKindTypeParameter CompletionItemKind = 25
)

CompletionItemKind constants.

type CompletionList

type CompletionList struct {
	IsIncomplete bool             `json:"isIncomplete"`
	Items        []CompletionItem `json:"items"`
}

CompletionList represents a list of completion items.

type CompletionOptions

type CompletionOptions struct {
	TriggerCharacters []string `json:"triggerCharacters,omitempty"`
	ResolveProvider   bool     `json:"resolveProvider,omitempty"`
}

CompletionOptions for completion requests.

type CompletionParams

type CompletionParams struct {
	TextDocumentPositionParams
	Context *CompletionContext `json:"context,omitempty"`
}

CompletionParams for completion requests.

type DefinitionParams

type DefinitionParams struct {
	TextDocumentPositionParams
}

DefinitionParams for go to definition requests.

type Diagnostic

type Diagnostic struct {
	Range           Range              `json:"range"`
	Severity        DiagnosticSeverity `json:"severity,omitempty"`
	Code            string             `json:"code,omitempty"`
	CodeDescription *CodeDescription   `json:"codeDescription,omitempty"`
	Source          string             `json:"source,omitempty"`
	Message         string             `json:"message"`
}

Diagnostic represents a diagnostic, such as a compiler error or warning.

type DiagnosticSeverity

type DiagnosticSeverity int

DiagnosticSeverity indicates the severity of a diagnostic.

const (
	DiagnosticSeverityError       DiagnosticSeverity = 1
	DiagnosticSeverityWarning     DiagnosticSeverity = 2
	DiagnosticSeverityInformation DiagnosticSeverity = 3
	DiagnosticSeverityHint        DiagnosticSeverity = 4
)

DiagnosticSeverity constants.

type DidChangeTextDocumentParams

type DidChangeTextDocumentParams struct {
	TextDocument   VersionedTextDocumentIdentifier  `json:"textDocument"`
	ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}

DidChangeTextDocumentParams for textDocument/didChange notification.

type DidCloseTextDocumentParams

type DidCloseTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

DidCloseTextDocumentParams for textDocument/didClose notification.

type DidOpenTextDocumentParams

type DidOpenTextDocumentParams struct {
	TextDocument TextDocumentItem `json:"textDocument"`
}

DidOpenTextDocumentParams for textDocument/didOpen notification.

type DidSaveTextDocumentParams

type DidSaveTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Text         string                 `json:"text,omitempty"`
}

DidSaveTextDocumentParams for textDocument/didSave notification.

type Document

type Document struct {
	URI     string // Document URI (file:///path/to/file.sql)
	Content string // Full document content
	Version int    // Version number, incremented on each change
	Lines   []int  // Byte offsets of line starts for fast position lookups
}

Document represents an open text document in the editor.

func (*Document) GetLine

func (d *Document) GetLine(line int) string

GetLine returns the content of a specific line.

func (*Document) GetTextAfter

func (d *Document) GetTextAfter(pos Position) string

GetTextAfter returns the text after the given position.

func (*Document) GetTextBefore

func (d *Document) GetTextBefore(pos Position) string

GetTextBefore returns the text before the given position.

func (*Document) GetTextInRange

func (d *Document) GetTextInRange(r Range) string

GetTextInRange returns the text within a range.

func (*Document) GetWordAtPosition

func (d *Document) GetWordAtPosition(pos Position) (string, Range)

GetWordAtPosition returns the word at the given position and its range.

func (*Document) OffsetToPosition

func (d *Document) OffsetToPosition(offset int) Position

OffsetToPosition converts a byte offset to a Position.

func (*Document) PositionToOffset

func (d *Document) PositionToOffset(pos Position) int

PositionToOffset converts a Position to a byte offset in the document.

type DocumentStore

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

DocumentStore manages open documents in memory.

func NewDocumentStore

func NewDocumentStore() *DocumentStore

NewDocumentStore creates a new document store.

func (*DocumentStore) Close

func (s *DocumentStore) Close(uri string)

Close removes a document from the store.

func (*DocumentStore) Get

func (s *DocumentStore) Get(uri string) *Document

Get retrieves a document by URI.

func (*DocumentStore) List

func (s *DocumentStore) List() []string

List returns all open document URIs.

func (*DocumentStore) Open

func (s *DocumentStore) Open(uri string, content string, version int)

Open adds or updates a document in the store.

func (*DocumentStore) Update

func (s *DocumentStore) Update(uri string, content string, version int)

Update modifies an existing document's content.

type Hover

type Hover struct {
	Contents MarkupContent `json:"contents"`
	Range    *Range        `json:"range,omitempty"`
}

Hover represents the result of a hover request.

type HoverParams

type HoverParams struct {
	TextDocumentPositionParams
}

HoverParams for hover requests.

type InitializeParams

type InitializeParams struct {
	ProcessID    int    `json:"processId"`
	RootURI      string `json:"rootUri"`
	Capabilities struct {
		TextDocument struct {
			Completion struct {
				CompletionItem struct {
					SnippetSupport bool `json:"snippetSupport"`
				} `json:"completionItem"`
			} `json:"completion"`
		} `json:"textDocument"`
	} `json:"capabilities"`
}

InitializeParams is sent as the first request from client to server.

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities `json:"capabilities"`
}

InitializeResult is the response to initialize request.

type InsertTextFormat

type InsertTextFormat int

InsertTextFormat defines whether the insert text is plain text or a snippet.

const (
	InsertTextFormatPlainText InsertTextFormat = 1
	InsertTextFormatSnippet   InsertTextFormat = 2
)

InsertTextFormat constants.

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error.

type JSONRPCMessage

type JSONRPCMessage struct {
	JSONRPC string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id,omitempty"`
	Method  string           `json:"method,omitempty"`
	Params  json.RawMessage  `json:"params,omitempty"`
	Result  json.RawMessage  `json:"result,omitempty"`
	Error   *JSONRPCError    `json:"error,omitempty"`
}

JSONRPCMessage represents a JSON-RPC 2.0 message.

type Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

Location represents a location inside a resource.

type MarkupContent

type MarkupContent struct {
	Kind  MarkupKind `json:"kind"`
	Value string     `json:"value"`
}

MarkupContent represents a string value with a specific markup type.

type MarkupKind

type MarkupKind string

MarkupKind describes the markup content type.

const (
	MarkupKindPlainText MarkupKind = "plaintext"
	MarkupKindMarkdown  MarkupKind = "markdown"
)

MarkupKind constants.

type MessageType

type MessageType int

MessageType indicates the type of a message.

const (
	MessageTypeError   MessageType = 1
	MessageTypeWarning MessageType = 2
	MessageTypeInfo    MessageType = 3
	MessageTypeLog     MessageType = 4
)

MessageType constants for showing messages to the client.

type Position

type Position struct {
	Line      uint32 `json:"line"`
	Character uint32 `json:"character"`
}

Position in a text document expressed as zero-based line and character offset.

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

PublishDiagnosticsParams are sent from server to client to publish diagnostics.

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

Range in a text document expressed as (zero-based) start and end positions.

type SaveOptions

type SaveOptions struct {
	IncludeText bool `json:"includeText,omitempty"`
}

SaveOptions for document save notifications.

type Server

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

Server implements the Language Server Protocol for LeapSQL.

func NewServer

func NewServer(reader io.Reader, writer io.Writer) *Server

NewServer creates a new LSP server instance.

func NewServerWithLogger

func NewServerWithLogger(reader io.Reader, writer io.Writer, logger *slog.Logger) *Server

NewServerWithLogger creates a new LSP server instance with a custom logger.

func (*Server) Run

func (s *Server) Run() error

Run starts the server's main loop, processing JSON-RPC messages.

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync           *TextDocumentSyncOptions `json:"textDocumentSync,omitempty"`
	CompletionProvider         *CompletionOptions       `json:"completionProvider,omitempty"`
	HoverProvider              bool                     `json:"hoverProvider,omitempty"`
	DefinitionProvider         bool                     `json:"definitionProvider,omitempty"`
	ReferencesProvider         bool                     `json:"referencesProvider,omitempty"`
	DocumentFormattingProvider bool                     `json:"documentFormattingProvider,omitempty"`
	CodeActionProvider         *CodeActionOptions       `json:"codeActionProvider,omitempty"`
}

ServerCapabilities describe what the server is capable of.

type ShowMessageParams

type ShowMessageParams struct {
	Type    MessageType `json:"type"`
	Message string      `json:"message"`
}

ShowMessageParams for window/showMessage notification.

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Range       *Range `json:"range,omitempty"`
	RangeLength uint32 `json:"rangeLength,omitempty"`
	Text        string `json:"text"`
}

TextDocumentContentChangeEvent describes changes to a text document.

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	URI string `json:"uri"`
}

TextDocumentIdentifier identifies a text document.

type TextDocumentItem

type TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int    `json:"version"`
	Text       string `json:"text"`
}

TextDocumentItem represents an item to transfer a text document from client to server.

type TextDocumentPositionParams

type TextDocumentPositionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

TextDocumentPositionParams is a parameter literal for requests that need a position.

type TextDocumentSyncKind

type TextDocumentSyncKind int

TextDocumentSyncKind defines how the client syncs document changes.

const (
	TextDocumentSyncKindNone        TextDocumentSyncKind = 0
	TextDocumentSyncKindFull        TextDocumentSyncKind = 1
	TextDocumentSyncKindIncremental TextDocumentSyncKind = 2
)

TextDocumentSyncKind constants.

type TextDocumentSyncOptions

type TextDocumentSyncOptions struct {
	OpenClose bool                 `json:"openClose,omitempty"`
	Change    TextDocumentSyncKind `json:"change,omitempty"`
	Save      *SaveOptions         `json:"save,omitempty"`
}

TextDocumentSyncOptions defines text document sync options.

type TextEdit

type TextEdit struct {
	Range   Range  `json:"range"`
	NewText string `json:"newText"`
}

TextEdit represents a textual edit applicable to a text document.

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	TextDocumentIdentifier
	Version int `json:"version"`
}

VersionedTextDocumentIdentifier identifies a specific version of a text document.

type WorkspaceEdit

type WorkspaceEdit struct {
	Changes map[string][]TextEdit `json:"changes,omitempty"`
}

WorkspaceEdit represents changes to many resources managed in the workspace.

Jump to

Keyboard shortcuts

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