Skip to content
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

Merged
merged 22 commits into from
Aug 12, 2022
Merged

upgrade lsp to 1.5 #3072

merged 22 commits into from
Aug 12, 2022

Conversation

kokobd
Copy link
Collaborator

@kokobd kokobd commented Aug 1, 2022

This is a prerequisite of #3046

@kokobd kokobd marked this pull request as draft August 1, 2022 12:08
@kokobd
Copy link
Collaborator Author

kokobd commented Aug 3, 2022

I'm receiving a lot of logs like this if --verbose is enabled in ghcide-tests. And finally got OOM even with 64GB memory.
image

So disabling it for now

@kokobd
Copy link
Collaborator Author

kokobd commented Aug 4, 2022

I see. In lsp, there is a debug log, printing response body:
https://github.com/haskell/lsp/blob/8b63438313828a31ba1065ea865e504d532d093e/lsp/src/Language/LSP/Server/Control.hs#L224-L234
And in HLS, our logger sends a copy of log to LSP client:

withDefaultRecorder logFilePath Nothing minPriority $ \textWithPriorityRecorder -> do
let
recorder = cmapWithPrio pretty $ mconcat
[textWithPriorityRecorder
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
, lspMessageRecorder
& cfilter (\WithPriority{ priority } -> priority >= Error)
& cmapWithPrio renderDoc
, lspLogRecorder
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
& cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)

Then it goes into infinite recursion... So we should not enable debug logs in lsp package itself.

@michaelpj
Copy link
Collaborator

Hmm, I thought I had convinced myself that wasn't a problem :| I'm not 100% sure what to do about this. It's nice to be able to log the responses from LSP, but we do indeed have a loop problem if we then forward them on like this.

@kokobd
Copy link
Collaborator Author

kokobd commented Aug 8, 2022

It's nice to be able to log the responses from LSP

And some other tests depend on the logs, I had to fix them one by one. This makes the PR harder than I initially thought.

Currently I'm working on hlint tests

@kokobd kokobd marked this pull request as ready for review August 9, 2022 12:50
@kokobd kokobd requested a review from michaelpj as a code owner August 9, 2022 12:50
@kokobd kokobd requested review from guibou and Ailrun as code owners August 9, 2022 12:50
@kokobd
Copy link
Collaborator Author

kokobd commented Aug 9, 2022

Finally, the CI is almost green.

Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, outstanding work!

Comment on lines -51 to -54
instance Hashable Location
instance Hashable Range
instance Hashable Position
instance Hashable UInt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instances have been added to lsp-types-1.5. This is not a question or complaint, just a note for the next reviewer

hls-test-utils/src/Test/Hls/Util.hs Outdated Show resolved Hide resolved
@@ -706,6 +706,7 @@ shakeRestart recorder IdeState{..} vfs reason acts =
backlog <- readTVarIO $ dirtyKeys shakeExtras
queue <- atomicallyNamed "actionQueue - peek" $ peekInProgress $ actionQueue shakeExtras

-- this log is required by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to filter out the bad debug logs from lsp right? I'd like to come up with a better solution there. Can you open a ticket in lsp and link to it here, so we remember why we're doing this? At the moment this means that the low-level message logs won't even go to the file logging, which is bad since they're useful.

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 :|

@@ -381,3 +380,14 @@ priorityToLsp =
Info -> MtInfo
Warning -> MtWarning
Error -> MtError

toCologActionWithPrio :: (MonadIO m, HasCallStack) => Recorder (WithPriority msg) -> LogAction m (WithSeverity msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first time co-log-core was introduced in HLS, so I think there isn't a existing function for this.

pure (rope, range, replacement)
monadicIO $ forAllM gen
$ \(rope, range, replacement) -> do
newRope <- liftIO $ applyChange (toCologActionWithPrio $ cmapWithPrio LogVfs recorder) rope (TextDocumentContentChangeEvent (Just range) Nothing replacement)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass mempty :: LogAction Identity here? then you don't need IO, and you'll just not get hte log messages which you don't care about anyway. Then I think you can keep the old code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good advice!

@kokobd kokobd added the merge me Label to trigger pull request merge label Aug 12, 2022
@mergify mergify bot merged commit 2554981 into master Aug 12, 2022
sloorush pushed a commit to sloorush/haskell-language-server that referenced this pull request Sep 12, 2022
* upgrade lsp to 1.5

* fix stack.yaml

* try fix tests

* disable verbose logging in ghcide

* fix more tests in ghcide

* fix floskell test

* disable debug log in func-test

* disable debug log in lsp itself

* Revert "disable debug log in func-test"

This reverts commit 1fd6658.

* remove unused import

* fix hls test utils

* upgrade lsp in nix

* fix func-tests

* Revert "fix func-tests"

This reverts commit 2ecd76d.

* fix waitForDiagnosticsFromSourceWithTimeout

* use Null as dummy message in waitForDiagnosticsFromSourceWithTimeout

* simplify a test case

* add comment about lsp bad logs
@kokobd kokobd deleted the kokobd/lsp-1.5 branch September 13, 2022 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants