File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
plugins/hls-refactor-plugin
src/Development/IDE/Plugin Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -1973,15 +1973,18 @@ regexSingleMatch msg regex = case matchRegexUnifySpaces msg regex of
19731973 _ -> Nothing
19741974
19751975-- | Process a list of (module_name, filename:src_span) values
1976- -- | Eg. [(Data.Map, app/ModuleB.hs:2:1-18), (Data.HashMap.Strict, app/ModuleB.hs:3:1-29)]
1976+ --
1977+ -- Eg. [(Data.Map, app/ModuleB.hs:2:1-18), (Data.HashMap.Strict, app/ModuleB.hs:3:1-29)]
19771978regExImports :: T. Text -> Maybe [(T. Text , T. Text )]
19781979regExImports msg
19791980 | Just mods' <- allMatchRegex msg " ‘([^’]*)’"
19801981 , Just srcspans' <- allMatchRegex msg
1982+ -- This regex has to be able to deal both with single-line srcpans like "(/path/to/File.hs:2:1-18)"
1983+ -- as well as multi-line srcspans like "(/path/to/File.hs:(3,1)-(5,2))"
19811984#if MIN_VERSION_ghc(9,7,0)
1982- " \\ (at ([^)]* )\\ )"
1985+ " \\ (at ([^:]+:[^ ]+ )\\ )"
19831986#else
1984- " \\ (([^)]* )\\ )"
1987+ " \\ (([^:]+:[^ ]+ )\\ )"
19851988#endif
19861989 , mods <- [mod | [_,mod ] <- mods']
19871990 , srcspans <- [srcspan | [_,srcspan] <- srcspans']
Original file line number Diff line number Diff line change @@ -1501,6 +1501,30 @@ extendImportTests = testGroup "extend import actions"
15011501 , " f :: Foo"
15021502 , " f = undefined"
15031503 ])
1504+ , testSession " data constructor with two multiline import lists that can be extended with it" $ template
1505+ []
1506+ (" A.hs" , T. unlines
1507+ [ " module A where"
1508+ , " import Prelude ("
1509+ , " )"
1510+ , " import Data.Maybe ("
1511+ , " )"
1512+ , " f = Nothing"
1513+ ])
1514+ (Range (Position 5 5 ) (Position 5 6 ))
1515+ [ " Add Maybe(..) to the import list of Data.Maybe"
1516+ , " Add Maybe(..) to the import list of Prelude"
1517+ , " Add Maybe(Nothing) to the import list of Data.Maybe"
1518+ , " Add Maybe(Nothing) to the import list of Prelude"
1519+ ]
1520+ (T. unlines
1521+ [" module A where"
1522+ , " import Prelude ("
1523+ , " )"
1524+ , " import Data.Maybe (Maybe (..)"
1525+ , " )"
1526+ , " f = Nothing"
1527+ ])
15041528 ]
15051529 where
15061530 codeActionTitle CodeAction {_title= x} = x
You can’t perform that action at this time.
0 commit comments