Documentation
¶
Index ¶
- Variables
- func DetectLanguage(path string) string
- func FileToURI(path string) string
- func GetAllInstallInfos() map[string]InstallInfo
- func GetLanguageExtensions(serverKey string) []string
- func IsServerInstalled(serverKey string, configs map[string]ServerConfig) bool
- func LanguageServerKey(language string) string
- func RunInstall(serverKey string) error
- func URIToFile(uri string) string
- type Client
- func (c *Client) Close()
- func (c *Client) FindReferences(ctx context.Context, filePath string, line, character int, ...) ([]Location, error)
- func (c *Client) GetDiagnostics(ctx context.Context, filePath string) ([]Diagnostic, error)
- func (c *Client) GetHover(ctx context.Context, filePath string, line, character int) (*HoverResult, error)
- func (c *Client) GetServer(ctx context.Context, language string) (*Server, error)
- func (c *Client) GetServerForFile(ctx context.Context, filePath string) (*Server, error)
- func (c *Client) GoToDefinition(ctx context.Context, filePath string, line, character int) ([]Location, error)
- func (c *Client) Rename(ctx context.Context, filePath string, line, character int, newName string) (*WorkspaceEdit, error)
- func (c *Client) SetConfigs(configs map[string]ServerConfig)
- func (c *Client) Status() map[string]string
- type ClientCapabilities
- type DefinitionCapability
- type Diagnostic
- type DiagnosticSeverity
- type DidCloseTextDocumentParams
- type DidOpenTextDocumentParams
- type HoverCapability
- type HoverParams
- type HoverResult
- type InitializeParams
- type InitializeResult
- type InstallInfo
- type LanguageInfo
- type Location
- type MarkupContent
- type Notification
- type Position
- type PublishDiagnosticsParams
- type Range
- type ReferenceContext
- type ReferenceParams
- type ReferencesCapability
- type RenameParams
- type Request
- type Response
- type ResponseError
- type Server
- func (s *Server) Call(ctx context.Context, method string, params interface{}) (*Response, error)
- func (s *Server) ClearDiagnostics(filePath string)
- func (s *Server) Close() error
- func (s *Server) CloseDocument(path string) error
- func (s *Server) GetLastDiagnostics(filePath string) []Diagnostic
- func (s *Server) IsRunning() bool
- func (s *Server) Name() string
- func (s *Server) OpenDocument(path, languageID, content string) error
- func (s *Server) Start(ctx context.Context, command string, args []string, rootURI string) error
- type ServerCapabilities
- type ServerConfig
- type TextDocumentClientCapabilities
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
- type TextEdit
- type WorkspaceEdit
Constants ¶
This section is empty.
Variables ¶
var InstallCommands = map[string]InstallInfo{ "go": { ServerKey: "go", PackageName: "gopls", Commands: []string{"go install golang.org/x/tools/gopls@latest"}, }, "typescript": { ServerKey: "typescript", PackageName: "vtsls", Commands: []string{"npm i -g @vtsls/language-server typescript"}, }, "python": { ServerKey: "python", PackageName: "pyright", Commands: []string{"pip install pyright", "npm i -g pyright"}, }, "rust": { ServerKey: "rust", PackageName: "rust-analyzer", Commands: []string{"rustup component add rust-analyzer"}, }, "java": { ServerKey: "java", PackageName: "jdtls", Commands: []string{"brew install jdtls"}, }, "c": { ServerKey: "c", PackageName: "clangd", Commands: []string{"brew install llvm", "apt install clangd"}, }, "cpp": { ServerKey: "cpp", PackageName: "clangd", Commands: []string{"brew install llvm", "apt install clangd"}, }, "ruby": { ServerKey: "ruby", PackageName: "solargraph", Commands: []string{"gem install solargraph"}, }, "kotlin": { ServerKey: "kotlin", PackageName: "kotlin-language-server", Commands: []string{"brew install kotlin-language-server"}, }, "swift": { ServerKey: "swift", PackageName: "sourcekit-lsp", Commands: []string{}, }, "csharp": { ServerKey: "csharp", PackageName: "csharp-ls", Commands: []string{"dotnet tool install --global csharp-ls"}, }, "scala": { ServerKey: "scala", PackageName: "metals", Commands: []string{"brew install coursier/formulas/coursier && cs install metals"}, }, "php": { ServerKey: "php", PackageName: "intelephense", Commands: []string{"npm i -g intelephense"}, }, "elixir": { ServerKey: "elixir", PackageName: "elixir-ls", Commands: []string{"brew install elixir-ls"}, }, "lua": { ServerKey: "lua", PackageName: "lua-language-server", Commands: []string{"brew install lua-language-server", "apt install lua-language-server"}, }, "css": { ServerKey: "css", PackageName: "vscode-css-language-server", Commands: []string{"npm i -g vscode-langservers-extracted"}, }, "html": { ServerKey: "html", PackageName: "vscode-html-language-server", Commands: []string{"npm i -g vscode-langservers-extracted"}, }, "vue": { ServerKey: "vue", PackageName: "@vue/language-server", Commands: []string{"npm i -g @vue/language-server"}, }, "svelte": { ServerKey: "svelte", PackageName: "svelte-language-server", Commands: []string{"npm i -g svelte-language-server"}, }, "yaml": { ServerKey: "yaml", PackageName: "yaml-language-server", Commands: []string{"npm i -g yaml-language-server"}, }, "toml": { ServerKey: "toml", PackageName: "taplo", Commands: []string{"cargo install taplo-cli --locked"}, }, "sql": { ServerKey: "sql", PackageName: "sqls", Commands: []string{"go install github.com/lighttiger2505/sqls@latest"}, }, "bash": { ServerKey: "bash", PackageName: "bash-language-server", Commands: []string{"npm i -g bash-language-server"}, }, "markdown": { ServerKey: "markdown", PackageName: "marksman", Commands: []string{"brew install marksman"}, }, }
InstallCommands はサーバーキー -> インストール情報のマッピング
Functions ¶
func DetectLanguage ¶
DetectLanguage returns the language ID for a file based on its extension
func GetAllInstallInfos ¶
func GetAllInstallInfos() map[string]InstallInfo
GetAllInstallInfos は全てのインストール情報を返す
func GetLanguageExtensions ¶
GetLanguageExtensions は指定されたサーバーキーに対応する拡張子を返す
func IsServerInstalled ¶
func IsServerInstalled(serverKey string, configs map[string]ServerConfig) bool
IsServerInstalled はLSPサーバーがインストールされているかチェック
func LanguageServerKey ¶
LanguageServerKey returns the key used in LSP configuration for a language This maps language IDs to their server configuration keys
func RunInstall ¶
RunInstall はLSPサーバーをインストール(最初のコマンドを実行) 成功した場合は nil、失敗した場合はエラーを返す
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages multiple LSP servers (one per language)
func (*Client) FindReferences ¶
func (c *Client) FindReferences(ctx context.Context, filePath string, line, character int, includeDeclaration bool) ([]Location, error)
FindReferences finds all references to a symbol
func (*Client) GetDiagnostics ¶
GetDiagnostics gets diagnostics (errors, warnings) for a file
func (*Client) GetHover ¶
func (c *Client) GetHover(ctx context.Context, filePath string, line, character int) (*HoverResult, error)
GetHover gets hover information for a symbol
func (*Client) GetServer ¶
GetServer returns the server for a language, starting it lazily if needed
func (*Client) GetServerForFile ¶
GetServerForFile returns the appropriate server for a file path
func (*Client) GoToDefinition ¶
func (c *Client) GoToDefinition(ctx context.Context, filePath string, line, character int) ([]Location, error)
GoToDefinition finds the definition of a symbol
func (*Client) Rename ¶
func (c *Client) Rename(ctx context.Context, filePath string, line, character int, newName string) (*WorkspaceEdit, error)
Rename renames a symbol at the given position to a new name
func (*Client) SetConfigs ¶
func (c *Client) SetConfigs(configs map[string]ServerConfig)
SetConfigs sets the server configurations
type ClientCapabilities ¶
type ClientCapabilities struct {
TextDocument TextDocumentClientCapabilities `json:"textDocument,omitempty"`
}
ClientCapabilities represents the client's capabilities
type DefinitionCapability ¶
type DefinitionCapability struct {
DynamicRegistration bool `json:"dynamicRegistration,omitempty"`
}
DefinitionCapability represents definition capability
type Diagnostic ¶
type Diagnostic struct {
Range Range `json:"range"`
Severity DiagnosticSeverity `json:"severity,omitempty"`
Code interface{} `json:"code,omitempty"` // string or number
Source string `json:"source,omitempty"`
Message string `json:"message"`
}
Diagnostic represents a diagnostic (error, warning, info, hint)
type DiagnosticSeverity ¶
type DiagnosticSeverity int
DiagnosticSeverity represents the severity of a diagnostic
const ( DiagnosticSeverityError DiagnosticSeverity = 1 DiagnosticSeverityWarning DiagnosticSeverity = 2 DiagnosticSeverityInformation DiagnosticSeverity = 3 DiagnosticSeverityHint DiagnosticSeverity = 4 )
type DidCloseTextDocumentParams ¶
type DidCloseTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
DidCloseTextDocumentParams are the parameters for the didClose notification
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
DidOpenTextDocumentParams are the parameters for the didOpen notification
type HoverCapability ¶
type HoverCapability struct {
DynamicRegistration bool `json:"dynamicRegistration,omitempty"`
}
HoverCapability represents hover capability
type HoverParams ¶
type HoverParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
HoverParams are the parameters for the hover request
type HoverResult ¶
type HoverResult struct {
Contents MarkupContent `json:"contents"`
Range *Range `json:"range,omitempty"`
}
HoverResult is the result of a hover request
type InitializeParams ¶
type InitializeParams struct {
ProcessID int `json:"processId"`
RootURI string `json:"rootUri"`
Capabilities ClientCapabilities `json:"capabilities"`
}
InitializeParams are the parameters for the initialize request
type InitializeResult ¶
type InitializeResult struct {
Capabilities ServerCapabilities `json:"capabilities"`
}
InitializeResult is the result of the initialize request
type InstallInfo ¶
type InstallInfo struct {
ServerKey string // サーバーキー(go, typescript等)
PackageName string // パッケージ名(gopls, vtsls等)
Commands []string // インストールコマンド(複数可: 1つ目を優先)
}
InstallInfo はLSPサーバーのインストール情報
func GetInstallInfo ¶
func GetInstallInfo(serverKey string) (InstallInfo, bool)
GetInstallInfo はサーバーキーからインストール情報を取得
type LanguageInfo ¶
type LanguageInfo struct {
ServerKey string // LSP設定のキー(go, typescript等)
Extensions []string // 検出された拡張子
FileCount int // ファイル数
}
LanguageInfo は検出された言語の情報
func DetectProjectLanguages ¶
func DetectProjectLanguages(rootDir string) ([]LanguageInfo, error)
DetectProjectLanguages はプロジェクト内の言語を検出
type MarkupContent ¶
type MarkupContent struct {
Kind string `json:"kind"` // "plaintext" or "markdown"
Value string `json:"value"`
}
MarkupContent represents markup content (plaintext or markdown)
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Notification represents a JSON-RPC 2.0 notification (no ID, no response expected)
type Position ¶
type Position struct {
Line int `json:"line"` // 0-indexed line number
Character int `json:"character"` // 0-indexed character offset
}
Position represents a position in a text document (0-indexed)
type PublishDiagnosticsParams ¶
type PublishDiagnosticsParams struct {
URI string `json:"uri"`
Diagnostics []Diagnostic `json:"diagnostics"`
}
PublishDiagnosticsParams are the parameters for the publishDiagnostics notification
type ReferenceContext ¶
type ReferenceContext struct {
IncludeDeclaration bool `json:"includeDeclaration"`
}
ReferenceContext represents the context for a reference request
type ReferenceParams ¶
type ReferenceParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
Context ReferenceContext `json:"context"`
}
ReferenceParams are the parameters for the references request
type ReferencesCapability ¶
type ReferencesCapability struct {
DynamicRegistration bool `json:"dynamicRegistration,omitempty"`
}
ReferencesCapability represents references capability
type RenameParams ¶
type RenameParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
NewName string `json:"newName"`
}
RenameParams are the parameters for the rename request
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response
type ResponseError ¶
type ResponseError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
ResponseError represents a JSON-RPC 2.0 error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server manages a single LSP server process
func (*Server) ClearDiagnostics ¶
ClearDiagnostics clears diagnostics for a file
func (*Server) CloseDocument ¶
CloseDocument sends a textDocument/didClose notification
func (*Server) GetLastDiagnostics ¶
func (s *Server) GetLastDiagnostics(filePath string) []Diagnostic
GetLastDiagnostics returns the last received diagnostics for a file
func (*Server) OpenDocument ¶
OpenDocument sends a textDocument/didOpen notification
type ServerCapabilities ¶
type ServerCapabilities struct {
ReferencesProvider bool `json:"referencesProvider,omitempty"`
DefinitionProvider bool `json:"definitionProvider,omitempty"`
HoverProvider bool `json:"hoverProvider,omitempty"`
TextDocumentSync int `json:"textDocumentSync,omitempty"` // 0=None, 1=Full, 2=Incremental
}
ServerCapabilities represents the server's capabilities
type ServerConfig ¶
ServerConfig holds configuration for an LSP server
type TextDocumentClientCapabilities ¶
type TextDocumentClientCapabilities struct {
References *ReferencesCapability `json:"references,omitempty"`
Definition *DefinitionCapability `json:"definition,omitempty"`
Hover *HoverCapability `json:"hover,omitempty"`
}
TextDocumentClientCapabilities represents text document capabilities
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 a text document (for didOpen)
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
TextDocumentPositionParams represents a position in a text document
type WorkspaceEdit ¶
WorkspaceEdit represents changes to many resources managed in the workspace