Skip to content

Commit 5876ac7

Browse files
committed
Implement parsing and diagnostics for cabal.project files with the cabal-project plugin.
1 parent d9aaa01 commit 5876ac7

File tree

21 files changed

+730
-1
lines changed

21 files changed

+730
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ store/
5151
gh-release-artifacts/
5252

5353
.hls/
54+
55+
# local cabal package
56+
vendor/parse-cabal-project

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
# Commit git commit -m "Removed submodule <name>"
99
# Delete the now untracked submodule files
1010
# rm -rf path_to_submodule
11+
12+
[submodule "vendor/cabal"]
13+
path = vendor/cabal
14+
url = https://github.com/rm41339/cabal.git

cabal.project

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ packages:
66
./ghcide
77
./hls-plugin-api
88
./hls-test-utils
9+
./vendor/cabal/Cabal
10+
./vendor/cabal/Cabal-syntax
11+
./vendor/cabal/cabal-install
12+
./vendor/cabal/cabal-install-solver
13+
./vendor/cabal/Cabal-described
14+
./vendor/cabal/Cabal-tree-diff
915

16+
package cabal-install
17+
tests: False
18+
benchmarks: False
1019

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

haskell-language-server.cabal

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,86 @@ test-suite hls-cabal-plugin-tests
317317
, text
318318
, hls-plugin-api
319319

320+
-----------------------------
321+
-- cabal project plugin
322+
-----------------------------
323+
324+
flag cabalProject
325+
description: Enable cabalProject plugin
326+
default: True
327+
manual: True
328+
329+
common cabalProject
330+
if flag(cabalProject)
331+
build-depends: haskell-language-server:hls-cabal-project-plugin
332+
cpp-options: -Dhls_cabal_project
333+
334+
library hls-cabal-project-plugin
335+
import: defaults, pedantic, warnings
336+
if !flag(cabalProject)
337+
buildable: False
338+
exposed-modules:
339+
Ide.Plugin.CabalProject
340+
Ide.Plugin.CabalProject.Parse
341+
Ide.Plugin.CabalProject.Diagnostics
342+
Ide.Plugin.CabalProject.Types
343+
344+
build-depends:
345+
, bytestring
346+
, Cabal-syntax >= 3.7
347+
, containers
348+
, deepseq
349+
, directory
350+
, filepath
351+
, extra >=1.7.4
352+
, ghcide == 2.11.0.0
353+
, hashable
354+
, hls-plugin-api == 2.11.0.0
355+
, hls-graph == 2.11.0.0
356+
, lens
357+
, lsp ^>=2.7
358+
, lsp-types ^>=2.3
359+
, regex-tdfa ^>=1.3.1
360+
, text
361+
, text-rope
362+
, transformers
363+
, unordered-containers >=0.2.10.0
364+
, containers
365+
, process
366+
, aeson
367+
, Cabal
368+
, pretty
369+
, cabal-install
370+
, cabal-install-solver
371+
, haskell-language-server:hls-cabal-plugin
372+
, base16-bytestring
373+
, cryptohash-sha1
374+
375+
hs-source-dirs: plugins/hls-cabal-project-plugin/src
376+
377+
test-suite hls-cabal-project-plugin-tests
378+
import: defaults, pedantic, test-defaults, warnings
379+
if !flag(cabalProject)
380+
buildable: False
381+
type: exitcode-stdio-1.0
382+
hs-source-dirs: plugins/hls-cabal-project-plugin/test
383+
main-is: Main.hs
384+
other-modules:
385+
Utils
386+
build-depends:
387+
, bytestring
388+
, Cabal-syntax >= 3.7
389+
, extra
390+
, filepath
391+
, ghcide
392+
, haskell-language-server:hls-cabal-project-plugin
393+
, hls-test-utils == 2.11.0.0
394+
, lens
395+
, lsp-types
396+
, text
397+
, hls-plugin-api
398+
, cabal-install
399+
320400
-----------------------------
321401
-- class plugin
322402
-----------------------------
@@ -1830,6 +1910,7 @@ library
18301910
, pedantic
18311911
-- plugins
18321912
, cabal
1913+
, cabalProject
18331914
, callHierarchy
18341915
, cabalfmt
18351916
, cabalgild

hls-plugin-api/src/Ide/Types.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{-# LANGUAGE UndecidableInstances #-}
1515
{-# LANGUAGE ViewPatterns #-}
1616
module Ide.Types
17-
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor
17+
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor, defaultCabalProjectPluginDescriptor
1818
, defaultPluginPriority
1919
, describePlugin
2020
, IdeCommand(..)
@@ -1077,6 +1077,21 @@ defaultCabalPluginDescriptor plId desc =
10771077
Nothing
10781078
[".cabal"]
10791079

1080+
defaultCabalProjectPluginDescriptor :: PluginId -> T.Text -> PluginDescriptor ideState
1081+
defaultCabalProjectPluginDescriptor plId desc =
1082+
PluginDescriptor
1083+
plId
1084+
desc
1085+
defaultPluginPriority
1086+
mempty
1087+
mempty
1088+
mempty
1089+
defaultConfigDescriptor
1090+
mempty
1091+
mempty
1092+
Nothing
1093+
[".project"]
1094+
10801095
newtype CommandId = CommandId T.Text
10811096
deriving (Show, Read, Eq, Ord)
10821097
instance IsString CommandId where

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Diagnostics.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Ide.Plugin.Cabal.Diagnostics
55
, warningDiagnostic
66
, positionFromCabalPosition
77
, fatalParseErrorDiagnostic
8+
, toBeginningOfNextLine
9+
, mkDiag
810
-- * Re-exports
911
, FileDiagnostic
1012
, Diagnostic(..)

0 commit comments

Comments
 (0)