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

Use haskell-lsp for lsp types #696

Closed
wants to merge 29 commits into from
Closed

Use haskell-lsp for lsp types #696

wants to merge 29 commits into from

Conversation

DavidM-D
Copy link
Contributor

First step to pulling out our custom LSP implementation

Pull Request Checklist

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

@DavidM-D DavidM-D requested a review from neil-da April 25, 2019 13:02
WORKSPACE Outdated Show resolved Hide resolved
@@ -413,13 +417,18 @@ hazel_repositories(
hazel_hackage("shake", "0.17.8", "ade4162f7540f044f0446981120800076712d1f98d30c5b5344c0f7828ec49a2") +
hazel_hackage("filepattern", "0.1.1", "f7fc5bdcfef0d43a793a3c64e7c0fd3b1d35eea97a37f0e69d6612ab255c9b4b") +
hazel_hackage("terminal-progress-bar", "0.4.0.1", "c5a9720fcbcd9d83f9551e431ee3975c61d7da6432aa687aef0c0e04e59ae277") +
hazel_hackage("rope-utf16-splay" , "0.2.0.0", "83d1961bf55355da49a6b55d6f58d02483eff1f8e6df53f4dccdab1ac49e101d") +
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ticket to add this to stackage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, on that now

@@ -17,6 +17,7 @@ import Development.IDE.Functions.Compile (TcModuleResult,
import qualified Development.IDE.Functions.Compile as Compile
import Development.IDE.Functions.FindImports (Import(..))
import Development.IDE.Functions.DependencyInformation
import Development.IDE.State.Shake
Copy link
Contributor

Choose a reason for hiding this comment

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

Why move this import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I have moved it

@@ -36,44 +36,44 @@ import Development.IDE.Types.SpanInfo
-- Foo* means Foo for me and Foo+

-- | Kick off things
type instance RuleResult OfInterest = IdeResult ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why rename IdeResult?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't, IdeResult is what you produce from the rules and IdeReturn is what you get back when you return a rule. Better name suggestions would be welcome

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!

WORKSPACE Outdated
pkgs = packages,
) +
# This is a special version of Haskell LSP without GPL dependencies
[ ("haskell-lsp", {"url": "https://github.com/DavidM-D/haskell-lsp/archive/{}.zip".format(HASKELL_LSP_COMMIT), "sha256": "7d706fbc1beb49a9345083d3eadb5e311936a2a8449e7765a65aa7d298dff9d6", "stripPrefix": "haskell-lsp-{}".format(HASKELL_LSP_COMMIT)})
Copy link
Contributor

Choose a reason for hiding this comment

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

What needs to happen for us to switch to upstream apart from haskell/lsp#70 being merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR needs to be resolved haskell/lsp#70, there's some LSP discussion going on, perhaps it could be resolved by the release of ropey, but our patches are pretty tiny at the moment. I think I'm also going to try and upstream our instances to make the diff even smaller

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we fork this to the digital-asset namespace please, and use it from there.

@@ -74,18 +76,19 @@ srcSpanToFilename (UnhelpfulSpan fs) = FS.unpackFS fs
srcSpanToFilename (RealSrcSpan real) = FS.unpackFS $ srcSpanFile real

srcSpanToLocation :: SrcSpan -> Location
srcSpanToLocation src = Location (srcSpanToFilename src) (srcSpanToRange src)
srcSpanToLocation src =
Location (LSP.filePathToUri $ srcSpanToFilename src) (srcSpanToRange src)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should hopefully fix URIs on Windows 👍

@@ -134,8 +133,10 @@ instance Hashable Key where
-- not propagate diagnostic errors through multiple phases.
type IdeResult v = ([Diagnostic], Maybe v)

type IdeReturn v = Maybe v
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a pretty confusing type synonym, especially given the fact that we already have IdeResult. I would just inline this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is something that you'd reasonably want to change at a later date and it's all over the place

Copy link
Contributor

Choose a reason for hiding this comment

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

Tat would be true if we hadn't just introduced IdeReturn but reused IdeResult. Since we are changing it everywhere, might as well change it to the end result.

LSP.Diagnostic
addLocation loc d =
d {
LSP._relatedInformation =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LSP._relatedInformation =
LSP._relatedInformation = Just $ LSP.List (rel loc : maybe [] toList (_relatedInformation d))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented

Copy link
Contributor

@neil-da neil-da left a comment

Choose a reason for hiding this comment

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

There seems to be a moving of invariants and types around IdeResult vs IdeReturn, so what was once encoded as ([Diagnostic], Maybe a) now gets moved to Maybe a through the type alias. Is that a necessary change? Or an unrelated change?

@@ -134,8 +133,10 @@ instance Hashable Key where
-- not propagate diagnostic errors through multiple phases.
type IdeResult v = ([Diagnostic], Maybe v)

type IdeReturn v = Maybe v
Copy link
Contributor

Choose a reason for hiding this comment

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

Tat would be true if we hadn't just introduced IdeReturn but reused IdeResult. Since we are changing it everywhere, might as well change it to the end result.

Map.lookup (filePathToUri fp)

-- | These functions live in the test framework rather that further down the stack because
-- you really should be deconstructing LSP diagnostic stores in this manner bar when testing
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't?

-- | These functions live in the test framework rather that further down the stack because
-- you really should be deconstructing LSP diagnostic stores in this manner bar when testing
fromStore :: D.StoreItem -> [D.Diagnostic]
fromStore (D.StoreItem _ ds) = join $ map toList $ Map.elems ds
Copy link
Contributor

Choose a reason for hiding this comment

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

concatMap?

fromStore (D.StoreItem _ ds) = join $ map toList $ Map.elems ds

allDiagnostics :: D.DiagnosticStore -> [D.Diagnostic]
allDiagnostics = join . map fromStore . Map.elems
Copy link
Contributor

Choose a reason for hiding this comment

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

concatMap?

@DavidM-D
Copy link
Contributor Author

There seems to be a moving of invariants and types around IdeResult vs IdeReturn, so what was once encoded as ([Diagnostic], Maybe a) now gets moved to Maybe a through the type alias. Is that a necessary change? Or an unrelated change?

It's (somewhat) necessary. We no longer store errors in the shake graph, we now store them the haskell-lsp data structure. I was going to write some code to handle this, but I realised that we weren't actually using the error return values, so I got rid of them.

@neil-da
Copy link
Contributor

neil-da commented Apr 25, 2019

That makes sense, but it feels like we're in an odd middle ground. Before IdeResult captured and abstracted over two levels of type constructor - now it abstracts over one, and is more complex than what it abstracts. I'd suggest:

Ditch IdeResult in all the type functions, e.g. type instance RuleResult GetModificationTime = UTCTime and then shove the Maybe in where you need it. I think this is probably a simplification over what you have now. It's possible we should have done this as a preparatory patch anyway.

hasSeriousErrors (List a) = any ((/=) uri . _uri . _location) a
uri = LSP.filePathToUri fp

addDiagnostics ::
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the semantics of this function? How does it remove old diagnostics that are no longer required? What if the Parser had a warning, and then that warning goes away - what's the flow?

@neil-da neil-da mentioned this pull request Apr 25, 2019
@neil-da
Copy link
Contributor

neil-da commented Apr 25, 2019

I sliced off a chunk of this commit and simplified it in #708

@DavidM-D DavidM-D closed this Apr 27, 2019
@dasormeter dasormeter deleted the new-lsp branch September 4, 2019 17:39
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.

3 participants