Skip to content

Qualify imported names plugin #2355

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

Merged
merged 45 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
acc1bcd
actual initial qualify imported names implementation
eddiemundo Nov 12, 2021
c3ab411
fix haskell-language-server.cabal conflict
eddiemundo Nov 12, 2021
9084b6a
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 12, 2021
f9c2940
renamed and added tests for QualifyImportedNames plugin
eddiemundo Nov 14, 2021
404bbd9
fix backtick and parenthesized operators not being qualified correctly
eddiemundo Nov 14, 2021
bb36298
add tests, and remove logging
eddiemundo Nov 14, 2021
0b33c83
add license, readme, and demo
eddiemundo Nov 15, 2021
b919648
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 15, 2021
106838a
remove old demo, add slightly better demo
eddiemundo Nov 15, 2021
2d0721c
remove old mp4 demo, add slightly gif demo
eddiemundo Nov 15, 2021
6173eb2
update readme to use demo
eddiemundo Nov 15, 2021
6ae18cb
readme typo
eddiemundo Nov 15, 2021
1d0631f
slight rewording of readme
eddiemundo Nov 15, 2021
62690c8
slight rewording of readme 2
eddiemundo Nov 15, 2021
3484bc6
remove Demo header from readme
eddiemundo Nov 15, 2021
464960a
don't need ShakeExtras and remove some more logging stuff
eddiemundo Nov 15, 2021
d625dc2
hopefully fix ghc 9 differences, rename plugin cabal file
eddiemundo Nov 15, 2021
d31057a
Merge branch 'master' into master
jneira Nov 16, 2021
76aed69
forgot comma on module re-export
eddiemundo Nov 16, 2021
9878a21
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 16, 2021
5b6111e
minimize imports
eddiemundo Nov 16, 2021
4215ed1
Merge branch 'master' into master
eddiemundo Nov 16, 2021
0308b4e
Merge branch 'master' into master
jneira Nov 17, 2021
541fef3
fix Hashmap import for ghc <= 8.8, remove unused extension pragmas
eddiemundo Nov 18, 2021
bd7c8cf
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 18, 2021
2fe20f1
Merge branch 'master' into master
jneira Nov 18, 2021
6b2323c
fix hls-qualify-imported-names ghcide bound
eddiemundo Nov 21, 2021
e4eb32e
Merge branch 'haskell:master' into master
eddiemundo Nov 21, 2021
653c105
add test suite to CI
eddiemundo Nov 21, 2021
3dd70a8
add more tests for qualify imported names plugin
eddiemundo Nov 21, 2021
53c352f
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 21, 2021
9ea9c93
change ghcide bound to match what @hololeap is doing
eddiemundo Nov 21, 2021
80684af
Merge branch 'master' into master
eddiemundo Nov 22, 2021
49bab5a
add qualify imported names to feature list
eddiemundo Nov 22, 2021
fa28e92
Merge branch 'master' into master
eddiemundo Nov 22, 2021
bb2c396
Merge branch 'master' into master
eddiemundo Nov 23, 2021
166f84a
Merge branch 'haskell:master' into master
eddiemundo Nov 27, 2021
bb7f014
Merge branch 'master' into master
jneira Nov 28, 2021
b04022f
Merge branch 'haskell:master' into master
eddiemundo Nov 28, 2021
cc9b2eb
Merge branch 'haskell:master' into qualify-imported-names-plugin
eddiemundo Nov 29, 2021
924b545
Merge branch 'master' of https://github.com/eddiemundo/haskell-langua…
eddiemundo Nov 29, 2021
a3056d9
add demo, readme, test files, test hie.yaml to extra source files
eddiemundo Nov 29, 2021
340511d
Merge branch 'master' into master
eddiemundo Nov 29, 2021
2cd7803
Merge branch 'master' into master
jneira Nov 29, 2021
bdb92be
Merge branch 'master' into master
jneira Nov 29, 2021
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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ jobs:
name: Test hls-hlint-plugin test suite
run: cabal test hls-hlint-plugin --test-options="$TEST_OPTS" || cabal test hls-hlint-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-hlint-plugin --test-options="$TEST_OPTS"

- if: matrix.test
name: Test hls-qualify-imported-names-plugin test suite
run: cabal test hls-qualify-imported-names-plugin --test-options="-j1 --rerun-update" || cabal test hls-qualify-imported-names-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-qualify-imported-names-plugin --test-options="-j1 --rerun"

test_post_job:
if: always()
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions cabal-ghc901.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages:
./plugins/hls-retrie-plugin
./plugins/hls-haddock-comments-plugin
./plugins/hls-splice-plugin
./plugins/hls-qualify-imported-names-plugin
./plugins/hls-floskell-plugin
./plugins/hls-pragmas-plugin
./plugins/hls-module-name-plugin
Expand Down
1 change: 1 addition & 0 deletions cabal-ghc921.project
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ packages:
-- ./plugins/hls-retrie-plugin
./plugins/hls-haddock-comments-plugin
-- ./plugins/hls-splice-plugin
./plugins/hls-qualify-imported-names-plugin
./plugins/hls-floskell-plugin
./plugins/hls-pragmas-plugin
./plugins/hls-module-name-plugin
Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ packages:
./plugins/hls-module-name-plugin
./plugins/hls-ormolu-plugin
./plugins/hls-call-hierarchy-plugin
./plugins/hls-qualify-imported-names-plugin


