@@ -182,25 +182,29 @@ completion _ide _ complParams = do
182
182
}
183
183
_ -> return $ J. List []
184
184
185
- -- ---------------------------------------------------------------------
185
+ -----------------------------------------------------------------------
186
186
187
- -- | Find first line after (last pragma / last shebang / beginning of file).
188
- -- Useful for inserting pragmas.
187
+ -- | Find first line after the last LANGUAGE pragma
188
+ -- Defaults to line 0 if the file contains no shebang(s), OPTIONS_GHC pragma(s), or other LANGUAGE pragma(s)
189
+ -- Otherwise it will be one after the count of line numbers, with order: Shebangs -> OPTIONS_GHC -> LANGUAGE
189
190
endOfModuleHeader :: T. Text -> Range
190
191
endOfModuleHeader contents = Range loc loc
191
192
where
192
193
loc = Position line 0
193
- line = maybe 0 succ (lastShebang contents <|> lastOptsGhc contents <|> lastLangPrag contents)
194
- lastShebang = lastLineWithPrefix $ T. isPrefixOf " #! "
195
- lastLangPrag = lastLineWithPrefix $ checkPragma " LANGUAGE " 8
196
- lastOptsGhc = lastLineWithPrefix $ checkPragma " OPTIONS_GHC " 11
194
+ line = afterLangPragma contents . afterOptsGhc contents $ afterShebang contents
195
+ afterLangPragma contents = afterPragma contents " LANGUAGE "
196
+ afterOptsGhc contents = afterPragma contents " OPTIONS_GHC "
197
+ afterShebang contents = maybe 0 succ $ lastLineWithPrefix ( T. isPrefixOf " #! " ) contents
197
198
198
199
lastLineWithPrefix :: (T. Text -> Bool ) -> T. Text -> Maybe Int
199
200
lastLineWithPrefix p contents = listToMaybe $ reverse $ findIndices p $ T. lines contents
200
201
201
- checkPragma :: T. Text -> Int -> T. Text -> Bool
202
- checkPragma name n = check
202
+ afterPragma :: T. Text -> T. Text -> Int -> Int
203
+ afterPragma contents name lineNum = maybe lineNum succ $ lastLineWithPrefix (checkPragma name) contents
204
+
205
+ checkPragma :: T. Text -> T. Text -> Bool
206
+ checkPragma name = check
203
207
where
204
208
check l = isPragma l && getName l == name
205
- getName l = T. take n $ T. dropWhile isSpace $ T. drop 3 l
209
+ getName l = T. take ( T. length name) $ T. dropWhile isSpace $ T. drop 3 l
206
210
isPragma = T. isPrefixOf " {-#"
0 commit comments