Skip to content

Commit 4aa933d

Browse files
authored
Merge branch 'master' into note-references
2 parents 9842702 + 20b9c23 commit 4aa933d

File tree

15 files changed

+425
-25
lines changed

15 files changed

+425
-25
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ packages:
88
./hls-test-utils
99

1010

11-
index-state: 2025-05-12T13:26:29Z
11+
index-state: 2025-06-07T14:57:40Z
1212

1313
tests: True
1414
test-show-details: direct

ghcide-test/exe/Main.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module Main (main) where
3333
import qualified HieDbRetry
3434
import Test.Tasty
3535
import Test.Tasty.Ingredients.Rerun
36-
import Test.Tasty.Runners
3736

3837
import AsyncTests
3938
import BootTests
@@ -71,7 +70,7 @@ import WatchedFileTests
7170
main :: IO ()
7271
main = do
7372
-- We mess with env vars so run single-threaded.
74-
defaultMainWithRerun $ PlusTestOptions mkSequential $ testGroup "ghcide"
73+
defaultMainWithRerun $ testGroup "ghcide"
7574
[ OpenCloseTest.tests
7675
, InitializeResponseTests.tests
7776
, CompletionTests.tests
@@ -105,6 +104,3 @@ main = do
105104
, HieDbRetry.tests
106105
, ExceptionTests.tests
107106
]
108-
where
109-
PlusTestOptions mkSequential _ =sequentialTestGroup "foo" AllFinish []
110-

ghcide/src/Development/IDE/Types/Diagnostics.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,19 @@ ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
102102
fdLspDiagnostic =
103103
lspDiag
104104
& attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
105-
& setGhcCode mbOrigMsg
105+
& attachDiagnosticCode ((diagnosticCode . errMsgDiagnostic) =<< mbOrigMsg)
106106
in
107107
FileDiagnostic {..}
108108

109-
-- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code which is linked
109+
-- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code, and include the link
110110
-- to https://errors.haskell.org/.
111-
setGhcCode :: Maybe (MsgEnvelope GhcMessage) -> LSP.Diagnostic -> LSP.Diagnostic
112-
setGhcCode mbOrigMsg diag =
113-
let mbGhcCode = do
114-
origMsg <- mbOrigMsg
115-
code <- diagnosticCode (errMsgDiagnostic origMsg)
116-
pure (InR (showGhcCode code))
117-
in
118-
diag { _code = mbGhcCode <|> _code diag }
111+
attachDiagnosticCode :: Maybe DiagnosticCode -> LSP.Diagnostic -> LSP.Diagnostic
112+
attachDiagnosticCode Nothing diag = diag
113+
attachDiagnosticCode (Just code) diag =
114+
let
115+
textualCode = showGhcCode code
116+
codeDesc = LSP.CodeDescription{ _href = Uri $ "https://errors.haskell.org/messages/" <> textualCode }
117+
in diag { _code = Just (InR textualCode), _codeDescription = Just codeDesc}
119118

120119
#if MIN_VERSION_ghc(9,9,0)
121120
-- DiagnosticCode only got a show instance in 9.10.1

haskell-language-server.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ library hls-stan-plugin
806806
, lsp-types
807807
, text
808808
, unordered-containers
809-
, stan >= 0.1.2.0
809+
, stan >= 0.2.1.0
810810
, trial
811811
, directory
812812

@@ -2115,7 +2115,7 @@ test-suite ghcide-tests
21152115
, sqlite-simple
21162116
, stm
21172117
, stm-containers
2118-
, tasty >=1.5
2118+
, tasty
21192119
, tasty-expected-failure
21202120
, tasty-hunit >=0.10
21212121
, tasty-quickcheck

hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
module Ide.Plugin.ConfigUtils (
77
pluginsToDefaultConfig,
8-
pluginsToVSCodeExtensionSchema
8+
pluginsToVSCodeExtensionSchema,
9+
pluginsCustomConfigToMarkdownTables
910
) where
1011

