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

Hlint plugin using ghc-lib #166

Merged
merged 71 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1ce5316
WIP on integrating hlint using DAML approach
alanz Feb 10, 2020
beb2e25
hlint plugin version with only diagnostics
jneira Jun 18, 2020
70ce253
Add apply-refact dependency
jneira Jun 21, 2020
a49ad1a
WIP adding apply hlint hints
jneira Jun 21, 2020
91af64b
Add missing dependencies
jneira Jul 1, 2020
6334ed5
Add hlint private lib
jneira Jul 1, 2020
6b06854
Update stack extra-deps
jneira Jul 1, 2020
cd8be02
Implement hlint applyOneCmd
jneira Jul 1, 2020
bd2a772
Move hlint module to its own src dir
jneira Jul 2, 2020
787a474
Rename lib to hlint-plugin
jneira Jul 2, 2020
4fbabd7
Move hlint plugin to a more generic path
jneira Jul 3, 2020
c03c385
Parse module with ghc session extensions
jneira Jul 7, 2020
1e3350c
Use both ghc and ghc-lib
jneira Jul 7, 2020
765d857
Make compile ghc-8.10.1 code path
jneira Jul 9, 2020
d3c6ee5
Remove unused imports and refact cpp blocks
jneira Jul 14, 2020
5c6885e
Remove trailing whitespace
jneira Jul 15, 2020
fd6fc80
Use ghcide with config in shakeExtras
jneira Aug 9, 2020
6e9a7bc
Add action to get client settings
jneira Aug 16, 2020
752c838
Make hlint depend on client setting
jneira Aug 16, 2020
0aef003
Use getFileContents action rule
jneira Aug 25, 2020
d13184e
Remove commented code from hie
jneira Aug 27, 2020
adeb930
Use edited content for compute edits
jneira Aug 28, 2020
26740f1
Use persisted VFS file with apply refact, expose applyAll
lukel97 Aug 29, 2020
7674fe7
Enable hlint tests
jneira Aug 29, 2020
ff778b6
Move test data to fix the cradle loading
jneira Aug 30, 2020
0e71e87
Fix hlint tests
jneira Aug 30, 2020
36982a5
Add indefinite progress to apply refact
jneira Sep 2, 2020
11086d5
Bump ghcide submodule
jneira Sep 7, 2020
b44ecb4
Adapt code to handle hashed value
jneira Sep 7, 2020
523953c
Replace vfs with raw temp file
jneira Sep 2, 2020
3a46078
Convert hlint-hls-plugin in a package
jneira Sep 9, 2020
a99912f
Rename to hls-hlint-plugin
jneira Sep 15, 2020
105c37f
Adapt to ghcide api changes
jneira Sep 16, 2020
706dfcc
Fix and clean stack extra-deps
jneira Oct 7, 2020
bff0d24
Use lsp-test-0.11.0.6
jneira Oct 17, 2020
55dfc3b
Fix hlint tests
jneira Oct 18, 2020
e24ebd2
Use hint name for code action title
jneira Oct 19, 2020
2f31ffb
Remove unused test data file
jneira Oct 19, 2020
839e75c
Remove unused parameter
jneira Oct 19, 2020
bf5108b
Add forcily needed hie.yaml
jneira Oct 19, 2020
7759c08
Make test not sensitive to commands order
jneira Oct 19, 2020
cd0b615
Make test resilient to default diags
jneira Oct 19, 2020
3adb995
Test only if the command has been applied
jneira Oct 19, 2020
f8dc9e0
Wait for hlint diagnostics explicitly
jneira Oct 19, 2020
3f4e950
Bump up ghc-lib min version
jneira Oct 19, 2020
89c4851
Use latest ghc-lib version
jneira Oct 19, 2020
8603c5c
Change mixins for PackageImport
jneira Oct 21, 2020
02308cd
Remove ghcide alternate repo
jneira Oct 22, 2020
e456f66
Simplify imports from ghcide
jneira Oct 25, 2020
814ad46
Use GHC.Compat from ghcide
jneira Oct 25, 2020
95dde7c
Restore imports for missing defs
jneira Oct 25, 2020
fc4ea30
Comment about the need to use tmp file
jneira Oct 25, 2020
73f669d
Remove hlintOn logging
jneira Oct 25, 2020
21b47f2
Remove hlint parser error from diagnostics
jneira Oct 25, 2020
d558e9a
Comment about GetHlintDiagnostics RuleResult
jneira Oct 26, 2020
1245439
Comment how hlint diags are recomputed
jneira Oct 26, 2020
e26b23f
Correct identation
jneira Oct 26, 2020
7f5a4ef
Use diagnostic code prefix "refact:"
jneira Oct 26, 2020
eeb62e0
Return hlint diags if no ghc parse errors
jneira Oct 26, 2020
929aaea
Combine hlint and hscEnv extensions
jneira Oct 26, 2020
f5d4311
Correct replace params
jneira Oct 26, 2020
1c1f7f3
Correct component name
jneira Oct 26, 2020
8b8e568
Fix apply refactoring
jneira Oct 26, 2020
c35cdda
Update tests to match new diags and ca's
jneira Oct 26, 2020
0e72151
Add GHC810 explicit version
jneira Oct 26, 2020
5d4d2e2
Set hlint code by ghc version
jneira Oct 26, 2020
f1751b7
Use hlint-3.2
jneira Oct 27, 2020
b549506
Remove ghc specific diag title
jneira Oct 27, 2020
ff0e4c7
Add and update comments
jneira Oct 27, 2020
01f8fd8
Provide evidence edits changes hlint diags
jneira Oct 27, 2020
94b7a3e
Rerun test suite to avoid flaky tests
jneira Oct 28, 2020
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/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ jobs:
# run the tests without parallelism, otherwise tasty will attempt to run
# all functional test cases simultaneously which causes way too many hls
# instances to be spun up for the poor github actions runner to handle
run: cabal test --test-options=-j1
run: cabal test --test-options="-j1 --rerun-update" || cabal test --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test --test-options="-j1 --rerun"

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cabal.project.local
*~
*.lock

