Skip to content

Commit 39b4389

Browse files
committed
fix merge issues
1 parent adcbe09 commit 39b4389

File tree

3 files changed

+4
-88
lines changed

3 files changed

+4
-88
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import qualified Data.ByteString as BS
1717
import Data.Hashable
1818
import Data.HashMap.Strict (HashMap)
1919
import qualified Data.HashMap.Strict as HashMap
20-
import Data.List (find)
2120
import qualified Data.List.NonEmpty as NE
2221
import qualified Data.Maybe as Maybe
2322
import qualified Data.Text as T
2423
import qualified Data.Text.Encoding as Encoding
2524
import Data.Typeable
2625
import Development.IDE as D
27-
import Development.IDE.Core.PluginUtils
2826
import Development.IDE.Core.Shake (restartShakeSession)
2927
import qualified Development.IDE.Core.Shake as Shake
3028
import Development.IDE.Graph (Key, alwaysRerun)
@@ -33,21 +31,19 @@ import Development.IDE.Types.Shake (toKey)
3331
import qualified Distribution.Fields as Syntax
3432
import qualified Distribution.Parsec.Position as Syntax
3533
import GHC.Generics
36-
import Ide.Plugin.Cabal.Completion.CabalFields as CabalFields
3734
import qualified Ide.Plugin.Cabal.Completion.Completer.Types as CompleterTypes
3835
import qualified Ide.Plugin.Cabal.Completion.Completions as Completions
3936
import Ide.Plugin.Cabal.Completion.Types (ParseCabalCommonSections (ParseCabalCommonSections),
4037
ParseCabalFields (..),
4138
ParseCabalFile (..))
4239
import qualified Ide.Plugin.Cabal.Completion.Types as Types
43-
import Ide.Plugin.Cabal.Definition (gotoDefinitionAction)
40+
import Ide.Plugin.Cabal.Definition (gotoDefinition)
4441
import qualified Ide.Plugin.Cabal.Diagnostics as Diagnostics
4542
import qualified Ide.Plugin.Cabal.FieldSuggest as FieldSuggest
4643
import qualified Ide.Plugin.Cabal.LicenseSuggest as LicenseSuggest
4744
import Ide.Plugin.Cabal.Orphans ()
4845
import Ide.Plugin.Cabal.Outline
4946
import qualified Ide.Plugin.Cabal.Parse as Parse
50-
import Ide.Plugin.Error
5147
import Ide.Types
5248
import qualified Language.LSP.Protocol.Lens as JL
5349
import qualified Language.LSP.Protocol.Message as LSP
@@ -98,7 +94,7 @@ descriptor recorder plId =
9894
, mkPluginHandler LSP.SMethod_TextDocumentCompletion $ completion recorder
9995
, mkPluginHandler LSP.SMethod_TextDocumentDocumentSymbol moduleOutline
10096
, mkPluginHandler LSP.SMethod_TextDocumentCodeAction $ fieldSuggestCodeAction recorder
101-
, mkPluginHandler LSP.SMethod_TextDocumentDefinition gotoDefinitionAction
97+
, mkPluginHandler LSP.SMethod_TextDocumentDefinition gotoDefinition
10298
]
10399
, pluginNotificationHandlers =
104100
mconcat
@@ -283,32 +279,6 @@ fieldSuggestCodeAction recorder ide _ (CodeActionParams _ _ (TextDocumentIdentif
283279
let completionTexts = fmap (^. JL.label) completions
284280
pure $ FieldSuggest.fieldErrorAction uri fieldName completionTexts _range
285281

286-
-- | CodeActions for going to definitions.
287-
--
288-
-- Provides a CodeAction for going to a definition when clicking on an identifier.
289-
-- The definition is found by traversing the sections and comparing their name to
290-
-- the clicked identifier.
291-
--
292-
-- TODO: Support more definitions than sections.
293-
gotoDefinition :: PluginMethodHandler IdeState LSP.Method_TextDocumentDefinition
294-
gotoDefinition ideState _ msgParam = do
295-
nfp <- getNormalizedFilePathE uri
296-
cabalFields <- runActionE "cabal-plugin.commonSections" ideState $ useE ParseCabalFields nfp
297-
case CabalFields.findTextWord cursor cabalFields of
298-
Nothing ->
299-
pure $ InR $ InR Null
300-
Just cursorText -> do
301-
commonSections <- runActionE "cabal-plugin.commonSections" ideState $ useE ParseCabalCommonSections nfp
302-
case find (isSectionArgName cursorText) commonSections of
303-
Nothing ->
304-
pure $ InR $ InR Null
305-
Just commonSection -> do
306-
pure $ InL $ Definition $ InL $ Location uri $ CabalFields.getFieldLSPRange commonSection
307-
where
308-
cursor = Types.lspPositionToCabalPosition (msgParam ^. JL.position)
309-
uri = msgParam ^. JL.textDocument . JL.uri
310-
isSectionArgName name (Syntax.Section _ sectionArgName _) = name == CabalFields.onelineSectionArgs sectionArgName
311-
isSectionArgName _ _ = False
312282

313283
-- ----------------------------------------------------------------
314284
-- Cabal file of Interest rules and global variable

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Definition.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ import System.FilePath (joinPath,
5252
-- gathering all possible definitions by calling subfunctions.
5353

5454
-- TODO: Resolve more cases for go-to definition.
55-
gotoDefinitionAction :: PluginMethodHandler IdeState LSP.Method_TextDocumentDefinition
56-
gotoDefinitionAction ide _ msgParam = do
55+
gotoDefinition :: PluginMethodHandler IdeState LSP.Method_TextDocumentDefinition
56+
gotoDefinition ide _ msgParam = do
5757
nfp <- getNormalizedFilePathE uri
5858
cabalFields <- runActionE "cabal-plugin.commonSections" ide $ useE ParseCabalFields nfp
5959
-- Trim the AST tree, so multiple passes in subfunctions won't hurt the performance.

plugins/hls-cabal-plugin/test/Main.hs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Definition (gotoDefinitionTests)
2121
import Ide.Plugin.Cabal.LicenseSuggest (licenseErrorSuggestion)
2222
import qualified Ide.Plugin.Cabal.Parse as Lib
2323
import qualified Language.LSP.Protocol.Lens as L
24-
import qualified Language.LSP.Protocol.Types as LSP
2524
import Outline (outlineTests)
2625
import System.FilePath
2726
import Test.Hls
@@ -230,56 +229,3 @@ codeActionTests = testGroup "Code Actions"
230229
InR action@CodeAction{_title} <- codeActions
231230
guard (_title == "Replace with " <> license)
232231
pure action
233-
234-
-- ----------------------------------------------------------------------------
235-
-- Goto Definition Tests
236-
-- ----------------------------------------------------------------------------
237-
238-
gotoDefinitionTests :: TestTree
239-
gotoDefinitionTests = testGroup "Goto Definition"
240-
[ positiveTest "middle of identifier" (mkP 27 16) (mkR 6 0 7 22)
241-
, positiveTest "left of identifier" (mkP 30 12) (mkR 10 0 17 40)
242-
, positiveTest "right of identifier" (mkP 33 22) (mkR 20 0 23 34)
243-
, positiveTest "left of '-' in identifier" (mkP 36 20) (mkR 6 0 7 22)
244-
, positiveTest "right of '-' in identifier" (mkP 39 19) (mkR 10 0 17 40)
245-
, positiveTest "identifier in identifier list" (mkP 42 16) (mkR 20 0 23 34)
246-
, positiveTest "left of ',' right of identifier" (mkP 45 33) (mkR 10 0 17 40)
247-
, positiveTest "right of ',' left of identifier" (mkP 48 34) (mkR 6 0 7 22)
248-
249-
, negativeTest "right of ',' left of space" (mkP 51 23)
250-
, negativeTest "right of ':' left of space" (mkP 54 11)
251-
, negativeTest "not a definition" (mkP 57 8)
252-
, negativeTest "empty space" (mkP 59 7)
253-
]
254-
where
255-
mkP :: UInt -> UInt -> Position
256-
mkP x1 y1 = Position x1 y1
257-
258-
mkR :: UInt -> UInt -> UInt -> UInt -> Range
259-
mkR x1 y1 x2 y2 = Range (mkP x1 y1) (mkP x2 y2)
260-
261-
getDefinition :: Show b => (Definition |? b) -> Range
262-
getDefinition (InL (Definition (InL loc))) = loc^.L.range
263-
getDefinition unk = error $ "Unexpected pattern '" ++ show unk ++ "' , expected '(InL (Definition (InL loc))'"
264-
265-
-- A positive test checks if the provided range is equal
266-
-- to the expected range from the definition in the test file.
267-
-- The test emulates a goto-definition request of an actual definition.
268-
positiveTest :: TestName -> Position -> Range -> TestTree
269-
positiveTest testName cursorPos expectedRange =
270-
runCabalTestCaseSession testName "goto-definition" $ do
271-
doc <- openDoc "simple-with-common.cabal" "cabal"
272-
definitions <- getDefinitions doc cursorPos
273-
let locationRange = getDefinition definitions
274-
liftIO $ locationRange @?= expectedRange
275-
276-
-- A negative test checks if the request failed and
277-
-- the provided result is empty, i.e. `InR $ InR Null`.
278-
-- The test emulates a goto-definition request of anything but an
279-
-- actual definition.
280-
negativeTest :: TestName -> Position -> TestTree
281-
negativeTest testName cursorPos =
282-
runCabalTestCaseSession testName "goto-definition" $ do
283-
doc <- openDoc "simple-with-common.cabal" "cabal"
284-
empty <- getDefinitions doc cursorPos
285-
liftIO $ empty @?= (InR $ InR LSP.Null)

0 commit comments

Comments
 (0)