1112
import Control.Lens (at, (&), (?~))
@@ -18,8 +19,15 @@ import qualified Data.Dependent.Sum as DSum
1819
import Data.List.Extra (nubOrd)
1920
import Data.String (IsString (fromString))
2021
import qualified Data.Text as T
22+
import GHC.TypeLits (symbolVal)
2123
import Ide.Plugin.Config
22-
import Ide.Plugin.Properties (toDefaultJSON,
24+
import Ide.Plugin.Properties (KeyNameProxy, MetaData (..),
25+
PluginCustomConfig (..),
26+
PluginCustomConfigParam (..),
27+
Properties (..),
28+
SPropertyKey (..),
29+
SomePropertyKeyWithMetaData (..),
30+
toDefaultJSON,
2331
toVSCodeExtensionSchema)
2432
import Ide.Types
2533
import Language.LSP.Protocol.Message
@@ -143,3 +151,92 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
143151
]
144152
withIdPrefix x = "haskell.plugin." <> pId <> "." <> x
145153
toKey' = fromString . T.unpack . withIdPrefix
154+
155+
156+
-- | Generates markdown tables for custom config
157+
pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T.Text
158+
pluginsCustomConfigToMarkdownTables IdePlugins {..} = T.unlines
159+
$ map renderCfg
160+
$ filter (\(PluginCustomConfig _ params) -> not $ null params)
161+
$ map toPluginCustomConfig ipMap
162+
where
163+
toPluginCustomConfig :: PluginDescriptor ideState -> PluginCustomConfig
164+
toPluginCustomConfig PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
165+
PluginCustomConfig { pcc'Name = pId, pcc'Params = toPluginCustomConfigParams c}
166+
toPluginCustomConfigParams :: CustomConfig -> [PluginCustomConfigParam]
167+
toPluginCustomConfigParams (CustomConfig p) = toPluginCustomConfigParams' p
168+
toPluginCustomConfigParams' :: Properties r -> [PluginCustomConfigParam]
169+
toPluginCustomConfigParams' EmptyProperties = []
170+
toPluginCustomConfigParams' (ConsProperties (keyNameProxy :: KeyNameProxy s) (k :: SPropertyKey k) (m :: MetaData t) xs) =
171+
toEntry (SomePropertyKeyWithMetaData k m) : toPluginCustomConfigParams' xs
172+
where
173+
toEntry :: SomePropertyKeyWithMetaData -> PluginCustomConfigParam
174+
toEntry (SomePropertyKeyWithMetaData SNumber MetaData {..}) =
175+
PluginCustomConfigParam {
176+
pccp'Name = T.pack $ symbolVal keyNameProxy,
177+
pccp'Description = description,
178+
pccp'Default = T.pack $ show defaultValue,
179+
pccp'EnumValues = []
180+
}
181+
toEntry (SomePropertyKeyWithMetaData SInteger MetaData {..}) =
182+
PluginCustomConfigParam {
183+
pccp'Name = T.pack $ symbolVal keyNameProxy,
184+
pccp'Description = description,
185+
pccp'Default = T.pack $ show defaultValue,
186+
pccp'EnumValues = []
187+
}
188+
toEntry (SomePropertyKeyWithMetaData SString MetaData {..}) =
189+
PluginCustomConfigParam {
190+
pccp'Name = T.pack $ symbolVal keyNameProxy,
191+
pccp'Description = description,
192+
pccp'Default = T.pack $ show defaultValue,
193+
pccp'EnumValues = []
194+
}
195+
toEntry (SomePropertyKeyWithMetaData SBoolean MetaData {..}) =
196+
PluginCustomConfigParam {
197+
pccp'Name = T.pack $ symbolVal keyNameProxy,
198+
pccp'Description = description,
199+
pccp'Default = T.pack $ show defaultValue,
200+
pccp'EnumValues = []
201+
}
202+
toEntry (SomePropertyKeyWithMetaData (SObject _) MetaData {..}) =
203+
PluginCustomConfigParam {
204+
pccp'Name = T.pack $ symbolVal keyNameProxy,
205+
pccp'Description = description,
206+
pccp'Default = "TODO: nested object", -- T.pack $ show defaultValue,
207+
pccp'EnumValues = []
208+
}
209+
toEntry (SomePropertyKeyWithMetaData (SArray _) MetaData {..}) =
210+
PluginCustomConfigParam {
211+
pccp'Name = T.pack $ symbolVal keyNameProxy,
212+
pccp'Description = description,
213+
pccp'Default = "TODO: Array values", -- T.pack $ show defaultValue,
214+
pccp'EnumValues = []
215+
}
216+
toEntry (SomePropertyKeyWithMetaData (SEnum _) EnumMetaData {..}) =
217+
PluginCustomConfigParam {
218+
pccp'Name = T.pack $ symbolVal keyNameProxy,
219+
pccp'Description = description,
220+
pccp'Default = T.pack $ show defaultValue,
221+
pccp'EnumValues = map (T.pack . show) enumValues
222+
}
223+
toEntry (SomePropertyKeyWithMetaData SProperties PropertiesMetaData {..}) =
224+
PluginCustomConfigParam {
225+
pccp'Name = T.pack $ symbolVal keyNameProxy,
226+
pccp'Description = description,
227+
pccp'Default = T.pack $ show defaultValue,
228+
pccp'EnumValues = []
229+
}
230+
renderCfg :: PluginCustomConfig -> T.Text
231+
renderCfg (PluginCustomConfig pId pccParams) =
232+
T.unlines (pluginHeader : tableHeader : rows pccParams)
233+
where
234+
pluginHeader = "## " <> pId
235+
tableHeader =
236+
"| Property | Description | Default | Allowed values |" <> "\n" <>
237+
"| --- | --- | --- | --- |"
238+
rows = map renderRow
239+
renderRow PluginCustomConfigParam {..} =
240+
"| `" <> pccp'Name <> "` | " <> pccp'Description <> " | `" <> pccp'Default <> "` | " <> renderEnum pccp'EnumValues <> " |"
241+
renderEnum [] = " &nbsp; " -- Placeholder to prevent missing cells
242+
renderEnum vs = "<ul> " <> (T.intercalate " " $ map (\x -> "<li><code>" <> x <> "</code></li>") vs) <> " </ul>"

