Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

ghc-mod code actions #659

Merged
merged 36 commits into from
Jul 15, 2018
Merged

ghc-mod code actions #659

merged 36 commits into from
Jul 15, 2018

Conversation

lukel97
Copy link
Collaborator

@lukel97 lukel97 commented Jun 26, 2018

This does some rudimentary string manipulation to read the warnings given out by ghc-mod, and provide contextual code actions for them. In the future we should probably add API in ghc-mod to directly give us the information to create these code actions.

So far it adds these types of code actions:

  • Renaming code actions for when something is misspelt (Perhaps you meant?)
  • Importing missing modules by searching up symbols in Hoogle with Hsimport (based off of Add an Import identifier command vscode-haskell#83)
  • Add missing dependencies to .cabal and package.yaml files (also based off of Add an Import identifier command vscode-haskell#83 !)
    • Works out and adds the dependency to the targets/components containing the file that the quick fix was applied on
  • Removing redundant imports or replacing it with an import for just instances

It also adds support for the new code action types in LSP v3.8, so you can use quick fix and refactor keybindings and such inside VS Code.

Todo

  • Add package.yaml support
  • Add more code actions
  • Add functional tests for all of this
  • Possibly look at moving the makeRequest functions inside the reactor into functions in the R monad

Also

This moves out the code action code (the logic that glues LSP and the various Haskell tools) into a separate module since it was getting pretty big, so some reactor types have also been moved out.

It also introduces Cabal as a dependency to mechanically edit the .cabal file, and I'm not sure how much this affects build time.
Its used to work out which library/executable should have the dependencies added to based on the module that the quick fix is being applied on.

@lukel97 lukel97 force-pushed the import-code-actions branch from c251361 to e3dddc0 Compare July 1, 2018 16:30
@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 1, 2018

@lukel97 lukel97 changed the title [WIP] ghc-mod code actions ghc-mod code actions Jul 1, 2018
@lukel97 lukel97 requested a review from alanz July 1, 2018 16:40
Fix new code action kinds returning a duplicate command on top of workspace edits
@lukel97 lukel97 force-pushed the import-code-actions branch from ed97d0a to 32ec0df Compare July 4, 2018 11:38
@lukel97 lukel97 requested a review from wz1000 July 11, 2018 12:46
deriving Eq

-- | Generate a 'WorkspaceEdit' value from an original file and text to replace it.
makeDiffResult :: FilePath -> T.Text -> (FilePath -> FilePath) -> IdeM WorkspaceEdit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this functionality move to haskell-lsp, some time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably, I imagine this would be useful for both clients and servers.

I'm also thinking we should probably also pass back the lsp funcs/lsp config back to haskell-lsp, so it can handle formatting the workspace edit according to the specification.

flip runReaderT caps $
ideDispatcher env errorHandler callbackHandler ideChan

-- TODO: Causes STM deadlock?
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is going on here with this comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to get the ideDispatcher thread to throw its exceptions onto the main thread instead of dying silently, but it caused other exceptions due to me not doing the async properly. We should probably revisit this some time. I can remove the comment and create a todo for this?

addDep _ = error "Not an array in addDep"


-- | Takes a cabal file and a path to a module in the dependency you want to edit.
Copy link
Collaborator

Choose a reason for hiding this comment

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

And it will lose comments and formatting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With cabal files it shouldn't. The printed cabal module after editing doesn't contain any formatting, but it tries to only apply the additions in the diff.
For package.yaml I couldn't get makeDiffResult to work with it, so it loses formatting. Interestingly enough there's another GSOC project for format preserving yaml editing: https://github.com/wisn/format-preserving-yaml/

@alanz alanz merged commit f9b5d64 into haskell:master Jul 15, 2018
@alanz alanz added this to the prehistory milestone Feb 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants