Skip to content

Commit

Permalink
WIP: start updating to lsp-2.0
Browse files Browse the repository at this point in the history
Towards #1350.

This is a giant pain in the butt.  Lots of names, function signatures,
etc. changed and there doesn't seem to be any documentation/migration
guide explaining how to update.
  • Loading branch information
byorgey committed Feb 7, 2024
1 parent bce45cc commit 0e75d77
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/swarm-lang/Swarm/Language/LSP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-- See the docs/EDITORS.md to learn how to use it.
module Swarm.Language.LSP where

import Data.Int (Int32)
import Control.Lens (to, (^.))
import Control.Monad (void)
import Control.Monad.IO.Class
Expand All @@ -15,9 +16,9 @@ import Data.Text (Text)
import Data.Text.IO qualified as Text
import Language.LSP.Diagnostics
import Language.LSP.Server
import Language.LSP.Types (Hover (Hover))
import Language.LSP.Types qualified as J
import Language.LSP.Types.Lens qualified as J
import Language.LSP.Protocol.Types (Hover (Hover))
import Language.LSP.Protocol.Types qualified as J
import Language.LSP.Protocol.Lens qualified as J
import Language.LSP.VFS (VirtualFile (..), virtualFileText)
import Swarm.Language.LSP.Hover qualified as H
import Swarm.Language.LSP.VarUsage qualified as VU
Expand All @@ -34,15 +35,15 @@ lspMain =
void $
runServer $
ServerDefinition
{ onConfigurationChange = const $ const $ Right ()
{ onConfigChange = const $ const $ Right ()
, defaultConfig = ()
, doInitialize = \env _req -> pure $ Right env
, staticHandlers = handlers
, interpretHandler = \env -> Iso (runLspT env) liftIO
, options =
defaultOptions
{ -- set sync options to get DidSave event, as well as Open and Close events.
textDocumentSync =
optTextDocumentSync =
Just
( J.TextDocumentSyncOptions
(Just True)
Expand All @@ -57,15 +58,17 @@ lspMain =
-- Using SyncFull seems to handle the debounce for us.
-- The alternative is to use SyncIncremental, but then then
-- handler is called for each key-stroke.
syncKind = J.TdSyncFull
syncKind = J.TextDocumentSyncKind_Full

diagnosticSourcePrefix :: Text
diagnosticSourcePrefix = "swarm-lsp"

debug :: (MonadIO m) => Text -> m ()
debug msg = liftIO $ Text.hPutStrLn stderr $ "[swarm-lsp] " <> msg

validateSwarmCode :: J.NormalizedUri -> J.TextDocumentVersion -> Text -> LspM () ()
type TextDocumentVersion = Int32

validateSwarmCode :: J.NormalizedUri -> TextDocumentVersion -> Text -> LspM () ()
validateSwarmCode doc version content = do
-- debug $ "Validating: " <> from (show doc) <> " ( " <> content <> ")"

Expand Down
5 changes: 2 additions & 3 deletions src/swarm-lang/Swarm/Language/LSP/Hover.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.Maybe (catMaybes, fromMaybe)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Utf16.Rope qualified as R
import Language.LSP.Types qualified as J
import Language.LSP.Protocol.Types qualified as J
import Language.LSP.VFS
import Swarm.Language.Context as Ctx
import Swarm.Language.Module (Module (..))
Expand All @@ -53,11 +53,10 @@ lspToRopePosition (J.Position myLine myCol) =

showHoverInfo ::
J.NormalizedUri ->
J.TextDocumentVersion ->
J.Position ->
VirtualFile ->
Maybe (Text, Maybe J.Range)
showHoverInfo _ _ p vf@(VirtualFile _ _ myRope) =
showHoverInfo _ p vf@(VirtualFile _ _ myRope) =
case readTerm' content of
Left _ -> Nothing
Right Nothing -> Nothing
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-lang/Swarm/Language/LSP/VarUsage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Set (Set)
import Data.Set qualified as S
import Data.Text (Text)
import Data.Text qualified as T
import Language.LSP.Types qualified as J
import Language.LSP.Protocol.Types qualified as J
import Swarm.Language.Parse qualified as P
import Swarm.Language.Syntax
import Swarm.Util qualified as U
Expand Down
3 changes: 2 additions & 1 deletion swarm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ library swarm-lang
containers,
extra,
lens,
lsp >= 1.6 && < 1.7,
lsp >= 2.0 && < 2.5,
lsp-types >= 2.0 && < 2.2,
hashable,
megaparsec,
mtl,
Expand Down

0 comments on commit 0e75d77

Please sign in to comment.