Skip to content

Conversation

@lukel97
Copy link
Collaborator

@lukel97 lukel97 commented Oct 27, 2019

Previously we were using a mixture of inferring server capabilities based on wether or not there was a handler registered for it, and wether or not the user of the library had set options for it.

This changes it to the former, so that Core.Options only contains options that are needed to tweak client behaviour, and all the actual capabilities are determined based on wether or not there is a handler set.

It also adds some stricter types, and throws errors if the user of the library forgets to set some mandatory options when a specific handler is set, for example executeCommand and documentOnTypeFormatting.

Closes #195

The capabilities should be all infered
Also pull out the logic into its own function
@lukel97 lukel97 requested a review from alanz October 27, 2019 21:04
@alanz alanz requested a review from cocreature October 27, 2019 21:21
-- | CodeActionKinds that this server may return.
-- The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server
-- may list out every specific kind they provide.
, codeActionKinds :: Maybe [J.CodeActionKind]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the API for this isn’t quite right (but that’s not new to this PR):
The LSP spec states

The CodeActionOptions return type is only valid if the client signals code action literal support via the property textDocument.codeAction.codeActionLiteralSupport.

However, the current API requires you to specify the options before you can inspect the capabilities so you can’t actually specify this properly.

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 catch. I think we can just return CodeActionOptionsStatic True in the case when the client capabilities do not declare support for code action literals, and pass on the code action options in the case that they do

(map singleton <$> completionAllCommitCharacters o)
| otherwise = Nothing

codeActionProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks ghcide in a way that I don’t know how to fix. We currently set this to CodeActionOptionsStatic True and as mentioned above, I can’t set the individual flags properly since I learn the capabilities after I need to specify the options. Maybe for now, we could use something like

isJust $ codeActionHandler h = maybe (J.CodeActionOptionsStatic True) (CodeActionOptions . Just) (codeActionKinds o)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That sounds reasonable. I left it this way as it is possible to return a CodeActionOptions with a null CodeActionKinds inside it (which doesn't make much sense given the previous comment), so I'm happy enough to default to the static capability if the kinds in the LSP options are set to Nothing

Also fix some providers being errenously set
@lukel97 lukel97 requested a review from cocreature November 1, 2019 19:48
Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@lukel97 lukel97 merged commit e0c0c0f into master Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make sure all capabilites are determined from handlers

4 participants