Skip to content

Commit eebf6b6

Browse files
committed
Don't look contents in endOfModuleHeader
1 parent 2f0fa18 commit eebf6b6

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

plugins/default/src/Ide/Plugin/Pragmas.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Control.Lens hiding (List)
1111
import Control.Monad (join)
1212
import Control.Monad.IO.Class
1313
import qualified Data.HashMap.Strict as H
14-
import Data.List.Extra (findIndex, nubOrdOn)
15-
import Data.Maybe (catMaybes, fromMaybe, listToMaybe)
14+
import Data.List.Extra (nubOrdOn)
15+
import Data.Maybe (catMaybes, listToMaybe)
1616
import qualified Data.Text as T
1717
import Development.IDE as D
1818
import Development.IDE.GHC.Compat
@@ -44,10 +44,9 @@ codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction
4444
codeActionProvider state _plId (CodeActionParams _ _ docId _ (J.CodeActionContext (J.List diags) _monly)) = do
4545
let mFile = docId ^. J.uri & uriToFilePath <&> toNormalizedFilePath'
4646
uri = docId ^. J.uri
47-
content <- fmap VFS.virtualFileText <$> LSP.getVirtualFile (toNormalizedUri uri)
4847
pm <- liftIO $ fmap join $ runAction "Pragmas.GetParsedModule" state $ getParsedModule `traverse` mFile
4948
let dflags = ms_hspp_opts . pm_mod_summary <$> pm
50-
insertRange = maybe (Range (Position 0 0) (Position 0 0)) (`endOfModuleHeader` content) pm
49+
insertRange = maybe (Range (Position 0 0) (Position 0 0)) endOfModuleHeader pm
5150
pedits = nubOrdOn snd . concat $ suggest dflags <$> diags
5251
return $ Right $ List $ pragmaEditToAction uri insertRange <$> pedits
5352

@@ -179,16 +178,12 @@ completion _ide _ complParams = do
179178

180179
-- | Find the first non-blank line before the first of (module name / imports / declarations).
181180
-- Useful for inserting pragmas.
182-
endOfModuleHeader :: ParsedModule -> Maybe T.Text -> Range
183-
endOfModuleHeader pm contents =
181+
endOfModuleHeader :: ParsedModule -> Range
182+
endOfModuleHeader pm =
184183
let mod = unLoc $ pm_parsed_source pm
185184
modNameLoc = getLoc <$> hsmodName mod
186185
firstImportLoc = getLoc <$> listToMaybe (hsmodImports mod)
187186
firstDeclLoc = getLoc <$> listToMaybe (hsmodDecls mod)
188-
line =
189-
fromMaybe 0 $
190-
firstNonBlankBefore . _line . _start =<< srcSpanToRange
191-
=<< modNameLoc <|> firstImportLoc <|> firstDeclLoc
192-
firstNonBlankBefore n = (n -) . fromMaybe 0 . findIndex (not . T.null) . reverse . take n . T.lines <$> contents
187+
line = maybe 0 (_line . _start) (modNameLoc <|> firstImportLoc <|> firstDeclLoc >>= srcSpanToRange)
193188
loc = Position line 0
194189
in Range loc loc

test/functional/FunctionalCodeAction.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ disableWarningTests =
592592
]
593593
, T.unlines
594594
[ "{-# OPTIONS_GHC -Wall #-}"
595-
, "{-# OPTIONS_GHC -Wno-unused-imports #-}"
596595
, ""
597596
, ""
597+
, "{-# OPTIONS_GHC -Wno-unused-imports #-}"
598598
, "module M where"
599599
, ""
600600
, "import Data.Functor"

0 commit comments

Comments
 (0)