Skip to content

Commit e3155c6

Browse files
committed
Code review changes
1 parent 4faad0d commit e3155c6

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

docs/contributing/plugin-tutorial.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Here is a visual statement of what we want to accomplish:
6060

6161
And here is the gist of the algorithm:
6262

63-
1. Request the type checking artefacts from the `ghcide` subsystem
63+
1. Request the type checking artefacts
6464
2. Extract the actual import lists from the type checked AST,
6565
3. Ask GHC to produce the minimal import lists for this AST,
6666
4. For every import statement without a explicit import list:
@@ -69,20 +69,11 @@ And here is the gist of the algorithm:
6969

7070
## Setup
7171

72-
To get started, lets 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, lets 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.
7373

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.
7575

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:
77-
78-
```sh
79-
cabal list-bin exe:haskell-language-server
80-
path/to/hls/dist-newstyle/build/x86_64-linux/ghc-9.2.7/haskell-language-server-2.0.0.0/x/haskell-language-server/build/haskell-language-server/haskell-language-server
81-
```
82-
83-
> **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-
![Settings](settings-vscode.png)
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.
8677

8778
## Anatomy of a plugin
8879

@@ -99,10 +90,10 @@ data PluginDescriptor (ideState :: *) =
9990
```
10091
A plugin has a unique id, command handlers, request handlers, notification handlers and rules:
10192

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.
10393
* Request handlers are called when an LSP client asks the server for information. These queries must be fulfilled as quickly as possible.
10494
* 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 do not need to define new rules.
95+
* Rules add new targets to the Shake build graph. Most plugins do not 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.
10697

10798
## The explicit imports plugin
10899

@@ -134,11 +125,11 @@ We'll start with the command, since it's the simplest of the two.
134125

135126
In short, commands works like this:
136127
- 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.
138129

139130
> **Note**: Check the [LSP spec](https://microsoft.github.io/language-server-protocol/specification) for a deeper understanding of how commands work.
140131
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:
142133

143134
```haskell
144135
-- hls-plugin-api/src/Ide/Types.hs
@@ -166,7 +157,7 @@ importLensCommand =
166157
runImportCommand = undefined
167158
```
168159

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`:
170161

171162
```haskell
172163
-- hls-plugin-api/src/Ide/Types.hs
@@ -195,13 +186,13 @@ runImportCommand _ (ImportCommandParams edit) = do
195186
return (Right Null)
196187
```
197188

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`.
199190

200191
### The code lens provider
201192

202193
The code lens provider implements all the steps of the algorithm described earlier:
203194

204-
> 1. Request the type checking artefacts from the ghcide subsystem
195+
> 1. Request the type checking artefacts
205196
> 2. Extract the actual import lists from the type checked AST,
206197
> 3. Ask GHC to produce the minimal import lists for this AST,
207198
> 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:
333324
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.
334325
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.
335326

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:
337328
```haskell
338329
data CodeLens =
339330
CodeLens

0 commit comments

Comments
 (0)