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

feat: Add support for LSP 2 #2560

Merged
merged 3 commits into from
Dec 25, 2023
Merged

feat: Add support for LSP 2 #2560

merged 3 commits into from
Dec 25, 2023

Conversation

Vekhir
Copy link
Contributor

@Vekhir Vekhir commented Dec 23, 2023

@mmhat
Building upon #2531, this further adds support for

  • lsp 2.1
  • lsp-types 2.0
  • lsp-test 0.16

This is a minimum refactoring by essentially following the compile errors and fixing them one by one without major structural changes. Most changes are just renaming.

No thoughts were given to backwards compatibility within LSP - the above versions are also the minimum requirement for dhall-lsp-server.
This is consistent with GHC 9.6.

Note

I had this diff lying around for a few days and it has been verified in my build for updating Arch packages to GHC 9.6.

Supersedes #2428

@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 24, 2023

@mmhat Rather obvious in hindsight, I've now updated the stack configuration to use the newer lsp libraries.
Not sure what to do about the hydra/nix issue.

@mmhat
Copy link
Collaborator

mmhat commented Dec 24, 2023

@Vekhir Thank you for doing this! I am about to review the work you did so far. Regarding the Hydra issue:
I am an ArchLinux user as well, so I faced the same problems while working on #2531 . I used the following to update packages in the Nix setup:

# We assume that the current directory is the root of the checked out work tree.
# Start a container with the work tree mounted under /work.
# (I use podman nowadays; docker should work as well.)
podman run -it --rm -v .:/work -w /work docker.io/nixos/nix
# Now we are in the container. We need to install cabal-install and cabal2nix:
nix-env -i cabal-install -i cabal2nix
# cabal2nix needs a hackage index tarball:
cabal update
# Now we generate the Nix expression for the lsp-2.1.0.0 package and store it in the right location:
cabal2nix cabal://lsp-2.1.0.0 > ./nix/packages/lsp.nix

Copy link
Collaborator

@mmhat mmhat left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -132,7 +133,7 @@ rangeToJSON (Range (x1,y1) (x2,y2)) =

hoverHandler :: Handlers HandlerM
hoverHandler =
LSP.requestHandler STextDocumentHover \request respond -> handleErrorWithDefault respond Nothing do
LSP.requestHandler SMethod_TextDocumentHover \request respond -> handleErrorWithDefault respond (maybeToNull Nothing) do
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
LSP.requestHandler SMethod_TextDocumentHover \request respond -> handleErrorWithDefault respond (maybeToNull Nothing) do
LSP.requestHandler SMethod_TextDocumentHover \request respond -> handleErrorWithDefault respond (InR Null) do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just saying Null here leads to ambiguity about Aeson.Null vs LSP.Types.Null, but otherwise is fine.

@@ -211,23 +212,23 @@ documentLinkHandler =
filePath <- localToPath prefix file
let filePath' = basePath </> filePath -- absolute file path
let _range = rangeToJSON range_
let _target = Just (filePathToUri filePath')
let _target = Just (Text.pack filePath')
Copy link
Collaborator

Choose a reason for hiding this comment

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

It appears to me that filePathToUri does a bit more than converting the FilePath to Text.
Maybe

Suggested change
let _target = Just (Text.pack filePath')
let _target = Just (getUri (filePathToUri filePath'))

is a bit more sensible here.

dhall-lsp-server/src/Dhall/LSP/Server.hs Show resolved Hide resolved
@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 24, 2023

@mmhat I've implemented your suggestions and fixed the CI build - it will hopefully pass now.

@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 24, 2023

Hydra now works, lets see if the rest works now too

@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 25, 2023

This check will most probably fail for GHC 8.10 since hashable 1.3.5.0 needs ghc-bignum, but I want to see the error message.
If stack provides a compatible version for ghc-bignum, then we are likely done.

lsp 2.x needs 'row-types'
@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 25, 2023

Failed due to typo... Fixed it now

@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 25, 2023

@mmhat Looks like we are done. If you don't have any objections, you can merge it.
Is there something you want/need done to make a Hackage release? Would make Arch integration easier.

@mmhat
Copy link
Collaborator

mmhat commented Dec 25, 2023

@Vekhir Can you please rebase your changes onto main?

Regarding a new release: Those are done by @Gabriella439 , so I think we have to be a bit more patient.

EDIT: Never mind, Github managed to merge it but the UI didn't show.

@mmhat mmhat merged commit 2000127 into dhall-lang:main Dec 25, 2023
6 checks passed
@mmhat
Copy link
Collaborator

mmhat commented Dec 25, 2023

@Vekhir Nice, excellent work! Thank you!

@Vekhir Vekhir deleted the support-lsp2 branch December 25, 2023 20:48
@Vekhir
Copy link
Contributor Author

Vekhir commented Dec 25, 2023

It's not urgent anyway. Thanks for your suggestions and reviewing!

rvl pushed a commit to rvl/dhall-haskell that referenced this pull request Feb 23, 2024
* feat: Add support for LSP 2

* fix: Update CI lsp versions

lsp 2.x needs 'row-types'

---------

Co-authored-by: Mann mit Hut <[email protected]>
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.

2 participants