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

Store the lsp client settings in shakeExtras and create a Rule to get them #731

Merged
merged 18 commits into from
Sep 23, 2020
Merged

Store the lsp client settings in shakeExtras and create a Rule to get them #731

merged 18 commits into from
Sep 23, 2020

Conversation

jneira
Copy link
Member

@jneira jneira commented Aug 16, 2020

  • The motivation is to expose the client settings in shake rules, concretely my goal is to enable or disable hlint diagnostics using a client setting, changing diagnostics on the fly if the user change it in the editor
    • I hope being able to configure the rules (when parsing or typechecking for example?) using the client settings could be useful in general
  • The config is stored in the json raw format and updated using the InitializeParams and the didChangeConfigurationParamsHandler notification
  • The first one is empty using vscode, it notifies a configuration change when the lsp server is started. I guess other editors will use the first one (???). I assume both should update the client settings cause the onInitialConfig and onConfigChange callbacks returns the same type (it is a type param in ghcide)
  • The client settings has an specific rule, which uses alwaysRerun, inspired in Typecheck entire project on Initial Load and typecheck reverse dependencies of a file on saving #688. There @pepeiborra advised it can degrade performance, but i guess there will be not much configuration changes.
  • With this patch a Rule that depends on GetClientSettings (for example the hlint rule that produces hlint diagnostics) is rerun on a file modification or opening a new one. Ideally i would like to trigger it within the configuration change itself (maybe restarting the shake session?)

Sorry i am missing something obvious in the ghcide or shake concepts, this is my first pr touching their internals.

@jneira jneira changed the title Store the lsp client settings in shakeExtras Store the lsp client settings in shakeExtrasand create a Rule to get them Aug 16, 2020
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 sensible to me! Please take a look at my comments about early cutoff. Moreover, I agree that it is a good idea to restart the Shake session (with the usual setSomethingModified) whenever the config changes, please add that too.

Could we have some tests to at least check that the Shake session is restarted when the config does change?

@jneira
Copy link
Member Author

jneira commented Aug 16, 2020

@pepeiborra many thanks for your comments and insights, i was a little bit lost in the ghcide codebase.
thanks @wz1000 too to point me to #688 as an example of a rule to get info stored in a Var

@jneira jneira changed the title Store the lsp client settings in shakeExtrasand create a Rule to get them Store the lsp client settings in shakeExtras and create a Rule to get them Aug 16, 2020
@jneira
Copy link
Member Author

jneira commented Aug 21, 2020

Could we have some tests to at least check that the Shake session is restarted when the config does change?

I'll try to add it asap. Only comment that i've cherrypicked changes here in hls and now hlint suggestions honour happily the client setting 😄

@pepeiborra
Copy link
Collaborator

needs rebase (and tests!)

@jneira
Copy link
Member Author

jneira commented Sep 4, 2020

rebased! that was easy, implement the tests will take me some time thought cause i am not used to ghcode test suite, any tip will be welcomed 😄

@pepeiborra
Copy link
Collaborator

The test should do something along these lines:

  1. Open a file
  2. Wait for progress
  3. Change the lsp client settings
  4. Observe the session did restart. This is the tricky bit, it might be observable by waiting for progress. I recommend uncommenting the lines 3323-3327 in test/Main.hs so that you can see the LSP traffic

@jneira
Copy link
Member Author

jneira commented Sep 5, 2020

Yeah, i was thinking in add a test in hls with hlint, cause there it is easy to observe how hlints diagnostics come and go.

@pepeiborra
Copy link
Collaborator

I think we want to have a test here as well please. You can send custom messages to the lsp client if necessary, see how cradle loading is tested

@jneira
Copy link
Member Author

jneira commented Sep 8, 2020

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@jneira
Copy link
Member Author

jneira commented Sep 16, 2020

I cant make progress with the tests cause the test suite hangs in windows. hls one too so i suspect some change in lsp-test around the shutdown of the process is involved. 😟

@jneira
Copy link
Member Author

jneira commented Sep 19, 2020

After fixing the hang of the test suite in windows and add some logging notifications in the Shake module i have been able to add the test cases.

@jneira jneira requested a review from pepeiborra September 19, 2020 10:17
@wz1000
Copy link
Collaborator

wz1000 commented Sep 20, 2020

/azp run

@azure-pipelines
Copy link

Pull request contains merge conflicts.

@wz1000
Copy link
Collaborator

wz1000 commented Sep 20, 2020

rebase needed

@jneira
Copy link
Member Author

jneira commented Sep 21, 2020

There is a failing test for ghc-8.6 and 8.10 (but no for 8.8 🤔 )

2020-09-20T21:57:49.0532485Z   Interface loading tests
2020-09-20T21:57:49.2935216Z     iface-error-test-1:                                                                                   FAIL
2020-09-20T21:57:49.2959459Z       Exception: NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException"
.............. (NamedParserException "Response for id: IdInt 1" (NamedParserException "NotificationMessage ServerMethod (ProgressParams WorkDoneProgressBeginParams)" (BothFailed (Unexpected "ConduitParser.empty") (Unexpected "ConduitParser.empty"))))))))))))))))))))))))))))) (Unexpected "ConduitParser.empty")))))))))))))))))))))))))))))

