Skip to content

Commit ffd0f34

Browse files
Kobayashijneira
Kobayashi
andauthored
fix positionInRange (#2625)
* add a failing test case for positionInRange * fix positionInRange in PluginUtils * add hls-plugin-api to CI * fix ci Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
1 parent 92a8cc0 commit ffd0f34

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

.github/workflows/test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ jobs:
133133
# run the tests without parallelism to avoid running out of memory
134134
run: cabal test ghcide --test-options="$TEST_OPTS" || cabal test ghcide --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test ghcide --test-options="$TEST_OPTS"
135135

136+
- if: matrix.test
137+
name: Test hls-plugin-api
138+
run: cabal test hls-plugin-api --test-options="$TEST_OPTS" || cabal test hls-plugin-api --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-plugin-api --test-options="$TEST_OPTS"
139+
136140
- if: matrix.test
137141
name: Test func-test suite
138142
env:

hls-plugin-api/hls-plugin-api.cabal

+15
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,18 @@ library
7777
DataKinds
7878
KindSignatures
7979
TypeOperators
80+
81+
test-suite tests
82+
type: exitcode-stdio-1.0
83+
default-language: Haskell2010
84+
hs-source-dirs: test
85+
main-is: Main.hs
86+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
87+
other-modules: Ide.PluginUtilsTest
88+
build-depends:
89+
base
90+
, hls-plugin-api
91+
, tasty
92+
, tasty-hunit
93+
, tasty-rerun
94+
, lsp-types

hls-plugin-api/src/Ide/PluginUtils.hs

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Ide.PluginUtils
2525
allLspCmdIds',
2626
installSigUsr1Handler,
2727
subRange,
28+
positionInRange,
2829
usePropertyLsp,
2930
response,
3031
handleMaybe,
@@ -178,7 +179,7 @@ getClientConfig = getConfig
178179
getPluginConfig :: MonadLsp Config m => PluginId -> m PluginConfig
179180
getPluginConfig plugin = do
180181
config <- getClientConfig
181-
return $ configForPlugin config plugin
182+
return $ configForPlugin config plugin
182183

183184
-- ---------------------------------------------------------------------
184185

@@ -220,11 +221,7 @@ subRange smallRange range =
220221
&& positionInRange (_end smallRange) range
221222

222223
positionInRange :: Position -> Range -> Bool
223-
positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) =
224-
pl > sl && pl < el
225-
|| pl == sl && pl == el && po >= so && po <= eo
226-
|| pl == sl && po >= so
227-
|| pl == el && po <= eo
224+
positionInRange p (Range sp ep) = sp <= p && p <= ep
228225

229226
-- ---------------------------------------------------------------------
230227

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Ide.PluginUtilsTest
2+
( tests
3+
) where
4+
5+
import Ide.PluginUtils (positionInRange)
6+
import Language.LSP.Types (Position (Position), Range (Range))
7+
import Test.Tasty
8+
import Test.Tasty.HUnit
9+
10+
tests :: TestTree
11+
tests = testGroup "PluginUtils"
12+
[ positionInRangeTest
13+
]
14+
15+
positionInRangeTest :: TestTree
16+
positionInRangeTest = testGroup "positionInRange"
17+
[ testCase "single line, after the end" $
18+
positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False
19+
, testCase "single line, before the begining" $
20+
positionInRange (Position 1 0) (Range (Position 1 1) (Position 1 6)) @?= False
21+
, testCase "single line, in range" $
22+
positionInRange (Position 1 5) (Range (Position 1 1) (Position 1 6)) @?= True
23+
, testCase "multiline, in range" $
24+
positionInRange (Position 3 5) (Range (Position 1 1) (Position 5 6)) @?= True
25+
, testCase "multiline, out of range" $
26+
positionInRange (Position 3 5) (Range (Position 3 6) (Position 4 10)) @?= False
27+
]

hls-plugin-api/test/Main.hs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Main where
2+
3+
import qualified Ide.PluginUtilsTest as PluginUtilsTest
4+
import Test.Tasty
5+
import Test.Tasty.Ingredients.Rerun
6+
7+
main :: IO ()
8+
main = defaultMainWithRerun tests
9+
10+
tests :: TestTree
11+
tests = testGroup "Main"
12+
[ PluginUtilsTest.tests
13+
]

0 commit comments

Comments
 (0)