···117117import (
118118 "context"
119119 "go.lsp.dev/protocol"
120120+ "go.lsp.dev/uri"
120121 "go.uber.org/zap"
121122)
122123···165166166167Check with [the spec](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#serverCapabilities) to be sure.
167168169169+#### Example
170170+171171+Here's an example method implementation that signals support for the Go to Definition feature:
172172+173173+```go
174174+func (h Handler) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) {
175175+ return &protocol.InitializeResult{
176176+ Capabilities: protocol.ServerCapabilities{
177177+ DefinitionProvider: true, // <-- right there
178178+ },
179179+ ServerInfo: &protocol.ServerInfo{
180180+ Name: "yourls",
181181+ Version: "0.1.0",
182182+ },
183183+ }, nil
184184+}
185185+```
186186+168187### Implementing a feature: the `Definition` example
169188189189+As with `Initialize`, hovering over the types of the parameters will help you greatly.
190190+191191+```go
192192+// IMPORTANT: You _can't_ take a pointer to your handler struct as the receiver,
193193+// your handler will no longer implement protocol.Server if you do that.
194194+func (h Handler) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) {
195195+ // ... do your processing ...
196196+ return []protocol.Location{
197197+ {
198198+ URI: uri.File(...),
199199+ Range: protocol.Range{
200200+ Start: protocol.Position{
201201+ Line: 0,
202202+ Character: 0,
203203+ },
204204+ End: protocol.Position{
205205+ Line: 0,
206206+ Character: 0,
207207+ },
208208+ },
209209+ },
210210+ }, nil
211211+}
212212+```
213213+170214## Using in IDEs & editors
171215172216### Neovim
···189233190234VSCode requires writing an entire extension to use an LSP server...
191235192192-If you want something quick 'n' dirty, you can use some generic
236236+If you want something quick 'n' dirty, you can use some generic
193237LSP client extension (for example, [llllvvuu's Generic LSP Client](https://marketplace.visualstudio.com/items?itemName=llllvvuu.llllvvuu-glspc)).
194238195195-But to do a proper extension that you can distribute to your user's,
239239+But to do a proper extension that you can distribute to your user's,
196240you'll want to follow [the vscode docs on LSP extension development](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide).
197241198242The guide assumes that you'll develop the LSP server in NodeJS too, but you can easily `rm -rf` the hell out of the `server/` directory from their template repository.