lsp

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiagnosticSeverityError   = 1
	DiagnosticSeverityWarning = 2
	DiagnosticSeverityInfo    = 3
	DiagnosticSeverityHint    = 4
)
View Source
const (
	CompletionItemKindText     = 1
	CompletionItemKindMethod   = 2
	CompletionItemKindFunction = 3
	CompletionItemKindField    = 5
	CompletionItemKindVariable = 6
	CompletionItemKindProperty = 10
	CompletionItemKindKeyword  = 14
	CompletionItemKindSnippet  = 15
)
View Source
const (
	InsertTextFormatPlainText = 1
	InsertTextFormatSnippet   = 2
)
View Source
const (
	SymbolKindNamespace = 3
	SymbolKindFunction  = 12
	SymbolKindString    = 15
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeAction

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

type CodeActionContext

type CodeActionContext struct {
	Diagnostics []Diagnostic `json:"diagnostics"`
}

type CodeActionParams

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

type CompletionItem

type CompletionItem struct {
	Label            string    `json:"label"`
	Detail           string    `json:"detail,omitempty"`
	Documentation    string    `json:"documentation,omitempty"`
	Kind             int       `json:"kind"`
	InsertText       string    `json:"insertText,omitempty"`
	InsertTextFormat int       `json:"insertTextFormat,omitempty"`
	TextEdit         *TextEdit `json:"textEdit,omitempty"`
}

type CompletionList

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

type CompletionOptions

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

type Diagnostic

type Diagnostic struct {
	Range    Range  `json:"range"`
	Severity int    `json:"severity"`
	Source   string `json:"source"`
	Message  string `json:"message"`
}

type DiagnosticOptions

type DiagnosticOptions struct {
	InterFileDependencies bool `json:"interFileDependencies"`
	WorkspaceDiagnostics  bool `json:"workspaceDiagnostics"`
}

type DidChangeTextDocumentParams

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

type DidChangeWatchedFilesParams

type DidChangeWatchedFilesParams struct {
	Changes []FileEvent `json:"changes"`
}

type DidCloseTextDocumentParams

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

type DidOpenTextDocumentParams

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

type DidSaveTextDocumentParams

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

type Document

type Document struct {
	URI     string
	Version int
	Content string
}

Document represents an open text document.

type DocumentDiagnosticParams

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

type DocumentDiagnosticReport

type DocumentDiagnosticReport struct {
	Kind  string       `json:"kind"`
	Items []Diagnostic `json:"items"`
}

type DocumentFormattingParams

type DocumentFormattingParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Options      FormattingOptions      `json:"options"`
}

type DocumentStore

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

DocumentStore tracks open text documents.

func NewDocumentStore

func NewDocumentStore() *DocumentStore

func (*DocumentStore) All

func (ds *DocumentStore) All() []*Document

All returns all open documents.

func (*DocumentStore) Change

func (ds *DocumentStore) Change(uri string, version int, content string)

func (*DocumentStore) Close

func (ds *DocumentStore) Close(uri string)

func (*DocumentStore) Get

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

func (*DocumentStore) IsOpen

func (ds *DocumentStore) IsOpen(uri string) bool

IsOpen returns true if the URI is currently open in the editor.

func (*DocumentStore) Open

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

type DocumentSymbol

