Skip to content

Treat undefined and null initialization options the same way #605

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

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading