11{-# LANGUAGE RankNTypes #-}
22{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
3+ {-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
34
45module Spec.Tests.Cpp (tests ) where
56
67import Data.String.Interpolate
78import Data.Text
9+ import Language.LSP.Protocol.Types
810import Test.Sandwich as Sandwich
911import TestLib.JupyterRunnerContext
12+ import TestLib.LSP
1013import TestLib.NixEnvironmentContext
1114import TestLib.NixTypes
1215import TestLib.TestSearchers
@@ -26,24 +29,47 @@ tests = describe "C++" $ parallel $ do
2629 tests' " c++23"
2730 tests' " c++2c"
2831
32+ testsWithLsp " c++23"
33+
2934tests' :: Text -> LanguageSpec
3035tests' flavor = describe [i |C++ (#{flavor})|] $ introduceNixEnvironment [kernelSpec flavor] [] " C++" $ introduceJupyterRunner $ do
3136 testKernelStdout " cpp" [__i |\#include <iostream>
3237 using namespace std;
3338 cout << "hi" << endl;|] " hi\n "
3439
40+ testsWithLsp :: Text -> LanguageSpec
41+ testsWithLsp flavor = describe [i |C++ (#{flavor}) with LSP|] $ introduceNixEnvironment [kernelSpecWithLsp flavor] [] " C++" $ do
42+ describe " LSP" $ do
43+ testDiagnostics'' " simple" lsName " test.cpp" (Just " cpp" )
44+ [__i |int main() {
45+ undefined_function();
46+ return 0;
47+ }|] [] $ \ diags -> do
48+ info [i |Got diags: #{diags}|]
49+ info [i |Got ranges: #{getDiagnosticRanges' diags}|]
50+ getDiagnosticRanges' diags `shouldBe` [(Range (Position 1 2 ) (Position 1 20 ), Just (InR " undeclared_var_use" ), " Use of undeclared identifier 'undefined_function'" )]
51+
52+ lsName :: Text
53+ lsName = " clangd"
3554
3655kernelSpec :: Text -> NixKernelSpec
37- kernelSpec flavor = NixKernelSpec {
56+ kernelSpec flavor = kernelSpec' [[i |flavor = "#{flavor}"|]]
57+
58+ kernelSpecWithLsp :: Text -> NixKernelSpec
59+ kernelSpecWithLsp flavor = kernelSpec' [
60+ [i |flavor = "#{flavor}"|]
61+ , " lsp.clangd.enable = true"
62+ ]
63+
64+ kernelSpec' :: [Text ] -> NixKernelSpec
65+ kernelSpec' extraConfig = NixKernelSpec {
3866 nixKernelName = " cpp"
3967 , nixKernelChannel = " codedown"
4068 , nixKernelDisplayName = Just " CPP"
4169 , nixKernelPackages = []
4270 , nixKernelMeta = Nothing
4371 , nixKernelIcon = Nothing
44- , nixKernelExtraConfig = Just [
45- [i |flavor = "#{flavor}"|]
46- ]
72+ , nixKernelExtraConfig = Just extraConfig
4773 }
4874
4975main :: IO ()
0 commit comments