1- {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
2- module Ide.Plugin.Cabal.Completion.CabalFields (findStanzaForColumn , findFieldSection , findTextWord , findFieldLine , getOptionalSectionName , getAnnotation , getFieldName , onelineSectionArgs , getFieldEndPosition , getSectionArgEndPosition , getNameEndPosition , getFieldLineEndPosition , getFieldLSPRange ) where
1+ module Ide.Plugin.Cabal.Completion.CabalFields
2+ ( findStanzaForColumn ,
3+ findFieldSection ,
4+ findTextWord ,
5+ findFieldLine ,
6+ getOptionalSectionName ,
7+ getAnnotation ,
8+ getFieldName ,
9+ onelineSectionArgs ,
10+ getFieldEndPosition ,
11+ getSectionArgEndPosition ,
12+ getNameEndPosition ,
13+ getFieldLineEndPosition ,
14+ getFieldLSPRange
15+ ) where
316
417import qualified Data.ByteString as BS
518import Data.List (find )
@@ -10,7 +23,7 @@ import qualified Data.Text.Encoding as T
1023import qualified Distribution.Fields as Syntax
1124import qualified Distribution.Parsec.Position as Syntax
1225import Ide.Plugin.Cabal.Completion.Types
13- import qualified Language.LSP.Protocol.Types as LSPTypes
26+ import qualified Language.LSP.Protocol.Types as LSP
1427
1528-- ----------------------------------------------------------------
1629-- Cabal-syntax utilities I don't really want to write myself
@@ -32,7 +45,7 @@ findStanzaForColumn col ctx = case NE.uncons ctx of
3245--
3346-- The result is said field and its starting position
3447-- or Nothing if the passed list of fields is empty.
35-
48+ --
3649-- This only looks at the row of the cursor and not at the cursor's
3750-- position within the row.
3851--
@@ -54,7 +67,7 @@ findFieldSection cursor (x:y:ys)
5467--
5568-- The result is said field line and its starting position
5669-- or Nothing if the passed list of fields is empty.
57-
70+ --
5871-- This function assumes that elements in a field's @FieldLine@ list
5972-- do not share the same row.
6073findFieldLine :: Syntax. Position -> [Syntax. Field Syntax. Position ] -> Maybe (Syntax. FieldLine Syntax. Position )
@@ -76,7 +89,7 @@ findFieldLine cursor fields =
7689-- or the cursor position is not next to, or on a word.
7790-- For this function, a word is a sequence of consecutive characters
7891-- that are not a space or column.
79-
92+ --
8093-- This function currently only considers words inside of a @FieldLine@.
8194findTextWord :: Syntax. Position -> [Syntax. Field Syntax. Position ] -> Maybe T. Text
8295findTextWord _cursor [] = Nothing
@@ -175,9 +188,9 @@ getNameEndPosition (Syntax.Name (Syntax.Position row col) byteString) = Syntax.P
175188getFieldLineEndPosition :: Syntax. FieldLine Syntax. Position -> Syntax. Position
176189getFieldLineEndPosition (Syntax. FieldLine (Syntax. Position row col) byteString) = Syntax. Position row (col + BS. length byteString)
177190
178- -- | Returns a LSP compatible range for a provided field
179- getFieldLSPRange :: Syntax. Field Syntax. Position -> LSPTypes . Range
180- getFieldLSPRange field = LSPTypes . Range startLSPPos endLSPPos
191+ -- | Returns an LSP compatible range for a provided field
192+ getFieldLSPRange :: Syntax. Field Syntax. Position -> LSP . Range
193+ getFieldLSPRange field = LSP . Range startLSPPos endLSPPos
181194 where
182195 startLSPPos = cabalPositionToLSPPosition $ getAnnotation field
183196 endLSPPos = cabalPositionToLSPPosition $ getFieldEndPosition field
0 commit comments