I guess the new log notifications for shake session broke it. 😟

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.

There is a failing test for ghc-8.6 and 8.10 (but no for 8.8 🤔 )

2020-09-20T21:57:49.0532485Z   Interface loading tests
2020-09-20T21:57:49.2935216Z     iface-error-test-1:                                                                                   FAIL
2020-09-20T21:57:49.2959459Z       Exception: NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException "NotificationMessage ServerMethod PublishDiagnosticsParams" (NamedParserException"
.............. (NamedParserException "Response for id: IdInt 1" (NamedParserException "NotificationMessage ServerMethod (ProgressParams WorkDoneProgressBeginParams)" (BothFailed (Unexpected "ConduitParser.empty") (Unexpected "ConduitParser.empty"))))))))))))))))))))))))))))) (Unexpected "ConduitParser.empty")))))))))))))))))))))))))))))

I guess the new log notifications for shake session broke it. 😟

You can probably simplify the failing test as below, which might help it pass:

    res <- skipManyTill anyMessage $ responseForId li

@jneira
Copy link
Member Author

jneira commented Sep 22, 2020

Really tired of fpcomplete timeouts 😢

@jneira
Copy link
Member Author

jneira commented Sep 22, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jneira
Copy link
Member Author

jneira commented Sep 22, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jneira
Copy link
Member Author

jneira commented Sep 23, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jneira
Copy link
Member Author

jneira commented Sep 23, 2020

🤞

@jneira
Copy link
Member Author

jneira commented Sep 23, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jneira
Copy link
Member Author

jneira commented Sep 23, 2020

finally ci is green! @pepeiborra i think last requested changes are done, thanks for your patience 😄

@jneira jneira requested a review from pepeiborra September 23, 2020 11:39
@pepeiborra
Copy link
Collaborator

Eureka!

@pepeiborra pepeiborra merged commit c361a26 into haskell:master Sep 23, 2020
pepeiborra pushed a commit to pepeiborra/ghcide that referenced this pull request Oct 5, 2020
… them (haskell#731)

* Store client settings in ide state

* Log ide config registered in initHandler

* Use a Maybe aware updater function

* Create a Rule to get client settings

* Create a specific getter for client settings

* Trim trailing whitespace

* Use modifyVar to avoid race conditions

* Add comment to GetClientSettings

* Use defineEarlyCutOffNoFile for GetClientSettings

* Restart shake on config changed

* Use Hashed for clientSettings

* Send log notifications to client about session

* Show test output directly

* Add tests over client settings

* Apply hlint hints

* Simplify iface test to make it more robust

Following @pepeiborra advise

* Send session notifications only in test mode

* Retry bench execution
@jneira jneira deleted the client-settings-da branch October 6, 2020 05:36
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
… them (haskell/ghcide#731)

* Store client settings in ide state

* Log ide config registered in initHandler

* Use a Maybe aware updater function

* Create a Rule to get client settings

* Create a specific getter for client settings

* Trim trailing whitespace

* Use modifyVar to avoid race conditions

* Add comment to GetClientSettings

* Use defineEarlyCutOffNoFile for GetClientSettings

* Restart shake on config changed

* Use Hashed for clientSettings

* Send log notifications to client about session

* Show test output directly

* Add tests over client settings

* Apply hlint hints

* Simplify iface test to make it more robust

Following @pepeiborra advise

* Send session notifications only in test mode

* Retry bench execution
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
… them (haskell/ghcide#731)

* Store client settings in ide state

* Log ide config registered in initHandler

* Use a Maybe aware updater function

* Create a Rule to get client settings

* Create a specific getter for client settings

* Trim trailing whitespace

* Use modifyVar to avoid race conditions

* Add comment to GetClientSettings

* Use defineEarlyCutOffNoFile for GetClientSettings

* Restart shake on config changed

* Use Hashed for clientSettings

* Send log notifications to client about session

* Show test output directly

* Add tests over client settings

* Apply hlint hints

* Simplify iface test to make it more robust

Following @pepeiborra advise

* Send session notifications only in test mode

* Retry bench execution
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
… them (haskell/ghcide#731)

* Store client settings in ide state

* Log ide config registered in initHandler

* Use a Maybe aware updater function

* Create a Rule to get client settings

* Create a specific getter for client settings

* Trim trailing whitespace

* Use modifyVar to avoid race conditions

* Add comment to GetClientSettings

* Use defineEarlyCutOffNoFile for GetClientSettings

* Restart shake on config changed

* Use Hashed for clientSettings

* Send log notifications to client about session

* Show test output directly

* Add tests over client settings

* Apply hlint hints

* Simplify iface test to make it more robust

Following @pepeiborra advise

* Send session notifications only in test mode

* Retry bench execution
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.

3 participants