git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Return a completion for operators (#2160)
f148735Christoph Hegemann
src/Language/PureScript/Ide/Externs.hs+10−2
@@ -103,11 +103,19 @@ convertDecl P.EDInstance{} = Nothing
103
103
104convertOperator :: P.ExternsFixity -> ExternDecl
104convertOperator :: P.ExternsFixity -> ExternDecl
105convertOperator P.ExternsFixity{..} =
105convertOperator P.ExternsFixity{..} =
106+ ValueOperator
106− FixityDeclaration (Left efOperator)
107+ efOperator
108+ (T.pack (P.showQualified (either P.runIdent P.runProperName) efAlias))
109+ efPrecedence
110+ efAssociativity
107
111
108convertTypeOperator :: P.ExternsTypeFixity -> ExternDecl
112convertTypeOperator :: P.ExternsTypeFixity -> ExternDecl
109convertTypeOperator P.ExternsTypeFixity{..} =
113convertTypeOperator P.ExternsTypeFixity{..} =
114+ TypeOperator
110− FixityDeclaration (Right efTypeOperator)
115+ efTypeOperator
116+ (T.pack (P.showQualified P.runProperName efTypeAlias))
117+ efTypePrecedence
118+ efTypeAssociativity
111
119
112unwrapPositioned :: P.Declaration -> P.Declaration
120unwrapPositioned :: P.Declaration -> P.Declaration
113unwrapPositioned (P.PositionedDeclaration _ _ x) = x
121unwrapPositioned (P.PositionedDeclaration _ _ x) = x
src/Language/PureScript/Ide/Imports.hs+2−2
@@ -215,9 +215,9 @@ addExplicitImport' decl moduleName imports =
215 P.TypeRef tn (Just [P.ProperName (T.unpack n)])
215 P.TypeRef tn (Just [P.ProperName (T.unpack n)])
216 refFromDeclaration (TypeDeclaration n _) =
216 refFromDeclaration (TypeDeclaration n _) =
217 P.TypeRef n (Just [])
217 P.TypeRef n (Just [])
218− refFromDeclaration (FixityDeclaration (Left op)) =
218+ refFromDeclaration (ValueOperator op _ _ _) =
219 P.ValueOpRef op
219 P.ValueOpRef op
220− refFromDeclaration (FixityDeclaration (Right op)) =
220+ refFromDeclaration (TypeOperator op _ _ _) =
221 P.TypeOpRef op
221 P.TypeOpRef op
222 refFromDeclaration d =
222 refFromDeclaration d =
223 P.ValueRef $ P.Ident $ T.unpack (identifierFromExternDecl d)
223 P.ValueRef $ P.Ident $ T.unpack (identifierFromExternDecl d)
src/Language/PureScript/Ide/Types.hs+2−1
@@ -61,7 +61,8 @@ data ExternDecl
61 P.Type -- The "type"
61 P.Type -- The "type"
62 -- | An exported module
62 -- | An exported module
63 | TypeClassDeclaration (P.ProperName 'P.ClassName)
63 | TypeClassDeclaration (P.ProperName 'P.ClassName)
64− | FixityDeclaration (Either (P.OpName 'P.ValueOpName) (P.OpName 'P.TypeOpName))
64+ | ValueOperator (P.OpName 'P.ValueOpName) Ident P.Precedence P.Associativity
65+ | TypeOperator (P.OpName 'P.TypeOpName) Ident P.Precedence P.Associativity
65 | Export ModuleIdent -- The exported Modules name
66 | Export ModuleIdent -- The exported Modules name
66 deriving (Show,Eq,Ord)
67 deriving (Show,Eq,Ord)
67
68
src/Language/PureScript/Ide/Util.hs+21−12
@@ -47,8 +47,8 @@ identifierFromExternDecl (TypeSynonymDeclaration name _) = runProperNameT name
47identifierFromExternDecl (DataConstructor name _ _) = name
47identifierFromExternDecl (DataConstructor name _ _) = name
48identifierFromExternDecl (TypeClassDeclaration name) = runProperNameT name
48identifierFromExternDecl (TypeClassDeclaration name) = runProperNameT name
49identifierFromExternDecl (ModuleDecl name _) = name
49identifierFromExternDecl (ModuleDecl name _) = name
50−identifierFromExternDecl (FixityDeclaration (Left op)) = runOpNameT op
50+identifierFromExternDecl (ValueOperator op _ _ _) = runOpNameT op
51−identifierFromExternDecl (FixityDeclaration (Right op)) = runOpNameT op
51+identifierFromExternDecl (TypeOperator op _ _ _) = runOpNameT op
52identifierFromExternDecl Dependency{} = "~Dependency~"
52identifierFromExternDecl Dependency{} = "~Dependency~"
53identifierFromExternDecl Export{} = "~Export~"
53identifierFromExternDecl Export{} = "~Export~"
54
54
@@ -56,16 +56,25 @@ identifierFromMatch :: Match -> Text
56identifierFromMatch (Match _ ed) = identifierFromExternDecl ed
56identifierFromMatch (Match _ ed) = identifierFromExternDecl ed
57
57
58completionFromMatch :: Match -> Maybe Completion
58completionFromMatch :: Match -> Maybe Completion
59−completionFromMatch (Match _ Dependency{}) = Nothing
59+completionFromMatch (Match m d) = case d of
60−completionFromMatch (Match _ Export{}) = Nothing
61−completionFromMatch (Match m d) = Just $ case d of
62− ValueDeclaration name type' -> Completion (m, name, prettyTypeT type')
60+ ValueDeclaration name type' -> Just $ Completion (m, name, prettyTypeT type')
63− TypeDeclaration name kind -> Completion (m, runProperNameT name, T.pack $ P.prettyPrintKind kind)
61+ TypeDeclaration name kind -> Just $ Completion (m, runProperNameT name, T.pack $ P.prettyPrintKind kind)
64− TypeSynonymDeclaration name kind -> Completion (m, runProperNameT name, prettyTypeT kind)
62+ TypeSynonymDeclaration name kind -> Just $ Completion (m, runProperNameT name, prettyTypeT kind)
65− DataConstructor name _ type' -> Completion (m, name, prettyTypeT type')
63+ DataConstructor name _ type' -> Just $ Completion (m, name, prettyTypeT type')
66− TypeClassDeclaration name -> Completion (m, runProperNameT name, "class")
64+ TypeClassDeclaration name -> Just $ Completion (m, runProperNameT name, "class")
67− ModuleDecl name _ -> Completion ("module", name, "module")
65+ ModuleDecl name _ -> Just $ Completion ("module", name, "module")
68− _ -> error "the impossible happened in completionFromMatch"
66+ ValueOperator op ref precedence associativity -> Just $ Completion (m, runOpNameT op, showFixity precedence associativity ref op)
67+ TypeOperator op ref precedence associativity -> Just $ Completion (m, runOpNameT op, showFixity precedence associativity ref op)
68+ Dependency{} -> Nothing
69+ Export{} -> Nothing
70+ where
71+ showFixity p a r o =
72+ let asso = case a of
73+ P.Infix -> "infix"
74+ P.Infixl -> "infixl"
75+ P.Infixr -> "infixr"
76+ in T.unwords [asso, T.pack (show p), r, "as", runOpNameT o]
77+
69
78
70encodeT :: (ToJSON a) => a -> Text
79encodeT :: (ToJSON a) => a -> Text
71encodeT = toStrict . decodeUtf8 . encode
80encodeT = toStrict . decodeUtf8 . encode
tests/Language/PureScript/Ide/ImportsSpec.hs+2−2
@@ -70,7 +70,7 @@ spec = do
70 addValueImport i mn is =
70 addValueImport i mn is =
71 prettyPrintImportSection (addExplicitImport' (ValueDeclaration i wildcard) mn is)
71 prettyPrintImportSection (addExplicitImport' (ValueDeclaration i wildcard) mn is)
72 addOpImport op mn is =
72 addOpImport op mn is =
73− prettyPrintImportSection (addExplicitImport' (FixityDeclaration op) mn is)
73+ prettyPrintImportSection (addExplicitImport' (ValueOperator op "" 2 P.Infix) mn is)
74 addDtorImport i t mn is =
74 addDtorImport i t mn is =
75 prettyPrintImportSection (addExplicitImport' (DataConstructor i t wildcard) mn is)
75 prettyPrintImportSection (addExplicitImport' (DataConstructor i t wildcard) mn is)
76 it "adds an implicit unqualified import" $
76 it "adds an implicit unqualified import" $
@@ -98,7 +98,7 @@ spec = do
98 ]
98 ]
99 it "adds an operator to an explicit import list" $
99 it "adds an operator to an explicit import list" $
100 shouldBe
100 shouldBe
101− (addOpImport (Left (P.OpName "<~>")) (P.moduleNameFromString "Data.Array") explicitImports)
101+ (addOpImport (P.OpName "<~>") (P.moduleNameFromString "Data.Array") explicitImports)
102 [ "import Prelude"
102 [ "import Prelude"
103 , "import Data.Array ((<~>), tail)"
103 , "import Data.Array ((<~>), tail)"
104 ]
104 ]