-
Notifications
You must be signed in to change notification settings - Fork 97
Use InitializeParams.rootUri for initial session setup #713
Conversation
|
ide <- getIdeState getNextReqId sendFunc (makeLSPVFSHandle lspFuncs) clientCapabilities | ||
withProgress withIndefiniteProgress | ||
withProgress withIndefiniteProgress cfg |
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.
I think the rootUri is available through LspFuncs
as rootPath
, which is a bit confusingly admittedly. Can we just pass that here instead? Instead of passing through the config.
exe/Main.hs
Outdated
-- we use `Maybe InitializeParams` as the config type. | ||
-- Change this if you want to parse InitializeRequest/DidChangeConfigurationNotification differently. | ||
let onInitialConfiguration RequestMessage{_params=initParams} = Right $ Just initParams | ||
onConfigurationChange = const $ Right Nothing |
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.
The config
type is the settings that users can customise from the language clients, not something internal to the language server. haskell-lsp
handles this a bit weirdly in that it lets us parse it ourselves from the initialisation message here but it's probably best to not use it as a mechanism for passing about information from the initialization request
To test this I would take a look at |
In the tests, I open ghcide in |
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.
Thank you for fixing this!
We already have code in place to parse and the InitializeParams
, and in the interest of consistency it would be better to reuse it.
I've quickly put some code together to show how this works. Can you take a look at pepeiborra@9d94d82 and adapt your PR accordingly? Please check that it works as expected as I have not actually run it.
@pepeiborra thanks I'll have a look. I followed @bubba 's advice and retrieved the path from LSPFuncs instead. Should I go back to the parsing approach? Also, do you have any idea why my testing approach isn't working? |
If you can follow @bubba 's advice with minimal changes, then I believe that should be fine.
I believe it doesn't work because ghcide calls findCradle see Main.hs:264 |
Aaha that makes sense. So then what is the change in behaviour that using rootUri should give us (and that i can test for)? |
@pepeiborra @sureyeaah just to make sure I understand this, the So perhaps a file structure like:
Launch ghcide in |
Thanks @pepeiborra @bubba! Ready for review. |
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.
Looks good to me, other than the pending simplification and the confirmation about the test
@@ -133,7 +133,7 @@ runLanguageServer options userHandlers onInitialConfig onConfigChange getIdeStat | |||
handleInit exitClientMsg clearReqId waitForCancel clientMsgChan [email protected]{..} = do | |||
|
|||
ide <- getIdeState getNextReqId sendFunc (makeLSPVFSHandle lspFuncs) clientCapabilities | |||
withProgress withIndefiniteProgress | |||
withProgress withIndefiniteProgress lspFuncs |
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.
A bunch of the arguments to getIdeState
are contained inside lspFuncs
. Please simplify
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.
Didn't realize. Fixed.
@@ -2781,9 +2782,22 @@ benchmarkTests = | |||
, Bench.name e /= "edit" -- the edit experiment does not ever fail | |||
] | |||
|
|||
-- | checks if we use InitializeParams.rootUri for loading session | |||
rootUriTests :: TestTree | |||
rootUriTests = testCase "use rootUri" . withoutStackEnv . runTest "dirA" "dirB" $ \dir -> do |
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.
Does this test fail without the new code?
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.
Yeah it does.
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.
This LGTM! Thanks for getting this squared off
rebase needed |
@pepeiborra rebased |
…e#713) * add rootUri tests * use rootUri in session loader
…e#713) * add rootUri tests * use rootUri in session loader
…e#713) * add rootUri tests * use rootUri in session loader
Pass the
config
param torunLanguageServer
so that we can extract the directory fromInitializeRequest
.Fixes https://github.com/digital-asset/ghcide/issues/646