Skip to content

Commit

Permalink
Enable rename plugin (#2809)
Browse files Browse the repository at this point in the history
* 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 <pepeiborra@gmail.com>
  • Loading branch information
OliverMadine and pepeiborra authored Apr 3, 2022
1 parent 21c4510 commit dda3e5e
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
"hls-class-plugin", "hls-eval-plugin", "hls-explicit-imports-plugin",
"hls-haddock-comments-plugin", "hls-hlint-plugin",
"hls-module-name-plugin", "hls-pragmas-plugin",
"hls-refine-imports-plugin", "hls-retrie-plugin",
"hls-refine-imports-plugin", "hls-rename-plugin", "hls-retrie-plugin",
"hls-splice-plugin", "hls-tactics-plugin",
"hls-call-hierarchy-plugin", "hls-alternate-number-format-plugin",
"hls-qualify-imported-names-plugin", "hls-selection-range-plugin",
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Here is a list of the additional settings currently supported by `haskell-langua
Plugins have a generic config to control their behaviour. The schema of such config is:

- `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.
- 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`.
- 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`.
- So to disable the import lens with an explicit list of module definitions you could set `haskell.plugin.importLens.globalOn: false`
- `haskell.plugin.${pluginName}.${lspCapability}On`: usually with default true. Whether a concrete plugin capability is enabled.
- 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`.
Expand All @@ -66,6 +66,8 @@ Plugins have a generic config to control their behaviour. The schema of such con
- `eval`:
- `haskell.plugin.eval.config.diff`, default true: When reloading haddock test results in changes, mark it with WAS/NOW.
- `haskell.plugin.eval.config.exception`, default false: When the command results in an exception, mark it with `*** Exception:`.
- `rename`:
- `haskell.plugin.rename.config.diff`, default false: Enables renaming across modules (experimental)
- `ghcide-completions`:
- `haskell.plugin.ghcide-completions.config.snippetsOn`, default true: Inserts snippets when using code completions.
- `haskell.plugin.ghcide-completions.config.autoExtendOn`, default true: Extends the import list automatically when completing a out-of-scope identifier.
Expand Down
14 changes: 13 additions & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Many of these are standard LSP features, but a lot of special features are provi
| [Code actions](#code-actions) | `textDocument/codeAction` |
| [Code lenses](#code-lenses) | `textDocument/codeLens` |
| [Selection range](#selection-range) | `textDocument/selectionRange` |
| [Rename](#rename) | `textDocument/rename` |

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!
Additionally, not all plugins are supported on all versions of GHC, see the [GHC version support page](supported-versions.md) for details.
Expand Down Expand Up @@ -305,6 +306,18 @@ support.

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

## Rename

Provided by: `hls-rename-plugin`

Provides renaming of symbols within a module. Experimental cross-module renaming can be enabled via the configuration.

![Rename Demo](https://user-images.githubusercontent.com/30090176/133072143-d7d03ec7-3db1-474e-ad5e-6f40d75ff7ab.gif)

Known limitations:

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

## Missing features

The following features are supported by the LSP specification but not implemented in HLS.
Expand All @@ -315,7 +328,6 @@ Contributions welcome!
| Signature help | Unimplemented | `textDocument/signatureHelp` |
| Jump to declaration | Unclear if useful | `textDocument/declaration` |
| Jump to implementation | Unclear if useful | `textDocument/implementation` |
| Renaming | [Parital implementation](https://github.com/haskell/haskell-language-server/issues/2193) | `textDocument/rename`, `textDocument/prepareRename` |
| Folding | Unimplemented | `textDocument/foldingRange` |
| Semantic tokens | Unimplemented | `textDocument/semanticTokens` |
| Linked editing | Unimplemented | `textDocument/linkedEditingRange` |
Expand Down
1 change: 1 addition & 0 deletions docs/supported-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Sometimes a plugin will be supported in the prebuilt binaries but not in a HLS b
| `hls-pragmas-plugin` | |
| `hls-qualify-imported-names-plugin` | |
| `hls-refine-imports-plugin` | |
| `hls-rename-plugin` | |
| `hls-retrie-plugin` | 9.2 |
| `hls-splice-plugin` | 9.2 |
| `hls-stylish-haskell-plugin` | 9.0, 9.2 |
Expand Down
8 changes: 4 additions & 4 deletions ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Development.IDE.Spans.AtPoint (
, computeTypeReferences
, FOIReferences(..)
, defRowToSymbolInfo
, getAstNamesAtPoint
, getNamesAtPoint
, toCurrentLocation
, rowToLoc
) where
Expand Down Expand Up @@ -86,7 +86,7 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
case HM.lookup file asts of
Nothing -> ([],[],[])
Just (HAR _ hf _ _ _,mapping) ->
let names = getAstNamesAtPoint hf pos mapping
let names = getNamesAtPoint hf pos mapping
adjustedLocs = HM.foldr go [] asts
go (HAR _ _ rf tr _, mapping) xs = refs ++ typerefs ++ xs
where
Expand All @@ -96,8 +96,8 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
$ concat $ mapMaybe (`M.lookup` tr) names
in (names, adjustedLocs,map fromNormalizedFilePath $ HM.keys asts)

getAstNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
getAstNamesAtPoint hf pos mapping =
getNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
getNamesAtPoint hf pos mapping =
concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
where
posFile = fromMaybe pos $ fromCurrentPosition mapping pos
Expand Down
2 changes: 1 addition & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ flag refineImports

flag rename
description: Enable rename plugin
default: False
default: True
manual: True

flag retrie
Expand Down
8 changes: 7 additions & 1 deletion plugins/hls-rename-plugin/hls-rename-plugin.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: hls-rename-plugin
version: 1.0.0.1
version: 1.0.0.2
synopsis: Rename plugin for Haskell Language Server
description:
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
Expand All @@ -26,13 +26,16 @@ library
, ghc
, ghc-exactprint
, ghcide ^>=1.6
, hashable
, hiedb
, hls-plugin-api ^>=1.3
, lsp
, lsp-types
, mod
, syb
, text
, transformers
, unordered-containers

default-language: Haskell2010

Expand All @@ -43,7 +46,10 @@ test-suite tests
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
, aeson
, base
, containers
, filepath
, hls-plugin-api
, hls-rename-plugin
, hls-test-utils ^>=1.2
Loading

0 comments on commit dda3e5e

Please sign in to comment.