-- Standard location for temporary packages needed for particular environments
-- For example it is used in the project gitlab mirror to help in the MAcOS M1 build script
Expand Down
5 changes: 5 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can watch demos for some of these features [below](#demos).
- [Integration](#hlint) with [hlint](https://github.com/ndmitchell/hlint), the most used haskell linter, to show diagnostics and apply hints via [apply-refact](https://github.com/mpickering/apply-refact)
- [Module name suggestions](#module-names) for insertion or correction
- [Call hierarchy support](#call-hierarchy)
- [Qualify names from an import declaration](#qualify-imported-names) in your code

## Demos

Expand Down Expand Up @@ -46,3 +47,7 @@ You can watch demos for some of these features [below](#demos).
### Call hierarchy

![Call Hierarchy in VSCode](https://github.com/haskell/haskell-language-server/raw/2857eeece0398e1cd4b2ffb6069b05c4d2308b39/plugins/hls-call-hierarchy-plugin/call-hierarchy-in-vscode.gif)

### Qualify imported names

![Qualify Imported Names Demo](../plugins/hls-qualify-imported-names-plugin/qualify-imported-names-demo.gif)
6 changes: 6 additions & 0 deletions exe/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import Ide.Plugin.Example as Example
import Ide.Plugin.Example2 as Example2

-- haskell-language-server optional plugins
#if qualifyImportedNames
import Ide.Plugin.QualifyImportedNames as QualifyImportedNames
#endif

#if callHierarchy
import Ide.Plugin.CallHierarchy as CallHierarchy
Expand Down Expand Up @@ -143,6 +146,9 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
#if importLens
ExplicitImports.descriptor "importLens" :
#endif
#if qualifyImportedNames
QualifyImportedNames.descriptor "qualifyImportedNames" :
#endif
#if refineImports
RefineImports.descriptor "refineImports" :
#endif
Expand Down
17 changes: 12 additions & 5 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ module Development.IDE.GHC.Compat.Core (
module GHC.Core.DataCon,
module GHC.Core.FamInstEnv,
module GHC.Core.InstEnv,
module GHC.Types.Unique.FM,
#if !MIN_VERSION_ghc(9,2,0)
module GHC.Core.Ppr.TyThing,
#endif
Expand Down Expand Up @@ -380,6 +381,7 @@ module Development.IDE.GHC.Compat.Core (
module TysWiredIn,
module Type,
module Unify,
module UniqFM,
module UniqSupply,
module Var,
#endif
Expand Down Expand Up @@ -426,6 +428,7 @@ import GHC.Core.DataCon hiding (dataConExTyCoVars)
import qualified GHC.Core.DataCon as DataCon
import GHC.Core.FamInstEnv
import GHC.Core.InstEnv
import GHC.Types.Unique.FM
#if MIN_VERSION_ghc(9,2,0)
import GHC.Core.Multiplicity (scaledThing)
#else
Expand Down Expand Up @@ -512,7 +515,9 @@ import GHC.Types.TyThing.Ppr
#else
import GHC.Types.Name.Set
#endif
import GHC.Types.SrcLoc (BufPos, BufSpan, SrcSpan (UnhelpfulSpan), SrcLoc(UnhelpfulLoc))
import GHC.Types.SrcLoc (BufPos, BufSpan,
SrcLoc (UnhelpfulLoc),
SrcSpan (UnhelpfulSpan))
import qualified GHC.Types.SrcLoc as SrcLoc
import GHC.Types.Unique.Supply
import GHC.Types.Var (Var (varName), setTyVarUnique,
Expand Down Expand Up @@ -631,21 +636,23 @@ import Type hiding (mkVisFunTys)
import TysPrim
import TysWiredIn
import Unify
import UniqFM
import UniqSupply
import Var (Var (varName), setTyVarUnique,
setVarUnique, varType)

#if MIN_VERSION_ghc(8,10,0)
import Coercion (coercionKind)
import Predicate
import SrcLoc (SrcSpan (UnhelpfulSpan), SrcLoc (UnhelpfulLoc))
import SrcLoc (SrcLoc (UnhelpfulLoc),
SrcSpan (UnhelpfulSpan))
#else
import SrcLoc (RealLocated,
SrcSpan (UnhelpfulSpan),
SrcLoc (UnhelpfulLoc))
import SrcLoc (RealLocated, SrcLoc (UnhelpfulLoc),
SrcSpan (UnhelpfulSpan))
#endif
#endif


#if !MIN_VERSION_ghc(8,8,0)
import Data.List (isSuffixOf)
import System.FilePath
Expand Down
11 changes: 11 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ flag splice
default: True
manual: True

flag qualifyImportedNames
description: Enable qualifyImportedNames plugin
default: True
manual: True

-- formatters

flag floskell
Expand Down Expand Up @@ -253,6 +258,11 @@ common splice
build-depends: hls-splice-plugin ^>=1.0.0.1
cpp-options: -Dsplice

common qualifyImportedNames
if flag(qualifyImportedNames)
build-depends: hls-qualify-imported-names-plugin ^>=1.0.0.0
cpp-options: -DqualifyImportedNames

-- formatters

common floskell
Expand Down Expand Up @@ -297,6 +307,7 @@ executable haskell-language-server
, moduleName
, pragmas
, splice
, qualifyImportedNames
, floskell
, fourmolu
, ormolu
Expand Down
201 changes: 201 additions & 0 deletions plugins/hls-qualify-imported-names-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
19 changes: 19 additions & 0 deletions plugins/hls-qualify-imported-names-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Qualify Imported Names

![Qualify Imported Names Demo](qualify-imported-names-demo.gif)

## Usage

1. Put cursor over the import declaration you want to qualify names from.
2. Initiate a Code Action.
3. Select `Qualify imported names`.

## Features
- Names are qualified on a per-import declaration basis.
- Names are qualified by the imported module's alias if it has one, otherwise by the imported module's name.
- If the import declaration has an explicit import list then the plugin will qualify only names on the list.
- If the import declaration has an explicit hiding list then the plugin will qualify names from the imported module that are not on the list.

## Change log
### 1.0.0.0
- Released...
Loading