You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/contributing/plugin-tutorial.md
+12-21Lines changed: 12 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ Here is a visual statement of what we want to accomplish:
60
60
61
61
And here is the gist of the algorithm:
62
62
63
-
1.Request the type checking artefacts from the `ghcide` subsystem
63
+
1.Request the type checking artefacts
64
64
2.Extract the actual import lists from the type checked AST,
65
65
3.AskGHC to produce the minimal import lists for this AST,
66
66
4.For every import statement without a explicit import list:
@@ -69,20 +69,11 @@ And here is the gist of the algorithm:
69
69
70
70
## Setup
71
71
72
-
To get started, let’s fetch the HLS repo and build it by following the [installation instructions](https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#building) in the Contributing section of this documentation.
72
+
To get started, let’s fetch the HLS repo and build it by following the [setup instructions](https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#building) in the Contributing section of this documentation.
73
73
74
-
If you run into any issues trying to build the binaries, you can get in touch with the HLS team using one of the [contact channels](https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#how-to-contact-the-haskell-ide-team) or [open an issue](https://github.com/haskell/haskell-language-server/issues/new?assignees=&labels=status%3A+needs+triage%2C+type%3A+support&projects=&template=support.md&title=) in the HLS repository.
74
+
If you run into any issues trying to build the binaries, you can get in touch with the HLS team using one of the [contact channels](https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#how-to-contact-the-haskell-ide-team) or [open an issue](https://github.com/haskell/haskell-language-server/issues) in the HLS repository.
75
75
76
-
Once the build is done, you can find the location of the `haskell-language-server` binary with ` cabal list-bin exe:haskell-language-server` and point your LSP client to it:
> **Note:** In VSCode this is done by editing the "Haskell Server Executable Path" setting. This way you can simply test your changes by reloading your editor after rebuilding the binary.
84
-
85
-

76
+
Make sure you use the HLS package you just built by following [this section](https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#manually-testing-your-hacked-hls) of the "Contributing" guide.
86
77
87
78
## Anatomy of a plugin
88
79
@@ -99,10 +90,10 @@ data PluginDescriptor (ideState :: *) =
99
90
```
100
91
A plugin has a unique id, command handlers, request handlers, notification handlers and rules:
101
92
102
-
*Commands are an LSP abstraction for actions initiated by the user which are handled in the server.These actions can be long running and involve multiple modules.
103
93
*Request handlers are called when an LSP client asks the server for information.These queries must be fulfilled as quickly as possible.
104
94
*Notification handlers are called by code that was not directly triggerd by an user/client.
105
-
*Rules add new targets to the Shake build graph defined in ghcide.Most plugins donot need to define new rules.
95
+
*Rules add new targets to the Shake build graph.Most plugins donot need to define new rules.
96
+
*Commands are an LSP abstraction for actions initiated by the user which are handled in the server.These actions can be long running and involve multiple modules.
106
97
107
98
## The explicit imports plugin
108
99
@@ -134,11 +125,11 @@ We'll start with the command, since it's the simplest of the two.
134
125
135
126
In short, commands works like this:
136
127
- The LSP server (HLS) initially sends a command descriptor to the client, in this case as part of a code lens.
137
-
- Whenever the client decides to execute the command on behalf of a user action (in this case a click on the code lens), it sends this same descriptor back to the LSP server which then proceeds to handle and execute the command. The latter part is implemented by the `commandFunc` field of our `PluginCommand` value.
128
+
- Whenever the client decides to execute the command on behalf of a user (in this case a click on the code lens), it sends this same descriptor back to the LSP server which then proceeds to handle and execute the command. The latter part is implemented by the `commandFunc` field of our `PluginCommand` value.
138
129
139
130
> **Note**: Check the [LSP spec](https://microsoft.github.io/language-server-protocol/specification) for a deeper understanding of how commands work.
140
131
141
-
The command handler will be called `importLensCommand` and have the `PluginCommand` type, which is a type synonym defined in `Ide.Types` as:
132
+
The command handler will be called `importLensCommand` and have the `PluginCommand` type, which is a type defined in `Ide.Types` as:
142
133
143
134
```haskell
144
135
-- hls-plugin-api/src/Ide/Types.hs
@@ -166,7 +157,7 @@ importLensCommand =
166
157
runImportCommand =undefined
167
158
```
168
159
169
-
The most important (and still `undefined`) field is `commandFunc :: CommandFunction`, another type synonym from `LSP.Types`:
160
+
The most important (and still `undefined`) field is `commandFunc :: CommandFunction`, a type synonym from `LSP.Types`:
170
161
171
162
```haskell
172
163
-- hls-plugin-api/src/Ide/Types.hs
@@ -195,13 +186,13 @@ runImportCommand _ (ImportCommandParams edit) = do
195
186
return (RightNull)
196
187
```
197
188
198
-
It [sends a request](https://hackage.haskell.org/package/lsp-1.6.0.0/docs/Language-LSP-Server.html#v:sendRequest) with the method `SWorkspaceApplyEdit` to the server with the `ApplyWorkspaceEditParams Nothing edit` parameters and a response handler (that does nothing). It then returns `Right Null`, an empty `Aeson.Value` wrapped in `Right`.
189
+
It [sends a request](https://hackage.haskell.org/package/lsp-1.6.0.0/docs/Language-LSP-Server.html#v:sendRequest) with the method `SWorkspaceApplyEdit` to the client with the `ApplyWorkspaceEditParams Nothing edit` parameters and a response handler (that does nothing). It then returns `Right Null`, an empty `Aeson.Value` wrapped in `Right`.
199
190
200
191
### The code lens provider
201
192
202
193
The code lens provider implements all the steps of the algorithm described earlier:
203
194
204
-
> 1. Request the type checking artefacts from the ghcide subsystem
195
+
> 1. Request the type checking artefacts
205
196
> 2. Extract the actual import lists from the type checked AST,
206
197
> 3. Ask GHC to produce the minimal import lists for this AST,
207
198
> 4. For every import statement without a explicit import list, find out what's the minimal import list, and produce a code lens to display it together with a diff to graft the import list in.
@@ -333,7 +324,7 @@ TODO: Figure out what to do with the following sections:
333
324
If you have used VSCode or any other LSP editor you are probably already familiar with the capabilities afforded by LSP. If not, check the [specification](https://microsoft.github.io/language-server-protocol/specification) for the full details.
334
325
Another good source of information is the [haskell-lsp-types](https://hackage.haskell.org/package/haskell-lsp-types) package, which contains a Haskell encoding of the protocol.
335
326
336
-
The [haskell-lsp-types](https://hackage.haskell.org/package/haskell-lsp-types-0.22.0.0/docs/Language-Haskell-LSP-Types.html#t:CodeLens) package encodes code lenses in Haskell as:
327
+
The [haskell-lsp-types](https://hackage.haskell.org/package/lsp-types) package encodes code lenses in Haskell as:
0 commit comments