Skip to content

Commit bd0217c

Browse files
authored
Treat undefined and null initialization options the same way (#605)
* 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
1 parent b0bc553 commit bd0217c

File tree

10 files changed

+151
-262
lines changed

10 files changed

+151
-262
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ hie
2121
hie.yaml
2222
.envrc
2323
**/.golden/*/actual
24+
/.direnv/

default.nix

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).defaultNix

flake.lock

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
description = "Haskell development environment";
3+
4+
inputs.flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
5+
6+
inputs.flake-utils.url = "github:numtide/flake-utils";
7+
8+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
9+
10+
outputs =
11+
{
12+
flake-utils,
13+
nixpkgs,
14+
...
15+
}:
16+
flake-utils.lib.eachDefaultSystem (
17+
system:
18+
let
19+
pkgs = nixpkgs.legacyPackages.${system};
20+
hpkgs = pkgs.haskellPackages;
21+
in
22+
{
23+
devShells.default = pkgs.mkShell {
24+
packages = [
25+
# Haskell toolchain.
26+
hpkgs.cabal-fmt
27+
hpkgs.cabal-install
28+
hpkgs.fourmolu
29+
hpkgs.ghc
30+
hpkgs.haskell-language-server
31+
32+
# Misc.
33+
pkgs.zlib
34+
pkgs.pkg-config
35+
];
36+
};
37+
}
38+
);
39+
}

lsp/src/Language/LSP/Server/Core.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,13 @@ not have to support `workspace/configuration`! In practice,
775775
many clients seem to follow the sensible approach laid out here:
776776
https://github.com/microsoft/language-server-protocol/issues/972#issuecomment-626668243
777777
778-
To make this work, we try to be tolerant by using the following strategy.
779-
When we receive a configuration object from any of the sources above, we first
780-
check to see if it has a field corresponding to our configuration section. If it
781-
does, then we assume that it our config and try to parse it. If it does not, we
782-
try to parse the entire config object. This hopefully lets us handle a variety
783-
of sensible cases where the client sends us mostly our config, either wrapped
784-
in our section or not.
778+
To make this work, we try to be tolerant by using the following strategy. When
779+
we receive a configuration object from any of the sources above, we first check
780+
to see if it has a field corresponding to our configuration section. If it does,
781+
then we assume that it is our config and try to parse it. If it does not parse,
782+
we try to parse the entire config object. This hopefully lets us handle a
783+
variety of sensible cases where the client sends us mostly our config, either
784+
wrapped in our section or not.
785785
-}
786786

787787
{- Note [Client- versus server-initiated progress]

lsp/src/Language/LSP/Server/Processing.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Data.Aeson hiding (
3333
Null,
3434
Options,
3535
)
36+
import Data.Aeson qualified as J
3637
import Data.Aeson.Lens ()
3738
import Data.Aeson.Types hiding (
3839
Error,
@@ -145,6 +146,9 @@ initializeRequestHandler logger ServerDefinition{..} vfs sendFunc req = do
145146
configObject = lookForConfigSection configSection <$> (p ^. L.initializationOptions)
146147

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

158161
stateVars <- liftIO $ do
159162
resVFS <- newTVarIO (VFSData vfs mempty)

nix/default.nix

-3
This file was deleted.

nix/sources.json

-38
This file was deleted.

0 commit comments

Comments
 (0)