4
4
module Ide.Plugin.Cabal.Diagnostics
5
5
( errorDiagnostic
6
6
, warningDiagnostic
7
+ , positionFromCabalPosition
7
8
-- * Re-exports
8
9
, FileDiagnostic
9
10
, Diagnostic (.. )
@@ -15,6 +16,7 @@ import Development.IDE (FileDiagnostic,
15
16
ShowDiagnostic (ShowDiag ))
16
17
import Distribution.Fields (showPError , showPWarning )
17
18
import qualified Ide.Plugin.Cabal.Parse as Lib
19
+ import Ide.PluginUtils (extendNextLine )
18
20
import Language.LSP.Types (Diagnostic (.. ),
19
21
DiagnosticSeverity (.. ),
20
22
DiagnosticSource , NormalizedFilePath ,
@@ -40,10 +42,19 @@ warningDiagnostic fp warning@(Lib.PWarning _ pos _) =
40
42
-- We define the range to be _from_ this position
41
43
-- _to_ the first column of the next line.
42
44
toBeginningOfNextLine :: Lib. Position -> Range
43
- toBeginningOfNextLine (Lib. Position line column) =
44
- Range
45
- (Position (fromIntegral line') (fromIntegral col'))
46
- (Position (fromIntegral $ line' + 1 ) 0 )
45
+ toBeginningOfNextLine cabalPos = extendNextLine $ Range pos pos
46
+ where
47
+ pos = positionFromCabalPosition cabalPos
48
+
49
+ -- | Convert a 'Lib.Position' from Cabal to a 'Range' that LSP understands.
50
+ --
51
+ -- Prefer this function over hand-rolled unpacking/packing, since LSP is zero-based,
52
+ -- while Cabal is one-based.
53
+ --
54
+ -- >>> positionFromCabalPosition $ Lib.Position 1 1
55
+ -- Position 0 0
56
+ positionFromCabalPosition :: Lib. Position -> Position
57
+ positionFromCabalPosition (Lib. Position line column) = Position (fromIntegral line') (fromIntegral col')
47
58
where
48
59
-- LSP is zero-based, Cabal is one-based
49
60
line' = line- 1
0 commit comments