Skip to content

Commit dda3e5e

Browse files
Enable rename plugin (#2809)
* refactor rename plugin - add context to error messages - remove unnecessary unwrapping of ParsedSource - use HashSet for references - consistent naming, whitespace, indentation, imports style * prevent renaming of built-in syntax * limit rename scope to current module * refine imports in rename plugin * allow renaming with implicit module names * update tests with cross-module renaming limitation * enable rename plugin - add rename package to hackage CI - set default build flag to True * add rename plugin to features docs * add rename plugin to ghc-8.10.X stack yaml files * improve position printing in rename error * implement cross-module rename config option * unignore tests for cross-module renames * update docs for cross-module renaming * fix within module renaming for ghc-9 * fix rename plugin language extensions for ghc-92 * add explicit GHC.Parser imports in rename plugin * fix typo in rename docs * use implicit import lists in rename plugin * relocate orphaned instances from rename plugin * Revert "relocate orphaned instances from rename plugin" This reverts commit bb91db0. Co-authored-by: Pepe Iborra <[email protected]>
1 parent 21c4510 commit dda3e5e

18 files changed

+239
-145
lines changed

.github/workflows/hackage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
"hls-class-plugin", "hls-eval-plugin", "hls-explicit-imports-plugin",
3434
"hls-haddock-comments-plugin", "hls-hlint-plugin",
3535
"hls-module-name-plugin", "hls-pragmas-plugin",
36-
"hls-refine-imports-plugin", "hls-retrie-plugin",
36+
"hls-refine-imports-plugin", "hls-rename-plugin", "hls-retrie-plugin",
3737
"hls-splice-plugin", "hls-tactics-plugin",
3838
"hls-call-hierarchy-plugin", "hls-alternate-number-format-plugin",
3939
"hls-qualify-imported-names-plugin", "hls-selection-range-plugin",

docs/configuration.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Here is a list of the additional settings currently supported by `haskell-langua
5050
Plugins have a generic config to control their behaviour. The schema of such config is:
5151

5252
- `haskell.plugin.${pluginName}.globalOn`: usually with default true. Whether the plugin is enabled at runtime or it is not. That is the option you might use if you want to disable completely a plugin.
53-
- Actual plugin names are: `ghcide-code-actions-fill-holes`, `ghcide-completions`, `ghcide-hover-and-symbols`, `ghcide-type-lenses`, `ghcide-code-actions-type-signatures`, `ghcide-code-actions-bindings`, `ghcide-code-actions-imports-exports`, `eval`, `moduleName`, `pragmas`, `refineImports`, `importLens`, `class`, `tactics` (aka wingman), `hlint`, `haddockComments`, `retrie`, `splice`.
53+
- Actual plugin names are: `ghcide-code-actions-fill-holes`, `ghcide-completions`, `ghcide-hover-and-symbols`, `ghcide-type-lenses`, `ghcide-code-actions-type-signatures`, `ghcide-code-actions-bindings`, `ghcide-code-actions-imports-exports`, `eval`, `moduleName`, `pragmas`, `refineImports`, `importLens`, `class`, `tactics` (aka wingman), `hlint`, `haddockComments`, `retrie`, `rename`, `splice`.
5454
- So to disable the import lens with an explicit list of module definitions you could set `haskell.plugin.importLens.globalOn: false`
5555
- `haskell.plugin.${pluginName}.${lspCapability}On`: usually with default true. Whether a concrete plugin capability is enabled.
5656
- Capabilities are the different ways a lsp server can interact with the editor. The current available capabilities of the server are: `callHierarchy`, `codeActions`, `codeLens`, `diagnostics`, `hover`, `symbols`, `completion`, `rename`.
@@ -66,6 +66,8 @@ Plugins have a generic config to control their behaviour. The schema of such con
6666
- `eval`:
6767
- `haskell.plugin.eval.config.diff`, default true: When reloading haddock test results in changes, mark it with WAS/NOW.
6868
- `haskell.plugin.eval.config.exception`, default false: When the command results in an exception, mark it with `*** Exception:`.
69+
- `rename`:
70+
- `haskell.plugin.rename.config.diff`, default false: Enables renaming across modules (experimental)
6971
- `ghcide-completions`:
7072
- `haskell.plugin.ghcide-completions.config.snippetsOn`, default true: Inserts snippets when using code completions.
7173
- `haskell.plugin.ghcide-completions.config.autoExtendOn`, default true: Extends the import list automatically when completing a out-of-scope identifier.

docs/features.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Many of these are standard LSP features, but a lot of special features are provi
1919
| [Code actions](#code-actions) | `textDocument/codeAction` |
2020
| [Code lenses](#code-lenses) | `textDocument/codeLens` |
2121
| [Selection range](#selection-range) | `textDocument/selectionRange` |
22+
| [Rename](#rename) | `textDocument/rename` |
2223

2324
The individual sections below also identify which [HLS plugin](./what-is-hls.md#hls-plugins) is responsible for providing the given functionality, which is useful if you want to raise an issue report or contribute!
2425
Additionally, not all plugins are supported on all versions of GHC, see the [GHC version support page](supported-versions.md) for details.
@@ -305,6 +306,18 @@ support.
305306

306307
![Selection range demo](https://user-images.githubusercontent.com/16440269/150301502-4c002605-9f8d-43f5-86d3-28846942c4ff.mov)
307308

309+
## Rename
310+
311+
Provided by: `hls-rename-plugin`
312+
313+
Provides renaming of symbols within a module. Experimental cross-module renaming can be enabled via the configuration.
314+
315+
![Rename Demo](https://user-images.githubusercontent.com/30090176/133072143-d7d03ec7-3db1-474e-ad5e-6f40d75ff7ab.gif)
316+
317+
Known limitations:
318+
319+
- Cross-module renaming requires all components to be indexed, which sometimes causes [partial renames in multi-component projects](https://github.com/haskell/haskell-language-server/issues/2193).
320+
308321
## Missing features
309322

310323
The following features are supported by the LSP specification but not implemented in HLS.
@@ -315,7 +328,6 @@ Contributions welcome!
315328
| Signature help | Unimplemented | `textDocument/signatureHelp` |
316329
| Jump to declaration | Unclear if useful | `textDocument/declaration` |
317330
| Jump to implementation | Unclear if useful | `textDocument/implementation` |
318-
| Renaming | [Parital implementation](https://github.com/haskell/haskell-language-server/issues/2193) | `textDocument/rename`, `textDocument/prepareRename` |
319331
| Folding | Unimplemented | `textDocument/foldingRange` |
320332
| Semantic tokens | Unimplemented | `textDocument/semanticTokens` |
321333
| Linked editing | Unimplemented | `textDocument/linkedEditingRange` |

docs/supported-versions.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
4949
| `hls-pragmas-plugin` | |
5050
| `hls-qualify-imported-names-plugin` | |
5151
| `hls-refine-imports-plugin` | |
52+
| `hls-rename-plugin` | |
5253
| `hls-retrie-plugin` | 9.2 |
5354
| `hls-splice-plugin` | 9.2 |
5455
| `hls-stylish-haskell-plugin` | 9.0, 9.2 |

ghcide/src/Development/IDE/Spans/AtPoint.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Development.IDE.Spans.AtPoint (
1717
, computeTypeReferences
1818
, FOIReferences(..)
1919
, defRowToSymbolInfo
20-
, getAstNamesAtPoint
20+
, getNamesAtPoint
2121
, toCurrentLocation
2222
, rowToLoc
2323
) where
@@ -86,7 +86,7 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
8686
case HM.lookup file asts of
8787
Nothing -> ([],[],[])
8888
Just (HAR _ hf _ _ _,mapping) ->
89-
let names = getAstNamesAtPoint hf pos mapping
89+
let names = getNamesAtPoint hf pos mapping
9090
adjustedLocs = HM.foldr go [] asts
9191
go (HAR _ _ rf tr _, mapping) xs = refs ++ typerefs ++ xs
9292
where
@@ -96,8 +96,8 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
9696
$ concat $ mapMaybe (`M.lookup` tr) names
9797
in (names, adjustedLocs,map fromNormalizedFilePath $ HM.keys asts)
9898

99-
getAstNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
100-
getAstNamesAtPoint hf pos mapping =
99+
getNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
100+
getNamesAtPoint hf pos mapping =
101101
concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
102102
where
103103
posFile = fromMaybe pos $ fromCurrentPosition mapping pos

haskell-language-server.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ flag refineImports
133133

134134
flag rename
135135
description: Enable rename plugin
136-
default: False
136+
default: True
137137
manual: True
138138

139139
flag retrie

plugins/hls-rename-plugin/hls-rename-plugin.cabal

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: hls-rename-plugin
3-
version: 1.0.0.1
3+
version: 1.0.0.2
44
synopsis: Rename plugin for Haskell Language Server
55
description:
66
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
@@ -26,13 +26,16 @@ library
2626
, ghc
2727
, ghc-exactprint
2828
, ghcide ^>=1.6
29+
, hashable
2930
, hiedb
3031
, hls-plugin-api ^>=1.3
3132
, lsp
3233
, lsp-types
34+
, mod
3335
, syb
3436
, text
3537
, transformers
38+
, unordered-containers
3639

3740
default-language: Haskell2010
3841

@@ -43,7 +46,10 @@ test-suite tests
4346
main-is: Main.hs
4447
ghc-options: -threaded -rtsopts -with-rtsopts=-N
4548
build-depends:
49+
, aeson
4650
, base
51+
, containers
4752
, filepath
53+
, hls-plugin-api
4854
, hls-rename-plugin
4955
, hls-test-utils ^>=1.2

0 commit comments

Comments
 (0)