Skip to content

support selection range lsp feature #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jan 24, 2022
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
54c693e
add selection range support
Jan 5, 2022
4567bf8
add the whole import area as a selection step
Jan 15, 2022
660c641
add selection range plugin to all project files
Jan 16, 2022
ef5ff8d
Merge branch 'master' into feat/selection-range
Jan 16, 2022
3e39bfc
merge type signature with value definition
Jan 19, 2022
f88461f
Merge branch 'master' into feat/selection-range
Jan 19, 2022
a240561
support ghc 9
Jan 20, 2022
9c536ad
fix it for ghc-9.0
Jan 20, 2022
d081f7e
Merge branch 'master' into feat/selection-range
Jan 20, 2022
dfe02ae
remove unnecessary import
Jan 20, 2022
836f680
reformat GhcIde.hs
Jan 20, 2022
0894399
selection range: make it easier to understand
Jan 21, 2022
1a7d0f5
selection range: improve error handling
Jan 21, 2022
83f6201
update lsp-types to 1.4.0.1
Jan 21, 2022
0a96413
Merge branch 'master' into feat/selection-range
Jan 22, 2022
48a4709
add selection range to doc
Jan 22, 2022
bd7fcfd
fix comment for findSelectionRangesByPositions
Jan 22, 2022
a7ce386
remove a use of partial function
Jan 22, 2022
23ea08e
update author & maintainer
Jan 22, 2022
4d75549
Merge branch 'master' into feat/selection-range
Jan 22, 2022
cd5d8bc
use foldlM1 instead of foldl1
Jan 23, 2022
2d3c3ec
Merge branch 'master' into feat/selection-range
Jan 23, 2022
8e975df
add testdata to cabal file
Jan 23, 2022
94d45b6
update performace tips and log level
Jan 23, 2022
965b5dd
Merge branch 'master' into feat/selection-range
Jan 23, 2022
85b36be
Merge branch 'master' into feat/selection-range
pepeiborra Jan 24, 2022
72112bc
update lsp-types in nix
Jan 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ module Ide.Plugin.SelectionRange.ASTPreProcess
) where

import Control.Monad.Reader (Reader, asks)
import Data.Foldable (find, foldl')
import Data.List (foldl1', groupBy)
import Data.Foldable (find, foldl', foldl1)
import Data.List (groupBy)
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe)
import qualified Data.Set as Set
Expand Down Expand Up @@ -61,19 +63,18 @@ mergeImports node = pure $ node { nodeChildren = children }
. nodeChildren $ node

merge :: [HieAST a] -> Maybe (HieAST a)
merge [] = Nothing
merge [x] = Just x
merge xs = createVirtualNode xs
merge [] = Nothing
merge [x] = Just x
merge (x:xs) = Just $ createVirtualNode (x NonEmpty.:| xs)

nodeIsImport :: HieAST a -> Bool
nodeIsImport = isAnnotationInAstNode ("ImportDecl", "ImportDecl")

createVirtualNode :: [HieAST a] -> Maybe (HieAST a)
createVirtualNode [] = Nothing
createVirtualNode children = Just $ mkAstNode (NodeInfo mempty mempty mempty) span' children
createVirtualNode :: NonEmpty (HieAST a) -> HieAST a
createVirtualNode children = mkAstNode (NodeInfo mempty mempty mempty) span' (NonEmpty.toList children)
where
span' :: RealSrcSpan
span' = foldl1' combineRealSrcSpans . fmap nodeSpan $ children
span' = foldl1 combineRealSrcSpans . fmap nodeSpan $ children

{-|
Combine type signature with variable definition under a new parent node, if the signature is placed right before the
Expand Down Expand Up @@ -107,7 +108,7 @@ mergeAdjacentSigDef refMap (n1, n2) = do
-- Does that identifier appear in the second AST node as a definition? If so, we combines the two nodes.
refs <- Map.lookup typeSigId refMap
if any (isIdentADef (nodeSpan n2)) refs
then createVirtualNode [n1, n2]
then pure . createVirtualNode $ n1 NonEmpty.:| [n2]
else Nothing
where
checkAnnotation :: Maybe ()
Expand Down