Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion lsp/lsp.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ library
, unliftio ^>=0.2
, unliftio-core ^>=0.2
, unordered-containers ^>=0.2
, websockets ^>=0.13

if flag(websocket)
cpp-options: -DENABLE_WEBSOCKET
build-depends:
websockets ^>=0.13

executable lsp-demo-reactor-server
import: warnings
Expand Down Expand Up @@ -118,6 +122,10 @@ flag demo
description: Build the demo executables
default: False

flag websocket
description: Enable WebSocket support
default: True

test-suite lsp-test
import: warnings
type: exitcode-stdio-1.0
Expand Down
23 changes: 19 additions & 4 deletions lsp/src/Language/LSP/Server/Control.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
Expand All @@ -18,20 +19,20 @@ module Language.LSP.Server.Control (
prependHeader,
parseHeaders,

#ifdef ENABLE_WEBSOCKET
-- ** Using websockets
WebsocketConfig (..),
withWebsocket,
withWebsocketRunServer,
#endif /* ENABLE_WEBSOCKET */
) where

import Colog.Core (LogAction (..), Severity (..), WithSeverity (..), (<&))
import Colog.Core qualified as L
import Control.Applicative ((<|>))
import Control.Concurrent
import Control.Concurrent.Async
import Control.Concurrent.STM.TChan
import Control.Exception (catchJust, finally, throwIO)
import Control.Monad
import Control.Exception (catchJust, throwIO)
import Control.Monad.IO.Class
import Control.Monad.STM
import Data.Aeson qualified as J
Expand All @@ -49,11 +50,17 @@ import Language.LSP.Protocol.Message
import Language.LSP.Server.Core
import Language.LSP.Server.Processing qualified as Processing
import Language.LSP.VFS
import Network.WebSockets qualified as WS
import Prettyprinter
import System.IO
import System.IO.Error (isResourceVanishedError)

#ifdef ENABLE_WEBSOCKET
import Control.Concurrent
import Control.Monad
import Control.Exception (finally)
import Network.WebSockets qualified as WS
#endif /* ENABLE_WEBSOCKET */

data LspServerLog
= LspProcessingLog Processing.LspProcessingLog
| DecodeInitializeError String
Expand All @@ -64,7 +71,9 @@ data LspServerLog
| ServerStopped
| ParsedMsg T.Text
| SendMsg TL.Text
#ifdef ENABLE_WEBSOCKET
| WebsocketLog WebsocketLog
#endif /* ENABLE_WEBSOCKET */
deriving (Show)

instance Pretty LspServerLog where
Expand All @@ -89,7 +98,9 @@ instance Pretty LspServerLog where
pretty Starting = "Server starting"
pretty (ParsedMsg msg) = "---> " <> pretty msg
pretty (SendMsg msg) = "<--2-- " <> pretty msg
#ifdef ENABLE_WEBSOCKET
pretty (WebsocketLog msg) = "Websocket:" <+> pretty msg
#endif /* ENABLE_WEBSOCKET */

-- ---------------------------------------------------------------------

Expand Down Expand Up @@ -269,6 +280,8 @@ parseOne logger clientIn = go

-- ---------------------------------------------------------------------

#ifdef ENABLE_WEBSOCKET

data WebsocketLog
= WebsocketShutDown
| WebsocketNewConnection
Expand Down Expand Up @@ -382,6 +395,8 @@ withWebsocketRunServer wsConf withLspDefinition ioLogger lspLogger =
}
lspDefinition

#endif /* ENABLE_WEBSOCKET */

-- ---------------------------------------------------------------------

-- | Simple server to make sure all output is serialised
Expand Down
Loading