Skip to content

Commit

Permalink
Add qnames for Haskell
Browse files Browse the repository at this point in the history
Summary:
One of the most common errors on API Docs appears to be

```
ServerException	ServerException {serverException_message = "QualifiedName: Language unsupported: Language_Haskell"}	247 (0.4%)
```

247 events in the last day.

I don't fully understand how it could be so common, unless Haskell api pages are getting rendered in search results somewhere and failing.

Somewhere along the line qnames became mandatory, instead of optional. So fix that.

also fixes search : "No results found in symbol"

in search, Haskell syms are still only discoverable by qname
{F1761495551}

the underlying problem is the hs.DefinitionName is a qname

we need a dotted form with separate structured components.

```
fbsource.fbcode.haskell> hs.DefinitionName _
{ "id": 88131, "key": "A.Types.A" }
{ "id": 61435, "key": "A.a" }
{ "id": 68899, "key": "A.main" }
{ "id": 82260, "key": "AardvarkTest.aardvarkCounter" }
{ "id": 82262, "key": "AardvarkTest.main" }
{ "id": 91585, "key": "Acl.Types.Identity" }
{ "id": 52655, "key": "AddPrefixTest.main" }
{ "id": 52661, "key": "AddPrefixTest.toPrefixedE" }
{ "id": 52659, "key": "AddPrefixTest.toPrefixedS" }
{ "id": 52657, "key": "AddPrefixTest.toPrefixedU" }
{ "id": 75973, "key": "AesonTest.main" }
{ "i
```

becomes:

Reviewed By: simonmar

Differential Revision: D59898073

fbshipit-source-id: 5f1851ca5350edf6d5ab60119be66da5feb1f7f8
  • Loading branch information
donsbot authored and facebook-github-bot committed Jul 18, 2024
1 parent ba496e1 commit 9a94952
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions glean/glass/Glean/Glass/SymbolId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ instance ToQName Code.Entity where
Code.Entity_flow x -> toQName x
Code.Entity_graphql x -> toQName x
Code.Entity_hack (Hack.Entity_decl x) -> toQName x
Code.Entity_hs x -> toQName x
Code.Entity_java x -> toQName x
Code.Entity_kotlin x -> toQName x
Code.Entity_pp x -> toQName x
Expand Down
53 changes: 44 additions & 9 deletions glean/glass/Glean/Glass/SymbolId/Hs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
{-# OPTIONS_GHC -Wno-orphans #-}

module Glean.Glass.SymbolId.Hs ({- instances -}) where

import Data.Text (Text)
import qualified Data.Text as Text
import Glean.Glass.SymbolId.Class
( toSymbolPredicate, Symbol(..) )

import Glean.Glass.SymbolId.Class
import Glean.Glass.Types (Name(..))
import Glean.Schema.CodeHs.Types as Hs (Entity (..))
import qualified Glean

import qualified Glean.Schema.Hs.Types as Hs
import qualified Glean.Schema.Src.Types as Src

import Glean.Schema.CodeHs.Types as Hs (Entity (..))
instance Symbol Hs.Entity where
toSymbol (Hs.Entity_definition d) = toSymbolPredicate d
toSymbol (Hs.Entity_function_ d) = toSymbolPredicate d
toSymbol (Hs.Entity_class_ d) = toSymbolPredicate d
toSymbol Hs.Entity_EMPTY = return []

instance Symbol Hs.Definition_key where
toSymbol (Hs.Definition_key name _) = do
Expand All @@ -37,8 +43,37 @@ instance Symbol Hs.Class_key where
fname <- Glean.keyOf range_file
return (fname : Text.splitOn "." name)

instance Symbol Hs.Entity where
toSymbol (Hs.Entity_definition d) = toSymbolPredicate d
toSymbol (Hs.Entity_function_ d) = toSymbolPredicate d
toSymbol (Hs.Entity_class_ d) = toSymbolPredicate d
toSymbol Hs.Entity_EMPTY = return []
instance ToQName Hs.Entity where
toQName (Hs.Entity_definition d) = Glean.keyOf d >>= toQName
toQName (Hs.Entity_function_ d) = Glean.keyOf d >>= toQName
toQName (Hs.Entity_class_ d) = Glean.keyOf d >>= toQName
toQName Hs.Entity_EMPTY =
return $ Left "toQName: Haskell: empty qname"

instance ToQName Hs.Definition_key where
toQName (Hs.Definition_key name _) = do
n <- Glean.keyOf name
return $ case reverse (Text.splitOn "." n) of
[] -> Left "toQName: Haskell: empty function qname"
[x] -> Right (Name x, Name "")
(x:xs) -> Right (Name x, joinDotted xs)

instance ToQName Hs.FunctionDefinition_key where
toQName (Hs.FunctionDefinition_key fnName Src.Range{..}) = do
name <- Glean.keyOf fnName
return $ case reverse (Text.splitOn "." name) of
[] -> Left "toQName: Haskell: empty function qname"
[x] -> Right (Name x, Name "")
(x:xs) -> Right (Name x, joinDotted xs)


instance ToQName Hs.Class_key where
toQName (Hs.Class_key clsName Src.Range{..}) = do
name <- Glean.keyOf clsName
return $ case reverse (Text.splitOn "." name) of
[] -> Left "toQName: Haskell: empty class qname"
[x] -> Right (Name x, Name "")
(x:xs) -> Right (Name x, joinDotted xs)

joinDotted :: [Text] -> Name
joinDotted = Name . Text.intercalate "." . reverse

0 comments on commit 9a94952

Please sign in to comment.