git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Return a completion for operators (#2160)

* Return a completion for operators Because we can't get at the type/kind for now we just print the referenced function/type constructor * show fixity for operators as their type

commitf148735be182c5e503877776ce95309b7550fe86 authorChristoph Hegemann <kRITZCREEK@users.noreply.github.com> dateTue 24 May 2016, 22:31 (10 years ago) parenta1168e3
5 files changed+37−19
src/Language/PureScript/Ide/Externs.hs+10−2 src/Language/PureScript/Ide/Imports.hs+2−2 src/Language/PureScript/Ide/Types.hs+2−1 src/Language/PureScript/Ide/Util.hs+21−12 tests/Language/PureScript/Ide/ImportsSpec.hs+2−2
src/Language/PureScript/Ide/Externs.hs+10−2
@@ -103,11 +103,19 @@ convertDecl P.EDInstance{} = Nothing
103103
104104convertOperator :: P.ExternsFixity -> ExternDecl
105105convertOperator P.ExternsFixity{..} =
106− FixityDeclaration (Left efOperator)
106+ ValueOperator
107+ efOperator
108+ (T.pack (P.showQualified (either P.runIdent P.runProperName) efAlias))
109+ efPrecedence
110+ efAssociativity
107111
108112convertTypeOperator :: P.ExternsTypeFixity -> ExternDecl
109113convertTypeOperator P.ExternsTypeFixity{..} =
110− FixityDeclaration (Right efTypeOperator)
114+ TypeOperator
115+ efTypeOperator
116+ (T.pack (P.showQualified P.runProperName efTypeAlias))
117+ efTypePrecedence
118+ efTypeAssociativity
111119
112120unwrapPositioned :: P.Declaration -> P.Declaration
113121unwrapPositioned (P.PositionedDeclaration _ _ x) = x
src/Language/PureScript/Ide/Imports.hs+2−2
@@ -215,9 +215,9 @@ addExplicitImport' decl moduleName imports =
215215 P.TypeRef tn (Just [P.ProperName (T.unpack n)])
216216 refFromDeclaration (TypeDeclaration n _) =
217217 P.TypeRef n (Just [])
218− refFromDeclaration (FixityDeclaration (Left op)) =
218+ refFromDeclaration (ValueOperator op _ _ _) =
219219 P.ValueOpRef op
220− refFromDeclaration (FixityDeclaration (Right op)) =
220+ refFromDeclaration (TypeOperator op _ _ _) =
221221 P.TypeOpRef op
222222 refFromDeclaration d =
223223 P.ValueRef $ P.Ident $ T.unpack (identifierFromExternDecl d)
src/Language/PureScript/Ide/Types.hs+2−1
@@ -61,7 +61,8 @@ data ExternDecl
6161 P.Type -- The "type"
6262 -- | An exported module
6363 | 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
6566 | Export ModuleIdent -- The exported Modules name
6667 deriving (Show,Eq,Ord)
6768
src/Language/PureScript/Ide/Util.hs+21−12
@@ -47,8 +47,8 @@ identifierFromExternDecl (TypeSynonymDeclaration name _) = runProperNameT name
4747identifierFromExternDecl (DataConstructor name _ _) = name
4848identifierFromExternDecl (TypeClassDeclaration name) = runProperNameT name
4949identifierFromExternDecl (ModuleDecl name _) = name
50−identifierFromExternDecl (FixityDeclaration (Left op)) = runOpNameT op
51−identifierFromExternDecl (FixityDeclaration (Right op)) = runOpNameT op
50+identifierFromExternDecl (ValueOperator op _ _ _) = runOpNameT op
51+identifierFromExternDecl (TypeOperator op _ _ _) = runOpNameT op
5252identifierFromExternDecl Dependency{} = "~Dependency~"
5353identifierFromExternDecl Export{} = "~Export~"
5454
@@ -56,16 +56,25 @@ identifierFromMatch :: Match -> Text
5656identifierFromMatch (Match _ ed) = identifierFromExternDecl ed
5757
5858completionFromMatch :: Match -> Maybe Completion
59−completionFromMatch (Match _ Dependency{}) = Nothing
60−completionFromMatch (Match _ Export{}) = Nothing
61−completionFromMatch (Match m d) = Just $ case d of
62− ValueDeclaration name type' -> Completion (m, name, prettyTypeT type')
63− TypeDeclaration name kind -> Completion (m, runProperNameT name, T.pack $ P.prettyPrintKind kind)
64− TypeSynonymDeclaration name kind -> Completion (m, runProperNameT name, prettyTypeT kind)
65− DataConstructor name _ type' -> Completion (m, name, prettyTypeT type')
66− TypeClassDeclaration name -> Completion (m, runProperNameT name, "class")
67− ModuleDecl name _ -> Completion ("module", name, "module")
68− _ -> error "the impossible happened in completionFromMatch"
59+completionFromMatch (Match m d) = case d of
60+ ValueDeclaration name type' -> Just $ Completion (m, name, prettyTypeT type')
61+ TypeDeclaration name kind -> Just $ Completion (m, runProperNameT name, T.pack $ P.prettyPrintKind kind)
62+ TypeSynonymDeclaration name kind -> Just $ Completion (m, runProperNameT name, prettyTypeT kind)
63+ DataConstructor name _ type' -> Just $ Completion (m, name, prettyTypeT type')
64+ TypeClassDeclaration name -> Just $ Completion (m, runProperNameT name, "class")
65+ ModuleDecl name _ -> Just $ Completion ("module", name, "module")
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+
6978
7079encodeT :: (ToJSON a) => a -> Text
7180encodeT = toStrict . decodeUtf8 . encode
tests/Language/PureScript/Ide/ImportsSpec.hs+2−2
@@ -70,7 +70,7 @@ spec = do
7070 addValueImport i mn is =
7171 prettyPrintImportSection (addExplicitImport' (ValueDeclaration i wildcard) mn is)
7272 addOpImport op mn is =
73− prettyPrintImportSection (addExplicitImport' (FixityDeclaration op) mn is)
73+ prettyPrintImportSection (addExplicitImport' (ValueOperator op "" 2 P.Infix) mn is)
7474 addDtorImport i t mn is =
7575 prettyPrintImportSection (addExplicitImport' (DataConstructor i t wildcard) mn is)
7676 it "adds an implicit unqualified import" $
@@ -98,7 +98,7 @@ spec = do
9898 ]
9999 it "adds an operator to an explicit import list" $
100100 shouldBe
101− (addOpImport (Left (P.OpName "<~>")) (P.moduleNameFromString "Data.Array") explicitImports)
101+ (addOpImport (P.OpName "<~>") (P.moduleNameFromString "Data.Array") explicitImports)
102102 [ "import Prelude"
103103 , "import Data.Array ((<~>), tail)"
104104 ]