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

Update version while editing to conform lsp spec #3566

Closed
wants to merge 7 commits into from

Conversation

July541
Copy link
Collaborator

@July541 July541 commented Apr 19, 2023

Fix #3547 and #3498.

Tests is broken due to lsp-test's limitation.

@July541 July541 marked this pull request as ready for review April 22, 2023 10:28
@July541 July541 requested a review from isovector as a code owner April 22, 2023 13:14
@michaelpj
Copy link
Collaborator

I confess I'm very hazy about how file versions are supposed to work at all, and the LSP spec doesn't really tell you. But shouldn't there be somewhere in the code where you bump the version?

@July541
Copy link
Collaborator Author

July541 commented Apr 22, 2023

I confess I'm very hazy about how file versions are supposed to work at all, and the LSP spec doesn't really tell you. But shouldn't there be somewhere in the code where you bump the version?

I've consulted with the client developer, see details here helix-editor/helix#6543 (comment)

@michaelpj
Copy link
Collaborator

Okay, sounds good. Maybe we should write something about how to use it? Or audit the other uses now you know what we should be doing?

@July541
Copy link
Collaborator Author

July541 commented Apr 23, 2023

I think we can add version checking in lsp-test for every editing after haskell/lsp#474 addressed.

@July541
Copy link
Collaborator Author

July541 commented Apr 23, 2023

Ideally, I want we can track version info in the plugin descriptor, then we can remove some parameters passing, but it's not easy.

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Okay, I think I'm convinced that this is the right thing to do. It would be nice to write down the logic somewhere, I'm not sure where. Alternatively, if we go the route of passing the VTDI everywhere instead of reconstructing it, we could add a hlint rule that warns if people use the constructor?

@@ -161,16 +161,16 @@ diffTextEdit fText f2Text withDeletions = J.List r


-- | A pure version of 'diffText' for testing
diffText' :: Bool -> (Uri,T.Text) -> T.Text -> WithDeletions -> WorkspaceEdit
diffText' supports (f,fText) f2Text withDeletions =
diffText' :: Bool -> (Uri,T.Text) -> T.Text -> WithDeletions -> TextDocumentVersion -> WorkspaceEdit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
diffText' :: Bool -> (Uri,T.Text) -> T.Text -> WithDeletions -> TextDocumentVersion -> WorkspaceEdit
diffText' :: Bool -> (VersionedTextDocmentIdentifier, T.Text) -> T.Text -> WithDeletions -> TextDocumentVersion -> WorkspaceEdit

what about something like this? Since really the idea is that we want to use the same identifier as the one we were given - at the moment we're taking the parts and then putting it back together, we could just take the identifier.

@@ -38,6 +38,7 @@ data AddMinimalMethodsParams = AddMinimalMethodsParams
, methodGroup :: List (T.Text, T.Text)
-- ^ (name text, signature text)
, withSig :: Bool
, textVersion :: TextDocumentVersion
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly, replace the uri field with a VerisonedTextDocumentIdentifier

@@ -451,8 +455,8 @@ codeActionProvider ideState pluginId (CodeActionParams _ _ documentId _ context)

-- | Convert a hlint diagnostic into an apply and an ignore code action
-- if applicable
diagnosticToCodeActions :: DynFlags -> T.Text -> PluginId -> TextDocumentIdentifier -> LSP.Diagnostic -> [LSP.CodeAction]
diagnosticToCodeActions dynFlags fileContents pluginId documentId diagnostic
diagnosticToCodeActions :: DynFlags -> T.Text -> PluginId -> TextDocumentIdentifier -> TextDocumentVersion -> LSP.Diagnostic -> [LSP.CodeAction]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
diagnosticToCodeActions :: DynFlags -> T.Text -> PluginId -> TextDocumentIdentifier -> TextDocumentVersion -> LSP.Diagnostic -> [LSP.CodeAction]
diagnosticToCodeActions :: DynFlags -> T.Text -> PluginId -> VersionedTextDocumentIdentifier -> LSP.Diagnostic -> [LSP.CodeAction]

@@ -511,13 +515,13 @@ mkSuppressHintTextEdits dynFlags fileContents hint =
combinedTextEdit : lineSplitTextEditList
-- ---------------------------------------------------------------------

applyAllCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState Uri
applyAllCmd recorder ide uri = do
applyAllCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState (Uri, TextDocumentVersion)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
applyAllCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState (Uri, TextDocumentVersion)
applyAllCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState VersionedTextDocumentIdentifier

-- | There can be more than one hint suggested at the same position, so HintTitle is used to distinguish between them.
, hintTitle :: HintTitle
, hintTitle :: HintTitle
, textVersion :: TextDocumentVersion
Copy link
Collaborator

Choose a reason for hiding this comment

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

etc.

logWith recorder Debug $ LogApplying file res
case res of
Left err -> pure $ Left (responseError (T.pack $ "hlint:applyOne: " ++ show err))
Right fs -> do
_ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing fs) (\_ -> pure ())
pure $ Right Null

applyHint :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> IO (Either String WorkspaceEdit)
applyHint recorder ide nfp mhint =
applyHint :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> TextDocumentVersion -> IO (Either String WorkspaceEdit)
Copy link
Collaborator

Choose a reason for hiding this comment

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

bit akward her because we've got a NFP here, but maybe we could get away with passing the VTDI instead?

@maralorn
Copy link
Contributor

I can report that the PR in this form fixes code actions in helix for me.

@July541 Just so you know, I am trying to work on this here at zurihac. Will report back once I have made progress.

@maralorn
Copy link
Contributor

Thank you, @July541 for doing most of the work on this. With #3643 brought over the finish line, this PR can be closed.

Copy link
Collaborator

@konn konn left a comment

Choose a reason for hiding this comment

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

LGTM foSplice Plugin 👍

@michaelpj michaelpj closed this Jun 12, 2023
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.

Some LSP Code actions (Hints) are not applied.
4 participants