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

Parse .cabal files; show error and warning diagnostics #2954

Merged
merged 26 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
be0150d
Extract cabal plugin in its own package
fendor Jul 10, 2022
c7b1a97
hls-cabal-plugin: Add plugin
runeksvendsen Jun 11, 2022
34dbd33
Add CI workflow
fendor Jun 23, 2022
62a6fad
Add test-suite for hls-cabal-plugin
fendor Jun 26, 2022
309260a
Fix various cabal issues
fendor Jul 10, 2022
28052ee
Update Codeowners file for hls-cabal-plugin
fendor Jul 10, 2022
f927930
Document Bytestring is UTF-8 encoded
fendor Jul 26, 2022
f7e5d64
Remove code duplication
fendor Aug 14, 2022
3638280
Add cabal files of interest and kick function
fendor Oct 10, 2022
fb941e3
Add more documentation
fendor Oct 30, 2022
46f6657
Mark flaky test-case as flaky with issue ref
fendor Nov 13, 2022
033caa9
Make fendor the only CODEOWNER for hls-cabal-plugin
fendor Nov 13, 2022
7a0f066
Add missing extra-source-files for hls-cabal-plugin
fendor Nov 13, 2022
fcd223d
Add proper CHANGELOG entry for the first version of hls-cabal-plugin
fendor Nov 13, 2022
1932674
Add support for Cabal 3.8
fendor Nov 19, 2022
525e2da
Set diagnostics source to cabal
fendor Nov 19, 2022
76137d4
Remove unused function
fendor Nov 19, 2022
66c6089
Add unit tests for code action utilities
fendor Nov 19, 2022
65780af
Remove overly specific logging of diagnostics from hls-cabal-plugin
fendor Nov 19, 2022
f33531c
Improve logging for Cabal FOIs
fendor Nov 19, 2022
c27b063
Add Range manipulation functions
fendor Nov 19, 2022
edd227f
Use Range manipulation functions from hls-plugin-api
fendor Nov 19, 2022
3938b8f
Add more documentation for crucial shake restart function
fendor Nov 19, 2022
99c7081
Add hls-cabal-plugin features to features.md
fendor Nov 19, 2022
701915c
Re-use existing GetFileContents rule
fendor Nov 19, 2022
ac3f998
Merge branch 'master' into rune/hls-cabal-plugin
mergify[bot] Nov 21, 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
1 change: 1 addition & 0 deletions .github/workflows/hackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
matrix:
package: ["hie-compat", "hls-graph", "shake-bench",
"hls-plugin-api", "ghcide", "hls-test-utils",
"hls-cabal-plugin",
"hls-brittany-plugin", "hls-floskell-plugin", "hls-fourmolu-plugin",
"hls-ormolu-plugin", "hls-stylish-haskell-plugin",
"hls-class-plugin", "hls-eval-plugin", "hls-explicit-imports-plugin",
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ jobs:
name: Test hls-cabal-fmt-plugin test suite
run: cabal test hls-cabal-fmt-plugin --flag=isolateTests --test-options="$TEST_OPTS" || cabal test hls-cabal-fmt-plugin --flag=isolateTests --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-cabal-fmt-plugin --flag=isolateTests --test-options="$TEST_OPTS"

- if: matrix.test
name: Test hls-cabal-plugin test suite
run: cabal test hls-cabal-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-cabal-plugin --test-options="$TEST_OPTS"

test_post_job:
if: always()
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Plugins
/plugins/hls-alternate-number-format-plugin @drsooch
/plugins/hls-brittany-plugin @fendor
/plugins/hls-cabal-plugin @fendor
/plugins/hls-cabal-fmt-plugin @VeryMilkyJoe @fendor
/plugins/hls-call-hierarchy-plugin @July541
/plugins/hls-class-plugin @Ailrun
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ packages:
./ghcide/test
./hls-plugin-api
./hls-test-utils
./plugins/hls-cabal-plugin
./plugins/hls-cabal-fmt-plugin
./plugins/hls-tactics-plugin
./plugins/hls-brittany-plugin
Expand Down
14 changes: 14 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Provided by: `hls-stan-plugin`

Provides Stan hints as diagnostics.

### Cabal parse errors and warnings

Provided by: `hls-cabal-plugin`

Provides errors and warnings from Cabal as diagnostics

## Hovers

Provided by: `ghcide`
Expand Down Expand Up @@ -308,6 +314,14 @@ Expand record wildcards, explicitly listing all record fields as field puns.

![Explicit Wildcard Demo](../plugins/hls-explicit-record-fields-plugin/wildcard.gif)

### Unknown SPDX License suggestion

Provided by: `hls-cabal-plugin`

Code action kind: `quickfix`

Correct common misspelling of SPDX Licenses such as `BSD-3-Clause`.

## Code lenses

### Add type signature
Expand Down
12 changes: 12 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ flag ignore-plugins-ghc-bounds
default: False
manual: True


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

flag class
description: Enable class plugin
default: True
Expand Down Expand Up @@ -215,6 +221,11 @@ common cabalfmt
build-depends: hls-cabal-fmt-plugin ^>= 0.1.0.0
cpp-options: -Dhls_cabalfmt

common cabal
if flag(cabal)
build-depends: hls-cabal-plugin ^>= 0.1
cpp-options: -Dhls_cabal

common class
if flag(class)
build-depends: hls-class-plugin ^>= 1.1
Expand Down Expand Up @@ -358,6 +369,7 @@ library
, warnings
, pedantic
-- plugins
, cabal
, callHierarchy
, cabalfmt
, changeTypeSignature
Expand Down
29 changes: 25 additions & 4 deletions hls-plugin-api/src/Ide/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Ide.PluginUtils
( WithDeletions(..),
getProcessID,
( -- * LSP Range manipulation functions
normalize,
extendNextLine,
extendLineStart,
WithDeletions(..),
getProcessID,
makeDiffTextEdit,
makeDiffTextEditAdditive,
diffText,
Expand Down Expand Up @@ -67,9 +70,27 @@ import qualified Text.Megaparsec.Char.Lexer as P
-- ---------------------------------------------------------------------

-- | Extend to the line below and above to replace newline character.
--
-- >>> normalize (Range (Position 5 5) (Position 5 10))
-- Range (Position 5 0) (Position 6 0)
normalize :: Range -> Range
normalize (Range (Position sl _) (Position el _)) =
Range (Position sl 0) (Position (el + 1) 0)
normalize = extendLineStart . extendNextLine

-- | Extend 'Range' to the start of the next line.
--
-- >>> extendNextLine (Range (Position 5 5) (Position 5 10))
-- Range (Position 5 5) (Position 6 0)
extendNextLine :: Range -> Range
extendNextLine (Range s (Position el _)) =
Range s (Position (el + 1) 0)

-- | Extend 'Range' to the start of the current line.
--
-- >>> extendLineStart (Range (Position 5 5) (Position 5 10))
-- Range (Position 5 0) (Position 5 10)
extendLineStart :: Range -> Range
extendLineStart (Range (Position sl _) e) =
Range (Position sl 0) e

-- ---------------------------------------------------------------------

Expand Down
28 changes: 26 additions & 2 deletions hls-test-utils/src/Test/Hls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Test.Hls
defaultTestRunner,
goldenGitDiff,
goldenWithHaskellDoc,
goldenWithCabalDoc,
goldenWithHaskellDocFormatter,
goldenWithCabalDocFormatter,
def,
Expand Down Expand Up @@ -124,12 +125,35 @@ goldenWithHaskellDoc
-> FilePath
-> (TextDocumentIdentifier -> Session ())
-> TestTree
goldenWithHaskellDoc plugin title testDataDir path desc ext act =
goldenWithHaskellDoc = goldenWithDoc "haskell"

goldenWithCabalDoc
:: PluginDescriptor IdeState
-> TestName
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> (TextDocumentIdentifier -> Session ())
-> TestTree
goldenWithCabalDoc = goldenWithDoc "cabal"

goldenWithDoc
:: T.Text
-> PluginDescriptor IdeState
-> TestName
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> (TextDocumentIdentifier -> Session ())
-> TestTree
goldenWithDoc fileType plugin title testDataDir path desc ext act =
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
$ runSessionWithServer plugin testDataDir
$ TL.encodeUtf8 . TL.fromStrict
<$> do
doc <- openDoc (path <.> ext) "haskell"
doc <- openDoc (path <.> ext) fileType
void waitForBuildQueue
act doc
documentContents doc
Expand Down
6 changes: 6 additions & 0 deletions plugins/hls-cabal-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Revision history for hls-cabal-plugin

## 0.1.0.0 -- YYYY-mm-dd

* Provide Diagnostics on parse errors and warnings for .cabal files
* Provide CodeAction for the common SPDX License mistake "BSD3" instead of "BSD-3-Clause"
20 changes: 20 additions & 0 deletions plugins/hls-cabal-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2022 Fendor

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 changes: 81 additions & 0 deletions plugins/hls-cabal-plugin/hls-cabal-plugin.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cabal-version: 3.0
name: hls-cabal-plugin
version: 0.1.0.0
synopsis: Cabal integration plugin with Haskell Language Server
description:
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>

homepage:
license: MIT
license-file: LICENSE
author: Fendor
maintainer: [email protected]
category: Development
extra-source-files:
CHANGELOG.md
test/testdata/*.cabal
test/testdata/simple-cabal/A.hs
test/testdata/simple-cabal/cabal.project
test/testdata/simple-cabal/hie.yaml
test/testdata/simple-cabal/simple-cabal.cabal

common warnings
ghc-options: -Wall

library
import: warnings
exposed-modules:
Ide.Plugin.Cabal
Ide.Plugin.Cabal.Diagnostics
Ide.Plugin.Cabal.LicenseSuggest
Ide.Plugin.Cabal.Parse

build-depends:
, base >=4.12 && <5
, bytestring
-- Ideally, we only want to support a single Cabal version, supporting
-- older versions is completely pointless since Cabal is backwards compatible,
-- the latest Cabal version can parse all versions of the Cabal file format.
--
-- However, stack is making this difficult, if we change the version of Cabal,
-- we essentially need to make sure all other packages in the snapshot have their
-- Cabal dependency version relaxed.
-- Most packages have a Hackage revision, but stack won't pick these up (for sensible reasons)
-- automatically, forcing us to manually update the packages revision id.
-- This is a lot of work for almost zero benefit, so we just allow more versions here
-- and we eventually completely drop support for building HLS with stack.
, Cabal ^>=3.2 || ^>=3.4 || ^>=3.6 || ^>= 3.8
, deepseq
, directory
, extra >=1.7.4
, ghcide ^>= 1.8
, hashable
, hls-plugin-api ^>=1.5
, hls-graph ^>=1.8
, lsp ^>=1.6.0.0
, lsp-types ^>=1.6.0.0
, regex-tdfa ^>=1.3.1
, stm
, text
, unordered-containers >=0.2.10.0

hs-source-dirs: src
default-language: Haskell2010

test-suite tests
import: warnings
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends:
, base
, bytestring
, filepath
, ghcide
, hls-cabal-plugin
, hls-test-utils ^>=1.4
, lens
, lsp-types
, tasty-hunit
, text
Loading