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
3
16
4
17
import qualified Data.ByteString as BS
5
18
import Data.List (find )
@@ -10,7 +23,7 @@ import qualified Data.Text.Encoding as T
10
23
import qualified Distribution.Fields as Syntax
11
24
import qualified Distribution.Parsec.Position as Syntax
12
25
import Ide.Plugin.Cabal.Completion.Types
13
- import qualified Language.LSP.Protocol.Types as LSPTypes
26
+ import qualified Language.LSP.Protocol.Types as LSP
14
27
15
28
-- ----------------------------------------------------------------
16
29
-- Cabal-syntax utilities I don't really want to write myself
@@ -32,7 +45,7 @@ findStanzaForColumn col ctx = case NE.uncons ctx of
32
45
--
33
46
-- The result is said field and its starting position
34
47
-- or Nothing if the passed list of fields is empty.
35
-
48
+ --
36
49
-- This only looks at the row of the cursor and not at the cursor's
37
50
-- position within the row.
38
51
--
@@ -54,7 +67,7 @@ findFieldSection cursor (x:y:ys)
54
67
--
55
68
-- The result is said field line and its starting position
56
69
-- or Nothing if the passed list of fields is empty.
57
-
70
+ --
58
71
-- This function assumes that elements in a field's @FieldLine@ list
59
72
-- do not share the same row.
60
73
findFieldLine :: Syntax. Position -> [Syntax. Field Syntax. Position ] -> Maybe (Syntax. FieldLine Syntax. Position )
@@ -76,7 +89,7 @@ findFieldLine cursor fields =
76
89
-- or the cursor position is not next to, or on a word.
77
90
-- For this function, a word is a sequence of consecutive characters
78
91
-- that are not a space or column.
79
-
92
+ --
80
93
-- This function currently only considers words inside of a @FieldLine@.
81
94
findTextWord :: Syntax. Position -> [Syntax. Field Syntax. Position ] -> Maybe T. Text
82
95
findTextWord _cursor [] = Nothing
@@ -175,9 +188,9 @@ getNameEndPosition (Syntax.Name (Syntax.Position row col) byteString) = Syntax.P
175
188
getFieldLineEndPosition :: Syntax. FieldLine Syntax. Position -> Syntax. Position
176
189
getFieldLineEndPosition (Syntax. FieldLine (Syntax. Position row col) byteString) = Syntax. Position row (col + BS. length byteString)
177
190
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
181
194
where
182
195
startLSPPos = cabalPositionToLSPPosition $ getAnnotation field
183
196
endLSPPos = cabalPositionToLSPPosition $ getFieldEndPosition field
0 commit comments