Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable rename plugin #2809

Merged
merged 21 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6f16def
refactor rename plugin
OliverMadine Mar 29, 2022
0207037
prevent renaming of built-in syntax
OliverMadine Mar 29, 2022
801271d
limit rename scope to current module
OliverMadine Mar 29, 2022
03c31ab
refine imports in rename plugin
OliverMadine Mar 29, 2022
8dafdd7
allow renaming with implicit module names
OliverMadine Mar 29, 2022
b7cda24
update tests with cross-module renaming limitation
OliverMadine Mar 29, 2022
ca5f91a
enable rename plugin
OliverMadine Mar 29, 2022
6731ef0
add rename plugin to features docs
OliverMadine Mar 29, 2022
c9ae847
add rename plugin to ghc-8.10.X stack yaml files
OliverMadine Mar 29, 2022
062fe8c
improve position printing in rename error
OliverMadine Mar 29, 2022
866d6f5
implement cross-module rename config option
OliverMadine Apr 2, 2022
bace426
unignore tests for cross-module renames
OliverMadine Apr 2, 2022
f35775e
update docs for cross-module renaming
OliverMadine Apr 2, 2022
b6065ca
fix within module renaming for ghc-9
OliverMadine Apr 2, 2022
61656f5
fix rename plugin language extensions for ghc-92
OliverMadine Apr 2, 2022
53b9cee
add explicit GHC.Parser imports in rename plugin
OliverMadine Apr 2, 2022
d024a6b
fix typo in rename docs
OliverMadine Apr 3, 2022
b469eef
use implicit import lists in rename plugin
OliverMadine Apr 3, 2022
bb91db0
relocate orphaned instances from rename plugin
OliverMadine Apr 3, 2022
70f4e18
Revert "relocate orphaned instances from rename plugin"
OliverMadine Apr 3, 2022
64f942f
Merge branch 'master' into rename-within-module
pepeiborra Apr 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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