Safe Haskell | None |
---|---|
Language | GHC2021 |
Ide.Plugin.Cabal.Completion.CabalFields
Synopsis
- findStanzaForColumn :: Int -> NonEmpty (Int, StanzaContext) -> (StanzaContext, FieldContext)
- getModulesNames :: [Field any] -> [([Maybe BuildTargetName], ModuleName)]
- getFieldLSPRange :: Field Position -> Range
- findFieldSection :: Position -> [Field Position] -> Maybe (Field Position)
- findTextWord :: Position -> [Field Position] -> Maybe Text
- findFieldLine :: Position -> [Field Position] -> Maybe (FieldLine Position)
- getOptionalSectionName :: [SectionArg ann] -> Maybe Text
- getAnnotation :: Field ann -> ann
- getFieldName :: Field ann -> FieldName
- onelineSectionArgs :: [SectionArg ann] -> Text
- getFieldEndPosition :: Field Position -> Position
- getSectionArgEndPosition :: SectionArg Position -> Position
- getNameEndPosition :: Name Position -> Position
- getFieldLineEndPosition :: FieldLine Position -> Position
Documentation
findStanzaForColumn :: Int -> NonEmpty (Int, StanzaContext) -> (StanzaContext, FieldContext) Source #
Determine the context of a cursor position within a stack of stanza contexts
If the cursor is indented more than one of the stanzas in the stack the respective stanza is returned if this is never the case, the toplevel stanza in the stack is returned.
getModulesNames :: [Field any] -> [([Maybe BuildTargetName], ModuleName)] Source #
Given a cabal AST returns pairs of all respective target names
and the module name bound to them. If a target is a main library gives
Nothing
, otherwise Just target-name
Examples of input cabal files and the outputs:
- Target is a main library module:
library exposed-modules: MyLib
getModulesNames
output:
[([Nothing], "MyLib")]
- Same module names in different targets:
test-suite first-target other-modules: Config test-suite second-target other-modules: Config
getModulesNames
output:
[([Just "first-target", Just "second-target"], "Config")]
getFieldLSPRange :: Field Position -> Range Source #
Returns an LSP compatible range for a provided field
findFieldSection :: Position -> [Field Position] -> Maybe (Field Position) Source #
Determine the field the cursor is currently a part of.
The result is said field and its starting position or Nothing if the passed list of fields is empty.
This only looks at the row of the cursor and not at the cursor's position within the row.
TODO: we do not handle braces correctly. Add more tests!
findTextWord :: Position -> [Field Position] -> Maybe Text Source #
Determine the exact word at the current cursor position.
The result is said word or Nothing if the passed list is empty or the cursor position is not next to, or on a word. For this function, a word is a sequence of consecutive characters that are not a space or column.
This function currently only considers words inside of a FieldLine
.
findFieldLine :: Position -> [Field Position] -> Maybe (FieldLine Position) Source #
Determine the field line the cursor is currently a part of.
The result is said field line and its starting position or Nothing if the passed list of fields is empty.
This function assumes that elements in a field's FieldLine
list
do not share the same row.
getOptionalSectionName :: [SectionArg ann] -> Maybe Text Source #
Returns the name of a section if it has a name.
This assumes that the given section args belong to named stanza in which case the stanza name is returned.
getAnnotation :: Field ann -> ann Source #
getFieldName :: Field ann -> FieldName Source #
onelineSectionArgs :: [SectionArg ann] -> Text Source #
Makes a single text line out of multiple
SectionArg
s. Allows to display conditions,
flags, etc in one line, which is easier to read.
For example, flag
(
pedantic
)
will be joined in
one line, instead of four SectionArg
s separately.
getFieldEndPosition :: Field Position -> Position Source #
Returns the end position of a provided field
getSectionArgEndPosition :: SectionArg Position -> Position Source #
Returns the end position of a provided section arg