-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
upgrade lsp to 1.5 #3072
upgrade lsp to 1.5 #3072
Changes from 18 commits
2f50ba7
ba518a2
278d029
c763e79
ba9a761
d8600d1
1fd6658
62815a1
bb7c09e
4e2ca61
56a00c9
15a2320
cf134bd
51d13f2
2ecd76d
ef84255
c89ccfd
bf25f01
94eba10
7f97557
f565fb2
81179cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,17 +34,17 @@ import UnliftIO.Concurrent | |
import UnliftIO.Directory | ||
import UnliftIO.Exception | ||
|
||
import qualified Colog.Core as Colog | ||
import Control.Monad.IO.Unlift (MonadUnliftIO) | ||
import Development.IDE.Core.IdeConfiguration | ||
import Development.IDE.Core.Shake hiding (Log) | ||
import Development.IDE.Core.Shake hiding (Log, Priority) | ||
import Development.IDE.Core.Tracing | ||
import Development.IDE.Types.Logger | ||
|
||
import Control.Monad.IO.Unlift (MonadUnliftIO) | ||
import Data.Kind (Type) | ||
import qualified Development.IDE.Session as Session | ||
import Development.IDE.Types.Logger | ||
import qualified Development.IDE.Types.Logger as Logger | ||
import Development.IDE.Types.Shake (WithHieDb) | ||
import Language.LSP.Server (LanguageContextEnv, | ||
LspServerLog, | ||
type (<~>)) | ||
import System.IO.Unsafe (unsafeInterleaveIO) | ||
|
||
|
@@ -55,6 +55,7 @@ data Log | |
| LogReactorThreadStopped | ||
| LogCancelledRequest !SomeLspId | ||
| LogSession Session.Log | ||
| LogLspServer LspServerLog | ||
deriving Show | ||
|
||
instance Pretty Log where | ||
|
@@ -74,13 +75,15 @@ instance Pretty Log where | |
LogCancelledRequest requestId -> | ||
"Cancelled request" <+> viaShow requestId | ||
LogSession log -> pretty log | ||
LogLspServer log -> pretty log | ||
|
||
-- used to smuggle RankNType WithHieDb through dbMVar | ||
newtype WithHieDbShield = WithHieDbShield WithHieDb | ||
|
||
runLanguageServer | ||
:: forall config a m. (Show config) | ||
=> LSP.Options | ||
=> Recorder (WithPriority Log) | ||
-> LSP.Options | ||
-> Handle -- input | ||
-> Handle -- output | ||
-> config | ||
|
@@ -90,7 +93,7 @@ runLanguageServer | |
LSP.Handlers (m config), | ||
(LanguageContextEnv config, a) -> m config <~> IO)) | ||
-> IO () | ||
runLanguageServer options inH outH defaultConfig onConfigurationChange setup = do | ||
runLanguageServer recorder options inH outH defaultConfig onConfigurationChange setup = do | ||
-- This MVar becomes full when the server thread exits or we receive exit message from client. | ||
-- LSP server will be canceled when it's full. | ||
clientMsgVar <- newEmptyMVar | ||
|
@@ -106,8 +109,15 @@ runLanguageServer options inH outH defaultConfig onConfigurationChange setup = d | |
, LSP.options = modifyOptions options | ||
} | ||
|
||
let lspCologAction :: MonadIO m2 => Colog.LogAction m2 (Colog.WithSeverity LspServerLog) | ||
lspCologAction = toCologActionWithPrio $ cfilter | ||
(\msg -> priority msg >= Info) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to filter out the bad debug logs from An alternative solution could be to change the log action in HLS that sends logs to the client to never send debug logs. But I guess that's also surprising :| |
||
(cmapWithPrio LogLspServer recorder) | ||
|
||
void $ untilMVar clientMsgVar $ | ||
void $ LSP.runServerWithHandles | ||
lspCologAction | ||
lspCologAction | ||
inH | ||
outH | ||
serverDefinition | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ module Development.IDE.Types.Logger | |
, lspClientLogRecorder | ||
, module PrettyPrinterModule | ||
, renderStrict | ||
, toCologActionWithPrio | ||
) where | ||
|
||
import Control.Concurrent (myThreadId) | ||
|
@@ -59,7 +60,6 @@ import Language.LSP.Server | |
import qualified Language.LSP.Server as LSP | ||
import Language.LSP.Types (LogMessageParams (..), | ||
MessageType (..), | ||
ResponseError, | ||
SMethod (SWindowLogMessage, SWindowShowMessage), | ||
ShowMessageParams (..)) | ||
#if MIN_VERSION_prettyprinter(1,7,0) | ||
|
@@ -69,11 +69,10 @@ import Prettyprinter.Render.Text (renderStrict) | |
import Data.Text.Prettyprint.Doc as PrettyPrinterModule | ||
import Data.Text.Prettyprint.Doc.Render.Text (renderStrict) | ||
#endif | ||
import Control.Lens ((^.)) | ||
import Ide.Types (CommandId (CommandId), | ||
PluginId (PluginId)) | ||
import Language.LSP.Types.Lens (HasCode (code), | ||
HasMessage (message)) | ||
import Colog.Core (LogAction (..), | ||
Severity, | ||
WithSeverity (..)) | ||
import qualified Colog.Core as Colog | ||
import System.IO (Handle, | ||
IOMode (AppendMode), | ||
hClose, hFlush, | ||
|
@@ -381,3 +380,14 @@ priorityToLsp = | |
Info -> MtInfo | ||
Warning -> MtWarning | ||
Error -> MtError | ||
|
||
toCologActionWithPrio :: (MonadIO m, HasCallStack) => Recorder (WithPriority msg) -> LogAction m (WithSeverity msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Worth checking if there's anywhere else doing this already? I can't remember if there is... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first time |
||
toCologActionWithPrio (Recorder _logger) = LogAction $ \WithSeverity{..} -> do | ||
let priority = severityToPriority getSeverity | ||
_logger $ WithPriority priority callStack getMsg | ||
where | ||
severityToPriority :: Severity -> Priority | ||
severityToPriority Colog.Debug = Debug | ||
severityToPriority Colog.Info = Info | ||
severityToPriority Colog.Warning = Warning | ||
severityToPriority Colog.Error = Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