Skip to content

Commit cb4c4af

Browse files
committed
Safely handle linenumbering for errors in the first line of cabal files
1 parent ed96358 commit cb4c4af

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ positionFromCabalPosition :: Syntax.Position -> Position
6363
positionFromCabalPosition (Syntax.Position line column) = Position (fromIntegral line') (fromIntegral col')
6464
where
6565
-- LSP is zero-based, Cabal is one-based
66-
line' = line-1
67-
col' = column-1
66+
-- Cabal can return line 0 for errors in the first line
67+
line' = if line <= 0 then 0 else line-1
68+
col' = if column <= 0 then 0 else column-1
6869

6970
-- | Create a 'FileDiagnostic'
7071
mkDiag

0 commit comments

Comments
 (0)