hls-plugin-api/src/Ide/Plugin/Properties.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ module Ide.Plugin.Properties
2121
MetaData (..),
2222
PropertyKey (..),
2323
SPropertyKey (..),
24+
SomePropertyKeyWithMetaData (..),
2425
KeyNameProxy (..),
2526
KeyNamePath (..),
26-
Properties,
27+
Properties(..),
2728
HasProperty,
2829
HasPropertyByPath,
2930
emptyProperties,
@@ -42,6 +43,8 @@ module Ide.Plugin.Properties
4243
usePropertyByPathEither,
4344
usePropertyByPath,
4445
(&),
46+
PluginCustomConfig(..),
47+
PluginCustomConfigParam(..),
4548
)
4649
where
4750

@@ -516,3 +519,15 @@ toVSCodeExtensionSchema' ps = case ps of
516519
]
517520
(SomePropertyKeyWithMetaData SProperties PropertiesMetaData {..}) ->
518521
map (first Just) $ toVSCodeExtensionSchema' childrenProperties
522+
523+
data PluginCustomConfig = PluginCustomConfig {
524+
pcc'Name :: T.Text,
525+
pcc'Params :: [PluginCustomConfigParam]
526+
}
527+
data PluginCustomConfigParam = PluginCustomConfigParam {
528+
pccp'Name :: T.Text,
529+
pccp'Description :: T.Text,
530+
pccp'Default :: T.Text,
531+
pccp'EnumValues :: [T.Text]
532+
}
533+

src/Ide/Arguments.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ data Arguments
3333
| BiosMode BiosAction
3434
| Ghcide GhcideArguments
3535
| VSCodeExtensionSchemaMode
36+
| PluginsCustomConfigMarkdownReferenceMode
3637
| DefaultConfigurationMode
3738
| PrintLibDir
3839

@@ -69,6 +70,7 @@ getArguments exeName plugins = execParser opts
6970
<|> hsubparser
7071
( command "vscode-extension-schema" extensionSchemaCommand
7172
<> command "generate-default-config" generateDefaultConfigCommand
73+
<> command "plugins-custom-config-markdown-reference" pluginsCustomConfigMarkdownReferenceCommand
7274
)
7375
<|> listPluginsParser
7476
<|> BiosMode <$> biosParser
@@ -86,6 +88,9 @@ getArguments exeName plugins = execParser opts
8688
generateDefaultConfigCommand =
8789
info (pure DefaultConfigurationMode)
8890
(fullDesc <> progDesc "Print config supported by the server with default values")
91+
pluginsCustomConfigMarkdownReferenceCommand =
92+
info (pure PluginsCustomConfigMarkdownReferenceMode)
93+
(fullDesc <> progDesc "Print markdown reference for plugins custom config")
8994

