this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

💬 Finish blog post on implementing a LSP server in Go

+46 -2
+46 -2
blog/making-an-lsp-server-in-go.md
··· 117 117 import ( 118 118 "context" 119 119 "go.lsp.dev/protocol" 120 + "go.lsp.dev/uri" 120 121 "go.uber.org/zap" 121 122 ) 122 123 ··· 165 166 166 167 Check with [the spec](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#serverCapabilities) to be sure. 167 168 169 + #### Example 170 + 171 + Here's an example method implementation that signals support for the Go to Definition feature: 172 + 173 + ```go 174 + func (h Handler) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) { 175 + return &protocol.InitializeResult{ 176 + Capabilities: protocol.ServerCapabilities{ 177 + DefinitionProvider: true, // <-- right there 178 + }, 179 + ServerInfo: &protocol.ServerInfo{ 180 + Name: "yourls", 181 + Version: "0.1.0", 182 + }, 183 + }, nil 184 + } 185 + ``` 186 + 168 187 ### Implementing a feature: the `Definition` example 169 188 189 + As with `Initialize`, hovering over the types of the parameters will help you greatly. 190 + 191 + ```go 192 + // IMPORTANT: You _can't_ take a pointer to your handler struct as the receiver, 193 + // your handler will no longer implement protocol.Server if you do that. 194 + func (h Handler) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error) { 195 + // ... do your processing ... 196 + return []protocol.Location{ 197 + { 198 + URI: uri.File(...), 199 + Range: protocol.Range{ 200 + Start: protocol.Position{ 201 + Line: 0, 202 + Character: 0, 203 + }, 204 + End: protocol.Position{ 205 + Line: 0, 206 + Character: 0, 207 + }, 208 + }, 209 + }, 210 + }, nil 211 + } 212 + ``` 213 + 170 214 ## Using in IDEs & editors 171 215 172 216 ### Neovim ··· 189 233 190 234 VSCode requires writing an entire extension to use an LSP server... 191 235 192 - If you want something quick 'n' dirty, you can use some generic 236 + If you want something quick 'n' dirty, you can use some generic 193 237 LSP client extension (for example, [llllvvuu's Generic LSP Client](https://marketplace.visualstudio.com/items?itemName=llllvvuu.llllvvuu-glspc)). 194 238 195 - But to do a proper extension that you can distribute to your user's, 239 + But to do a proper extension that you can distribute to your user's, 196 240 you'll want to follow [the vscode docs on LSP extension development](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide). 197 241 198 242 The 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.