.tasty-rerun-log

# shake build information
_build/

Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ packages:
ghcide
hls-plugin-api
./plugins/tactics
./plugins/hls-hlint-plugin

source-repository-package
type: git
Expand Down
5 changes: 4 additions & 1 deletion exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Ide.Main (defaultMain)
import Ide.Types (IdePlugins)

-- haskell-language-server plugins

import Ide.Plugin.Eval as Eval
import Ide.Plugin.Example as Example
import Ide.Plugin.Example2 as Example2
Expand All @@ -22,6 +23,7 @@ import Ide.Plugin.Ormolu as Ormolu
import Ide.Plugin.Retrie as Retrie
import Ide.Plugin.StylishHaskell as StylishHaskell
import Ide.Plugin.Tactic as Tactic
import Ide.Plugin.Hlint as Hlint
#if AGPL
import Ide.Plugin.Brittany as Brittany
#endif
Expand Down Expand Up @@ -55,11 +57,12 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
, StylishHaskell.descriptor "stylish-haskell"
, Retrie.descriptor "retrie"
#if AGPL
, Brittany.descriptor "brittany"
, Brittany.descriptor "brittany"
#endif
, Eval.descriptor "eval"
, ImportLens.descriptor "importLens"
, ModuleName.descriptor "moduleName"
, Hlint.descriptor "hlint"
]
examplePlugins =
[Example.descriptor "eg"
Expand Down
5 changes: 4 additions & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ library

default-language: Haskell2010


executable haskell-language-server
import: agpl, common-deps
main-is: Main.hs
Expand Down Expand Up @@ -119,6 +120,7 @@ executable haskell-language-server
, hashable
, haskell-language-server
, haskell-lsp ^>=0.22
, hls-hlint-plugin
, hls-plugin-api
, hls-tactics-plugin
, lens
Expand Down Expand Up @@ -197,7 +199,7 @@ common hls-test-utils
, hslogger
, hspec
, hspec-core
, lsp-test >=0.11.0.4
, lsp-test >=0.11.0.6
, stm
, tasty-hunit
, temporary
Expand Down Expand Up @@ -274,6 +276,7 @@ test-suite wrapper-test
, process
, tasty
, tasty-ant-xml >=1.1.6
, tasty-rerun

hs-source-dirs: test/wrapper
main-is: Main.hs
Expand Down
5 changes: 4 additions & 1 deletion hie.yaml.cbl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cradle:
- path: "./src"
component: "lib:haskell-language-server"

- path: "./.stack-work/"
- path: "./dist-newstyle/"
component: "lib:haskell-language-server"

- path: "./ghcide/src"
Expand All @@ -45,3 +45,6 @@ cradle:

- path: "./hls-plugin-api/src"
component: "hls-plugin-api:lib:hls-plugin-api"

- path: "./plugins/hls-hlint-plugin/src"
component: "lib:hls-hlint-plugin"
3 changes: 3 additions & 0 deletions hie.yaml.stack
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ cradle:

- path: "./hls-plugin-api/src"
component: "hls-plugin-api:lib:hls-plugin-api"

- path: "./plugins/hls-hlint-plugin/src"
component: "hls-hlint-plugin:lib:hls-hlint-plugin"
1 change: 1 addition & 0 deletions hls-plugin-api/hls-plugin-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
, ghc-boot-th
, ghcide >=0.4
, haskell-lsp ^>=0.22
, hashable
jneira marked this conversation as resolved.
Show resolved Hide resolved
, hslogger
, lens
, process
Expand Down
13 changes: 13 additions & 0 deletions hls-plugin-api/src/Ide/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Ide.Plugin
, allLspCmdIds'
, getPid
, responseError
, getClientConfig
, getClientConfigAction
) where

import Control.Exception(SomeException, catch)
Expand All @@ -25,13 +27,15 @@ import Control.Monad
import qualified Data.Aeson as J
import qualified Data.Default
import Data.Either
import Data.Hashable (unhashed)
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Maybe
import qualified Data.Text as T
import Development.IDE hiding (pluginRules)
import Development.IDE.LSP.Server
import GHC.Generics
import Ide.Logger
import Ide.Plugin.Config
import Ide.Plugin.Formatter
import Ide.Types
Expand Down Expand Up @@ -588,4 +592,13 @@ getPrefixAtPos lf uri pos = do
getClientConfig :: LSP.LspFuncs Config -> IO Config
getClientConfig lf = fromMaybe Data.Default.def <$> LSP.config lf

-- | Returns the client configurarion stored in the IdeState.
-- You can use this function to access it from shake Rules
getClientConfigAction :: Action Config
getClientConfigAction = do
mbVal <- unhashed <$> useNoFile_ GetClientSettings
logm $ "getClientConfigAction:clientSettings:" ++ show mbVal
case J.fromJSON <$> mbVal of
Just (J.Success c) -> return c
_ -> return Data.Default.def
-- ---------------------------------------------------------------------
201 changes: 201 additions & 0 deletions plugins/hls-hlint-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.
Loading