9095
printVersionParser :: String -> Parser PrintVersion
9196
printVersionParser exeName =

src/Ide/Main.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Data.Function ((&))
1515
import Data.List (sortOn)
1616
import Data.Text (Text)
1717
import qualified Data.Text as T
18+
import qualified Data.Text.IO as T (putStrLn)
1819
import Data.Text.Lazy.Encoding (decodeUtf8)
1920
import qualified Data.Text.Lazy.IO as LT
2021
import Development.IDE.Core.Rules hiding (Log)
@@ -28,7 +29,8 @@ import HIE.Bios.Types hiding (Log)
2829
import qualified HIE.Bios.Types as HieBios
2930
import Ide.Arguments
3031
import Ide.Logger as G
31-
import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
32+
import Ide.Plugin.ConfigUtils (pluginsCustomConfigToMarkdownTables,
33+
pluginsToDefaultConfig,
3234
pluginsToVSCodeExtensionSchema)
3335
import Ide.Types (IdePlugins, PluginId (PluginId),
3436
describePlugin, ipMap, pluginId)
@@ -103,6 +105,8 @@ defaultMain recorder args idePlugins = do
103105

104106
VSCodeExtensionSchemaMode -> do
105107
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins
108+
PluginsCustomConfigMarkdownReferenceMode -> do
109+
T.putStrLn $ pluginsCustomConfigToMarkdownTables idePlugins
106110
DefaultConfigurationMode -> do
107111
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins
108112
PrintLibDir -> do

stack-lts22.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ghc-options:
1515
allow-newer: true
1616
allow-newer-deps:
1717
- extensions
18+
# stan dependencies
19+
- directory-ospath-streaming
1820

1921
extra-deps:
2022
- Diff-0.5
@@ -27,10 +29,9 @@ extra-deps:
2729
- lsp-types-2.3.0.0
2830
- monad-dijkstra-0.1.1.4 # 5
2931
- retrie-1.2.3
30-
- tasty-1.5.3
3132

3233
# stan and friends
33-
- stan-0.1.3.0
34+
- stan-0.2.1.0
3435
- dir-traverse-0.2.3.0
3536
- extensions-0.1.0.1
3637
- tomland-1.3.3.2
@@ -40,6 +41,7 @@ extra-deps:
4041
- validation-selective-0.2.0.0
4142
- cabal-add-0.1
4243
- cabal-install-parsers-0.6.1.1
44+
- directory-ospath-streaming-0.2.2
4345

4446

4547
configure-options:
@@ -57,6 +59,9 @@ flags:
5759
BuildExecutable: false
5860
cabal-add:
5961
cabal-syntax: true
62+
# stan dependencies
63+
directory-ospath-streaming:
64+
os-string: false
6065

6166
nix:
6267
packages: [icu libcxx zlib]

stack.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ allow-newer-deps:
1717
- extensions
1818
- hw-fingertree
1919
- retrie
20+
# stan dependencies
21+
- directory-ospath-streaming
2022

2123
extra-deps:
2224
- floskell-0.11.1
@@ -28,12 +30,13 @@ extra-deps:
2830
- retrie-1.2.3
2931

3032
# stan dependencies not found in the stackage snapshot
31-
- stan-0.1.3.0
33+
- stan-0.2.1.0
3234
- dir-traverse-0.2.3.0
3335
- extensions-0.1.0.1
3436
- trial-0.0.0.0
3537
- trial-optparse-applicative-0.0.0.0
3638
- trial-tomland-0.0.0.0
39+
- directory-ospath-streaming-0.2.2
3740

3841
configure-options:
3942
ghcide:
@@ -50,6 +53,9 @@ flags:
5053
BuildExecutable: false
5154
cabal-add:
5255
cabal-syntax: true
56+
# stan dependencies
57+
directory-ospath-streaming:
58+
os-string: false
5359

5460
nix:
5561
packages: [icu libcxx zlib]

0 commit comments

Comments
 (0)