Skip to content

DRAFT: Cabal project plugin diagnostics #4615

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ jobs:
ghc: ${{ matrix.ghc }}
os: ${{ runner.os }}

- name: Init submodules
run: git submodule update --init

- name: Build
run: cabal build all

Expand Down Expand Up @@ -238,6 +241,10 @@ jobs:
name: Test hls-cabal-plugin test suite
run: cabal test hls-cabal-plugin-tests || cabal test hls-cabal-plugin-tests

- if: matrix.test
name: Test hls-cabal-project-plugin test suite
run: cabal test hls-cabal-project-plugin-tests || cabal test hls-cabal-project-plugin-tests

# TODO enable when it supports 9.10
- if: matrix.test && matrix.ghc != '9.10' && matrix.ghc != '9.12'
name: Test hls-retrie-plugin test suite
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
# Commit git commit -m "Removed submodule <name>"
# Delete the now untracked submodule files
# rm -rf path_to_submodule

[submodule "vendor/cabal"]
path = vendor/cabal
url = https://github.com/rm41339/cabal.git
25 changes: 25 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@ packages:
./ghcide
./hls-plugin-api
./hls-test-utils
./vendor/cabal/Cabal
./vendor/cabal/Cabal-syntax
./vendor/cabal/cabal-install
./vendor/cabal/cabal-install-solver
./vendor/cabal/Cabal-described
./vendor/cabal/Cabal-tree-diff

source-repository-package
type: git
location: https://github.com/fendor/cabal-add/
tag: 3ae65c28bfc6eff66a7a05bb9547665f62a35b63

source-repository-package
type: git
location: https://github.com/fendor/haskell-ci/
tag: e3e68f064f9610267bb47ea6404ccaa6924c2201
subdir: cabal-install-parsers

package cabal-install
tests: False
benchmarks: False

flags: -ormolu -stylishHaskell -stan -fourmolu

index-state: 2025-05-12T13:26:29Z

Expand Down Expand Up @@ -51,6 +73,9 @@ constraints:
-- cabal-add depends on cabal-install-parsers.
allow-newer:
cabal-install-parsers:Cabal-syntax,
*:Cabal-syntax,
*:cabal-install,
*:Cabal

if impl(ghc >= 9.11)
benchmarks: False
Expand Down
1 change: 1 addition & 0 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
,retryOnException
,Log(..)
,runWithDb
, cacheDir
) where

-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
Expand Down Expand Up @@ -629,7 +630,7 @@
| compileTime == runTime -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
| otherwise -> return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])

Check warning on line 633 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef' cradle_files (\\ xs -> (cfp : xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ cradle_files ((:) cfp)"
-- Failure case, either a cradle error or the none cradle
Left err -> do
dep_info <- getDependencyInfo (maybeToList hieYaml)
Expand Down Expand Up @@ -896,7 +897,7 @@
pure us
isBad ci = (homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units
-- Whenever we spin up a session on Linux, dynamically load libm.so.6
-- in. We need this in case the binary is statically linked, in which

Check warning on line 900 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in newComponentCache in module Development.IDE.Session: Redundant bracket ▫︎ Found: "(homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units" ▫︎ Perhaps: "homeUnitId_ (componentDynFlags ci) `OS.member` bad_units"
-- case the interactive session will fail when trying to load
-- ghc-prim, which happens whenever Template Haskell is being
-- evaluated or haskell-language-server's eval plugin tries to run
Expand Down
81 changes: 81 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,86 @@ test-suite hls-cabal-plugin-tests
, text
, hls-plugin-api

-----------------------------
-- cabal project plugin
-----------------------------

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

common cabalProject
if flag(cabalProject)
build-depends: haskell-language-server:hls-cabal-project-plugin
cpp-options: -Dhls_cabal_project

library hls-cabal-project-plugin
import: defaults, pedantic, warnings
if !flag(cabalProject)
buildable: False
exposed-modules:
Ide.Plugin.CabalProject
Ide.Plugin.CabalProject.Parse
Ide.Plugin.CabalProject.Diagnostics
Ide.Plugin.CabalProject.Types

build-depends:
, bytestring
, Cabal-syntax >= 3.7
, containers
, deepseq
, directory
, filepath
, extra >=1.7.4
, ghcide == 2.11.0.0
, hashable
, hls-plugin-api == 2.11.0.0
, hls-graph == 2.11.0.0
, lens
, lsp ^>=2.7
, lsp-types ^>=2.3
, regex-tdfa ^>=1.3.1
, text
, text-rope
, transformers
, unordered-containers >=0.2.10.0
, containers
, process
, aeson
, Cabal
, pretty
, cabal-install
, cabal-install-solver
, haskell-language-server:hls-cabal-plugin
, base16-bytestring
, cryptohash-sha1

hs-source-dirs: plugins/hls-cabal-project-plugin/src

test-suite hls-cabal-project-plugin-tests
import: defaults, pedantic, test-defaults, warnings
if !flag(cabalProject)
buildable: False
type: exitcode-stdio-1.0
hs-source-dirs: plugins/hls-cabal-project-plugin/test
main-is: Main.hs
other-modules:
Utils
build-depends:
, bytestring
, Cabal-syntax >= 3.7
, extra
, filepath
, ghcide
, haskell-language-server:hls-cabal-project-plugin
, hls-test-utils == 2.11.0.0
, lens
, lsp-types
, text
, hls-plugin-api
, cabal-install

-----------------------------
-- class plugin
-----------------------------
Expand Down Expand Up @@ -1830,6 +1910,7 @@ library
, pedantic
-- plugins
, cabal
, cabalProject
, callHierarchy
, cabalfmt
, cabalgild
Expand Down
17 changes: 16 additions & 1 deletion hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
module Ide.Types
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor, defaultCabalProjectPluginDescriptor
, defaultPluginPriority
, describePlugin
, IdeCommand(..)
Expand Down Expand Up @@ -1077,6 +1077,21 @@ defaultCabalPluginDescriptor plId desc =
Nothing
[".cabal"]

defaultCabalProjectPluginDescriptor :: PluginId -> T.Text -> PluginDescriptor ideState
defaultCabalProjectPluginDescriptor plId desc =
PluginDescriptor
plId
desc
defaultPluginPriority
mempty
mempty
mempty
defaultConfigDescriptor
mempty
mempty
Nothing
[".project"]

newtype CommandId = CommandId T.Text
deriving (Show, Read, Eq, Ord)
instance IsString CommandId where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Ide.Plugin.Cabal.Diagnostics
, warningDiagnostic
, positionFromCabalPosition
, fatalParseErrorDiagnostic
, toBeginningOfNextLine
, mkDiag
-- * Re-exports
, FileDiagnostic
, Diagnostic(..)
Expand Down
Loading
Loading