Skip to content

Commit c37ed4a

Browse files
authored
Merge branch 'master' into jhrcek/cleanup-cabal-conditionals
2 parents 3f1ce87 + b000b6b commit c37ed4a

File tree

10 files changed

+51
-42
lines changed

10 files changed

+51
-42
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ packages:
3636
./plugins/hls-overloaded-record-dot-plugin
3737
./plugins/hls-semantic-tokens-plugin
3838

39-
index-state: 2024-01-05T19:06:05Z
39+
index-state: 2024-01-13T19:06:05Z
4040

4141
tests: True
4242
test-show-details: direct

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ library
7878
, hashable
7979
, hie-bios ==0.13.1
8080
, hie-compat ^>=0.3.0.0
81-
, hiedb >=0.4.4 && <0.4.5
81+
, hiedb ^>= 0.5.0.1
8282
, hls-graph == 2.5.0.0
8383
, hls-plugin-api == 2.5.0.0
8484
, implicit-hie >= 0.1.4.0 && < 0.1.5

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

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
{-# LANGUAGE TypeFamilies #-}
1212
{-# LANGUAGE TypeOperators #-}
1313
{-# LANGUAGE UndecidableInstances #-}
14-
-- See Note [Constraints]
15-
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
1614

1715
module Ide.Plugin.Properties
1816
( PropertyType (..),
@@ -44,13 +42,11 @@ import qualified Data.Aeson.Types as A
4442
import Data.Either (fromRight)
4543
import Data.Function ((&))
4644
import Data.Kind (Constraint, Type)
47-
import qualified Data.Map.Strict as Map
4845
import Data.Proxy (Proxy (..))
4946
import Data.String (IsString (fromString))
5047
import qualified Data.Text as T
5148
import GHC.OverloadedLabels (IsLabel (..))
5249
import GHC.TypeLits
53-
import Unsafe.Coerce (unsafeCoerce)
5450

5551
-- | Types properties may have
5652
data PropertyType
@@ -114,7 +110,10 @@ data SomePropertyKeyWithMetaData
114110
-- A property is an immediate child of the json object in each plugin's "config" section.
115111
-- It was designed to be compatible with vscode's settings UI.
116112
-- Use 'emptyProperties' and 'useProperty' to create and consume 'Properties'.
117-
newtype Properties (r :: [PropertyKey]) = Properties (Map.Map String SomePropertyKeyWithMetaData)
113+
data Properties (r :: [PropertyKey]) where
114+
ConsProperties :: (k ~ 'PropertyKey s t, KnownSymbol s, NotElem s ks)
115+
=> KeyNameProxy s -> (SPropertyKey k) -> (MetaData t) -> Properties ks -> Properties (k : ks)
116+
EmptyProperties :: Properties '[]
118117

119118
-- | A proxy type in order to allow overloaded labels as properties' names at the call site
120119
data KeyNameProxy (s :: Symbol) = KnownSymbol s => KeyNameProxy
@@ -132,6 +131,10 @@ type family FindByKeyName (s :: Symbol) (r :: [PropertyKey]) :: PropertyType whe
132131
FindByKeyName s ('PropertyKey s t ': _) = t
133132
FindByKeyName s (_ ': xs) = FindByKeyName s xs
134133

134+
type family IsPropertySymbol (s :: Symbol) (r :: PropertyKey) :: Bool where
135+
IsPropertySymbol s ('PropertyKey s _) = 'True
136+
IsPropertySymbol s _ = 'False
137+
135138
type family Elem (s :: Symbol) (r :: [PropertyKey]) :: Constraint where
136139
Elem s ('PropertyKey s _ ': _) = ()
137140
Elem s (_ ': xs) = Elem s xs
@@ -143,7 +146,17 @@ type family NotElem (s :: Symbol) (r :: [PropertyKey]) :: Constraint where
143146
NotElem s '[] = ()
144147

145148
-- | In row @r@, there is a 'PropertyKey' @k@, which has name @s@ and carries haskell type @t@
146-
type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~ t, KnownSymbol s)
149+
type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~ t, KnownSymbol s, FindPropertyMeta s r t)
150+
class FindPropertyMeta (s :: Symbol) (r :: [PropertyKey]) t where
151+
findSomePropertyKeyWithMetaData :: KeyNameProxy s -> Properties r -> (SPropertyKey ('PropertyKey s t), MetaData t)
152+
instance (FindPropertyMetaIf (IsPropertySymbol symbol k) symbol k ks t) => FindPropertyMeta symbol (k : ks) t where
153+
findSomePropertyKeyWithMetaData = findSomePropertyKeyWithMetaDataIf
154+
class (bool ~ IsPropertySymbol symbol k) => FindPropertyMetaIf bool symbol k ks t where
155+
findSomePropertyKeyWithMetaDataIf :: KeyNameProxy symbol -> Properties (k : ks) -> (SPropertyKey ('PropertyKey symbol t), MetaData t)
156+
instance (k ~ 'PropertyKey s t) => FindPropertyMetaIf 'True s k ks t where
157+
findSomePropertyKeyWithMetaDataIf _ (ConsProperties _ k m _) = (k, m)
158+
instance ('False ~ IsPropertySymbol s k, FindPropertyMeta s ks t) => FindPropertyMetaIf 'False s k ks t where
159+
findSomePropertyKeyWithMetaDataIf s (ConsProperties _ _ _ ks) = findSomePropertyKeyWithMetaData s ks
147160

148161
-- ---------------------------------------------------------------------
149162

@@ -164,7 +177,7 @@ type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~
164177
-- @
165178

166179
emptyProperties :: Properties '[]
167-
emptyProperties = Properties Map.empty
180+
emptyProperties = EmptyProperties
168181

169182
insert ::
170183
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
@@ -173,30 +186,14 @@ insert ::
173186
MetaData t ->
174187
Properties r ->
175188
Properties (k ': r)
176-
insert kn key metadata (Properties old) =
177-
Properties
178-
( Map.insert
179-
(symbolVal kn)
180-
(SomePropertyKeyWithMetaData key metadata)
181-
old
182-
)
189+
insert = ConsProperties
183190

184191
find ::
185192
(HasProperty s k t r) =>
186193
KeyNameProxy s ->
187194
Properties r ->
188195
(SPropertyKey k, MetaData t)
189-
find kn (Properties p) = case p Map.! symbolVal kn of
190-
(SomePropertyKeyWithMetaData sing metadata) ->
191-
-- Note [Constraints]
192-
-- It's safe to use unsafeCoerce here:
193-
-- Since each property name is unique that the redefinition will be prevented by predication on the type level list,
194-
-- the value we get from the name-indexed map must be exactly the singleton and metadata corresponding to the type.
195-
-- We drop this information at type level: some of the above type families return '() :: Constraint',
196-
-- so GHC will consider them as redundant.
197-
-- But we encode it using semantically identical 'Map' at term level,
198-
-- which avoids inducting on the list by defining a new type class.
199-
unsafeCoerce (sing, metadata)
196+
find = findSomePropertyKeyWithMetaData
200197

201198
-- ---------------------------------------------------------------------
202199

@@ -350,7 +347,10 @@ defineEnumProperty kn description enums defaultValue =
350347

351348
-- | Converts a properties definition into kv pairs with default values from 'MetaData'
352349
toDefaultJSON :: Properties r -> [A.Pair]
353-
toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
350+
toDefaultJSON pr = case pr of
351+
EmptyProperties -> []
352+
ConsProperties keyNameProxy k m xs ->
353+
toEntry (symbolVal keyNameProxy) (SomePropertyKeyWithMetaData k m) : toDefaultJSON xs
354354
where
355355
toEntry :: String -> SomePropertyKeyWithMetaData -> A.Pair
356356
toEntry s = \case
@@ -371,8 +371,10 @@ toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
371371

372372
-- | Converts a properties definition into kv pairs as vscode schema
373373
toVSCodeExtensionSchema :: T.Text -> Properties r -> [A.Pair]
374-
toVSCodeExtensionSchema prefix (Properties p) =
375-
[fromString (T.unpack prefix <> k) A..= toEntry v | (k, v) <- Map.toList p]
374+
toVSCodeExtensionSchema prefix ps = case ps of
375+
EmptyProperties -> []
376+
ConsProperties (keyNameProxy :: KeyNameProxy s) (k :: SPropertyKey k) (m :: MetaData t) xs ->
377+
fromString (T.unpack prefix <> symbolVal keyNameProxy) A..= toEntry (SomePropertyKeyWithMetaData k m) : toVSCodeExtensionSchema prefix xs
376378
where
377379
toEntry :: SomePropertyKeyWithMetaData -> A.Value
378380
toEntry = \case

plugins/hls-call-hierarchy-plugin/src/Ide/Plugin/CallHierarchy/Query.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ module Ide.Plugin.CallHierarchy.Query (
1111
import qualified Data.Text as T
1212
import Database.SQLite.Simple
1313
import Development.IDE.GHC.Compat
14-
import HieDb (HieDb (getConn), Symbol (..),
15-
toNsChar)
14+
import HieDb (HieDb (getConn), Symbol (..))
1615
import Ide.Plugin.CallHierarchy.Types
1716

1817
incomingCalls :: HieDb -> Symbol -> IO [Vertex]
@@ -73,9 +72,9 @@ getSymbolPosition (getConn -> conn) Vertex{..} = do
7372
]
7473
) (occ, sl, sc, sl, el, ec, el)
7574

76-
parseSymbol :: Symbol -> (String, String, String)
75+
parseSymbol :: Symbol -> (OccName, ModuleName, Unit)
7776
parseSymbol Symbol{..} =
78-
let o = toNsChar (occNameSpace symName) : occNameString symName
79-
m = moduleNameString $ moduleName symModule
80-
u = unitString $ moduleUnit symModule
77+
let o = symName
78+
m = moduleName symModule
79+
u = moduleUnit symModule
8180
in (o, m, u)

plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Query.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ hieAstSpanNames vf ast =
8383
inclusion a b = not $ exclusion a b
8484
exclusion :: Identifier -> IdentifierDetails a -> Bool
8585
exclusion idt IdentifierDetails {identInfo = infos} = case idt of
86-
Left _ -> True
87-
Right name ->
88-
isDerivedOccName (nameOccName name)
89-
|| any isEvidenceContext (S.toList infos)
86+
Left _ -> True
87+
Right _ -> any isEvidenceContext (S.toList infos)
9088

9189
-------------------------------------------------
9290

plugins/hls-semantic-tokens-plugin/test/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ semanticTokensDataTypeTests =
187187
"get semantic Tokens"
188188
[ goldenWithSemanticTokens "simple datatype" "TDataType",
189189
goldenWithSemanticTokens "record" "TRecord",
190+
goldenWithSemanticTokens "record" "TRecordDuplicateRecordFields",
190191
goldenWithSemanticTokens "datatype import" "TDatatypeImported",
191192
goldenWithSemanticTokens "datatype family" "TDataFamily",
192193
goldenWithSemanticTokens "GADT" "TGADT"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
5:6-9 TTypeCon "Foo"
2+
5:12-15 TDataCon "Foo"
3+
5:18-21 TRecField "boo"
4+
5:26-32 TTypeSyn "String"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE DuplicateRecordFields #-}
2+
3+
module TRecordDuplicateRecordFields where
4+
5+
data Foo = Foo { boo :: !String }

stack-lts21.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ allow-newer: true
4545

4646
extra-deps:
4747
- floskell-0.11.1
48-
- hiedb-0.4.4.0
48+
- hiedb-0.5.0.1
4949
- hie-bios-0.13.1
5050
- implicit-hie-0.1.4.0
5151
- monad-dijkstra-0.1.1.3

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ allow-newer: true
4545
extra-deps:
4646
- floskell-0.11.1
4747
- retrie-1.2.2
48-
- hiedb-0.4.4.0
48+
- hiedb-0.5.0.1
4949
- implicit-hie-0.1.4.0
5050
- hie-bios-0.13.1
5151
- lsp-2.3.0.0

0 commit comments

Comments
 (0)