Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Use InitializeParams.rootUri for initial session setup #713

Merged
merged 2 commits into from
Sep 3, 2020

Conversation

sureyeaah
Copy link
Contributor

@sureyeaah sureyeaah commented Jul 28, 2020

Pass the config param to runLanguageServer so that we can extract the directory from InitializeRequest.

Fixes https://github.com/digital-asset/ghcide/issues/646

@sureyeaah
Copy link
Contributor Author

sureyeaah commented Jul 28, 2020

  • Is there a better way to extract something from the config besides the InitCBConfig type class?
  • How do I test this?

ide <- getIdeState getNextReqId sendFunc (makeLSPVFSHandle lspFuncs) clientCapabilities
withProgress withIndefiniteProgress
withProgress withIndefiniteProgress cfg
Copy link
Collaborator

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

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

@lukel97
Copy link
Collaborator

lukel97 commented Jul 28, 2020

To test this I would take a look at runInDir https://github.com/digital-asset/ghcide/blob/826e886adac32378cb8a9f1ad735ca9234806eab/test/exe/Main.hs#L3043-L3064 and probably make another version that doesn't set the --cwd flag and calls runSession in a specific directory, and seeing if it can load documents relative to the specified root directory

@sureyeaah
Copy link
Contributor Author

sureyeaah commented Jul 29, 2020

In the tests, I open ghcide in dirA and run the session with root as dirB. Both these directories have different hie.yaml files. But regardless of whether I use InitializeParams.rootUri, the dirB/hie.yaml file is always used.

Copy link
Collaborator

@pepeiborra pepeiborra left a 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.

@sureyeaah
Copy link
Contributor Author

sureyeaah commented Jul 29, 2020

@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?

@pepeiborra
Copy link
Collaborator

@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?

If you can follow @bubba 's advice with minimal changes, then I believe that should be fine.

Also, do you have any idea why my testing approach isn't working?

I believe it doesn't work because ghcide calls findCradle see Main.hs:264

@sureyeaah
Copy link
Contributor Author

Aaha that makes sense. So then what is the change in behaviour that using rootUri should give us (and that i can test for)?

@lukel97
Copy link
Collaborator

lukel97 commented Jul 29, 2020

@pepeiborra @sureyeaah just to make sure I understand this, the findCradle logic is independent of the root directory and only depends on the file being loaded. But findCradle I think is really misnamed, since it only finds the hie.yaml file. The root directory is used for the implicit cradle instead, as dir here:

https://github.com/digital-asset/ghcide/blob/765967d19be4ca64abc999173029a6bfe6aec113/session-loader/Development/IDE/Session.hs#L199-L205

So perhaps a file structure like:

- a/
  - Foo.hs
  - a.cabal
- b/
  - Bar.hs
  - b.cabal

Launch ghcide in a/, but set the rootDir to ../b. Then try to load Bar.hs and see what happens?

@sureyeaah
Copy link
Contributor Author

Thanks @pepeiborra @bubba! Ready for review.

Copy link
Collaborator

@pepeiborra pepeiborra left a 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
Copy link
Collaborator

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

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it does.

Copy link
Collaborator

@lukel97 lukel97 left a 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

@pepeiborra
Copy link
Collaborator

rebase needed

@sureyeaah
Copy link
Contributor Author

@pepeiborra rebased

@lukel97 lukel97 merged commit cb2fd66 into haskell:master Sep 3, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…e#713)

* add rootUri tests

* use rootUri in session loader
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…e#713)

* add rootUri tests

* use rootUri in session loader
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…e#713)

* add rootUri tests

* use rootUri in session loader
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial session setup should use LSP InitializeParams.rootUri
3 participants