type DocumentSymbol struct {
	Name           string           `json:"name"`
	Detail         string           `json:"detail,omitempty"`
	Kind           int              `json:"kind"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

type DocumentSymbolParams

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

DocumentSymbolParams for textDocument/documentSymbol.

type FileEvent

type FileEvent struct {
	URI  string `json:"uri"`
	Type int    `json:"type"`
}

type FormattingOptions

type FormattingOptions struct {
	TabSize                uint32 `json:"tabSize"`
	InsertSpaces           bool   `json:"insertSpaces"`
	TrimTrailingWhitespace bool   `json:"trimTrailingWhitespace,omitempty"`
}

type Handler

type Handler interface {
	Initialize(params InitializeParams) (InitializeResult, error)
	DidOpen(params DidOpenTextDocumentParams)
	DidChange(params DidChangeTextDocumentParams)
	DidClose(params DidCloseTextDocumentParams)
	DidSave(params DidSaveTextDocumentParams)
	DidChangeWatchedFiles(params DidChangeWatchedFilesParams)
	Hover(params TextDocumentPositionParams) (*Hover, error)
	Definition(params TextDocumentPositionParams) (*Location, error)
	Completion(params TextDocumentPositionParams) (CompletionList, error)
	DocumentSymbol(params DocumentSymbolParams) ([]DocumentSymbol, error)
	References(params ReferenceParams) ([]Location, error)
	SemanticTokensFull(params SemanticTokensParams) (SemanticTokens, error)
	Diagnostic(params DocumentDiagnosticParams) (DocumentDiagnosticReport, error)
	WorkspaceSymbol(params WorkspaceSymbolParams) ([]SymbolInformation, error)
	Rename(params RenameParams) (*WorkspaceEdit, error)
	PrepareRename(params PrepareRenameParams) (*Range, error)
	CodeAction(params CodeActionParams) ([]CodeAction, error)
	Formatting(params DocumentFormattingParams) ([]TextEdit, error)
}

Handler interface for routing LSP methods.

type Hover

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

type InitializeParams

type InitializeParams struct {
	RootURI      string          `json:"rootUri"`
	Capabilities json.RawMessage `json:"capabilities"`
}

type InitializeResult

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

type Location

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

type MarkupContent

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

type Position

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

type PrepareRenameParams

type PrepareRenameParams struct {
	TextDocumentPositionParams
}

type PublishDiagnosticsParams

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

type Range

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

type ReferenceContext

type ReferenceContext struct {
	IncludeDeclaration bool `json:"includeDeclaration"`
}

type ReferenceParams

type ReferenceParams struct {
	TextDocumentPositionParams
	Context ReferenceContext `json:"context"`
}

type RenameOptions

type RenameOptions struct {
	PrepareProvider bool `json:"prepareProvider"`
}

type RenameParams

type RenameParams struct {
	TextDocumentPositionParams
	NewName string `json:"newName"`
}

type SemanticTokens

type SemanticTokens struct {
	Data []uint32 `json:"data"`
}

type SemanticTokensLegend

type SemanticTokensLegend struct {
	TokenTypes     []string `json:"tokenTypes"`
	TokenModifiers []string `json:"tokenModifiers"`
}

type SemanticTokensOptions

type SemanticTokensOptions struct {
	Full   bool                 `json:"full"`
	Legend SemanticTokensLegend `json:"legend"`
}

type SemanticTokensParams

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

SemanticTokensParams for textDocument/semanticTokens/full.

type Server

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

Server is the LSP server.

func NewServer

func NewServer(transport *jsonrpc.Transport, handler Handler) *Server

func (*Server) LogMessage added in v0.1.6

func (s *Server) LogMessage(msgType int, message string)

LogMessage sends a window/logMessage notification to the client.

func (*Server) Notify

func (s *Server) Notify(method string, params interface{})

Notify sends a notification to the client.

func (*Server) OpenDocuments

func (s *Server) OpenDocuments() []*Document

OpenDocuments returns all currently open documents.

func (*Server) RegisterFileWatchers

func (s *Server) RegisterFileWatchers()

RegisterFileWatchers sends a client/registerCapability request to watch Go files.

func (*Server) Run

func (s *Server) Run() error

Run starts the main message loop.

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync           int                    `json:"textDocumentSync"`
	HoverProvider              bool                   `json:"hoverProvider"`
	DefinitionProvider         bool                   `json:"definitionProvider"`
	CompletionProvider         *CompletionOptions     `json:"completionProvider,omitempty"`
	DocumentSymbolProvider     bool                   `json:"documentSymbolProvider"`
	ReferencesProvider         bool                   `json:"referencesProvider"`
	SemanticTokensProvider     *SemanticTokensOptions `json:"semanticTokensProvider,omitempty"`
	DiagnosticProvider         *DiagnosticOptions     `json:"diagnosticProvider,omitempty"`
	WorkspaceSymbolProvider    bool                   `json:"workspaceSymbolProvider,omitempty"`
	DocumentFormattingProvider bool                   `json:"documentFormattingProvider,omitempty"`
	CodeActionProvider         bool                   `json:"codeActionProvider,omitempty"`
	RenameProvider             *RenameOptions         `json:"renameProvider,omitempty"`
}

type SymbolInformation

type SymbolInformation struct {
	Name     string   `json:"name"`
	Kind     int      `json:"kind"`
	Location Location `json:"location"`
}

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Text string `json:"text"`
}

type TextDocumentIdentifier

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

type TextDocumentItem

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

type TextDocumentPositionParams

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

type TextEdit

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

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	URI     string `json:"uri"`
	Version int    `json:"version"`
}

type WorkspaceEdit

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

type WorkspaceSymbolParams

type WorkspaceSymbolParams struct {
	Query string `json:"query"`
}

Jump to

Keyboard shortcuts

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