Skip to content

Commit

Permalink
Treat undefined and null initialization options the same way (#605)
Browse files Browse the repository at this point in the history
* Overhaul Nix configuration

- allow usage of Nix Flakes
- remove `niv` code (may be a controversial change)
- redirect `nix-shell` to `flake.nix`

* Fix minor typo in LSP configuration note

* Treat `undefined` and `null` initialization options the same way

Treat non-existing "initializationOptions", and `"initializationOptions": null`
the same way.

Fixes #604
  • Loading branch information
dschrempf authored Feb 19, 2025
1 parent b0bc553 commit bd0217c
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ hie
hie.yaml
.envrc
**/.golden/*/actual
/.direnv/
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).defaultNix
76 changes: 76 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "Haskell development environment";

inputs.flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

inputs.flake-utils.url = "github:numtide/flake-utils";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs =
{
flake-utils,
nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
hpkgs = pkgs.haskellPackages;
in
{
devShells.default = pkgs.mkShell {
packages = [
# Haskell toolchain.
hpkgs.cabal-fmt
hpkgs.cabal-install
hpkgs.fourmolu
hpkgs.ghc
hpkgs.haskell-language-server

# Misc.
pkgs.zlib
pkgs.pkg-config
];
};
}
);
}
14 changes: 7 additions & 7 deletions lsp/src/Language/LSP/Server/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,13 @@ not have to support `workspace/configuration`! In practice,
many clients seem to follow the sensible approach laid out here:
https://github.com/microsoft/language-server-protocol/issues/972#issuecomment-626668243
To make this work, we try to be tolerant by using the following strategy.
When we receive a configuration object from any of the sources above, we first
check to see if it has a field corresponding to our configuration section. If it
does, then we assume that it our config and try to parse it. If it does not, we
try to parse the entire config object. This hopefully lets us handle a variety
of sensible cases where the client sends us mostly our config, either wrapped
in our section or not.
To make this work, we try to be tolerant by using the following strategy. When
we receive a configuration object from any of the sources above, we first check
to see if it has a field corresponding to our configuration section. If it does,
then we assume that it is our config and try to parse it. If it does not parse,
we try to parse the entire config object. This hopefully lets us handle a
variety of sensible cases where the client sends us mostly our config, either
wrapped in our section or not.
-}

{- Note [Client- versus server-initiated progress]
Expand Down
5 changes: 4 additions & 1 deletion lsp/src/Language/LSP/Server/Processing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Data.Aeson hiding (
Null,
Options,
)
import Data.Aeson qualified as J
import Data.Aeson.Lens ()
import Data.Aeson.Types hiding (
Error,
Expand Down Expand Up @@ -145,6 +146,9 @@ initializeRequestHandler logger ServerDefinition{..} vfs sendFunc req = do
configObject = lookForConfigSection configSection <$> (p ^. L.initializationOptions)

initialConfig <- case configObject of
-- Treat non-existing "initializationOptions" and `"initializationOptions": null` the same way.
Nothing -> pure defaultConfig
Just J.Null -> pure defaultConfig
Just o -> case parseConfig defaultConfig o of
Right newConfig -> do
liftIO $ logger <& LspCore (NewConfig o) `WithSeverity` Debug
Expand All @@ -153,7 +157,6 @@ initializeRequestHandler logger ServerDefinition{..} vfs sendFunc req = do
-- Warn not error here, since initializationOptions is pretty unspecified
liftIO $ logger <& LspCore (ConfigurationParseError o err) `WithSeverity` Warning
pure defaultConfig
Nothing -> pure defaultConfig

stateVars <- liftIO $ do
resVFS <- newTVarIO (VFSData vfs mempty)
Expand Down
3 changes: 0 additions & 3 deletions nix/default.nix

This file was deleted.

38 changes: 0 additions & 38 deletions nix/sources.json

This file was deleted.

Loading

0 comments on commit bd0217c

Please sign in to comment.