git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-ide] Also detect location information for operators (#2602)
43c133fChristoph Hegemann
src/Language/PureScript/Ide/Externs.hs+2−2
@@ -138,9 +138,9 @@ annotateModule (defs, types) decls =
138 IdeDeclTypeClass tc ->
138 IdeDeclTypeClass tc ->
139 annotateType (tc ^. ideTCName . properNameT) (IdeDeclTypeClass tc)
139 annotateType (tc ^. ideTCName . properNameT) (IdeDeclTypeClass tc)
140 IdeDeclValueOperator op ->
140 IdeDeclValueOperator op ->
141− annotateValue (op ^. ideValueOpAlias & valueOperatorAliasT) (IdeDeclValueOperator op)
141+ annotateValue (op ^. ideValueOpName . opNameT) (IdeDeclValueOperator op)
142 IdeDeclTypeOperator op ->
142 IdeDeclTypeOperator op ->
143− annotateType (op ^. ideTypeOpAlias & typeOperatorAliasT) (IdeDeclTypeOperator op)
143+ annotateType (op ^. ideTypeOpName . opNameT) (IdeDeclTypeOperator op)
144 IdeDeclKind i ->
144 IdeDeclKind i ->
145 annotateKind (i ^. properNameT) (IdeDeclKind i)
145 annotateKind (i ^. properNameT) (IdeDeclKind i)
146 where
146 where
src/Language/PureScript/Ide/SourceFile.hs+4
@@ -106,6 +106,10 @@ extractSpans ss d = case d of
106 P.DataDeclaration _ name _ ctors ->
106 P.DataDeclaration _ name _ ctors ->
107 (IdeNSType (P.runProperName name), ss)
107 (IdeNSType (P.runProperName name), ss)
108 : map (\(cname, _) -> (IdeNSValue (P.runProperName cname), ss)) ctors
108 : map (\(cname, _) -> (IdeNSValue (P.runProperName cname), ss)) ctors
109+ P.FixityDeclaration (Left (P.ValueFixity _ _ opName)) ->
110+ [(IdeNSValue (P.runOpName opName), ss)]
111+ P.FixityDeclaration (Right (P.TypeFixity _ _ opName)) ->
112+ [(IdeNSType (P.runOpName opName), ss)]
109 P.ExternDeclaration ident _ ->
113 P.ExternDeclaration ident _ ->
110 [(IdeNSValue (P.runIdent ident), ss)]
114 [(IdeNSValue (P.runIdent ident), ss)]
111 P.ExternDataDeclaration name _ ->
115 P.ExternDataDeclaration name _ ->
src/Language/PureScript/Ide/Types.hs+4−4
@@ -145,7 +145,7 @@ data IdeState = IdeState
145 { ideStage1 :: Stage1
145 { ideStage1 :: Stage1
146 , ideStage2 :: Stage2
146 , ideStage2 :: Stage2
147 , ideStage3 :: Stage3
147 , ideStage3 :: Stage3
148− }
148+ } deriving (Show)
149
149
150emptyIdeState :: IdeState
150emptyIdeState :: IdeState
151emptyIdeState = IdeState emptyStage1 emptyStage2 emptyStage3
151emptyIdeState = IdeState emptyStage1 emptyStage2 emptyStage3
@@ -162,16 +162,16 @@ emptyStage3 = Stage3 M.empty Nothing
162data Stage1 = Stage1
162data Stage1 = Stage1
163 { s1Externs :: ModuleMap P.ExternsFile
163 { s1Externs :: ModuleMap P.ExternsFile
164 , s1Modules :: ModuleMap (P.Module, FilePath)
164 , s1Modules :: ModuleMap (P.Module, FilePath)
165− }
165+ } deriving (Show)
166
166
167data Stage2 = Stage2
167data Stage2 = Stage2
168 { s2AstData :: AstData P.SourceSpan
168 { s2AstData :: AstData P.SourceSpan
169− }
169+ } deriving (Show, Eq)
170
170
171data Stage3 = Stage3
171data Stage3 = Stage3
172 { s3Declarations :: ModuleMap [IdeDeclarationAnn]
172 { s3Declarations :: ModuleMap [IdeDeclarationAnn]
173 , s3CachedRebuild :: Maybe (P.ModuleName, P.ExternsFile)
173 , s3CachedRebuild :: Maybe (P.ModuleName, P.ExternsFile)
174− }
174+ } deriving (Show)
175
175
176newtype Match a = Match (P.ModuleName, a)
176newtype Match a = Match (P.ModuleName, a)
177 deriving (Show, Eq, Functor)
177 deriving (Show, Eq, Functor)
src/Language/PureScript/Ide/Util.hs+4
@@ -27,6 +27,7 @@ module Language.PureScript.Ide.Util
27 , prettyTypeT
27 , prettyTypeT
28 , properNameT
28 , properNameT
29 , identT
29 , identT
30+ , opNameT
30 , module Language.PureScript.Ide.Logging
31 , module Language.PureScript.Ide.Logging
31 ) where
32 ) where
32
33
@@ -123,6 +124,9 @@ properNameT = iso P.runProperName P.ProperName
123identT :: Iso' P.Ident Text
124identT :: Iso' P.Ident Text
124identT = iso P.runIdent P.Ident
125identT = iso P.runIdent P.Ident
125
126
127+opNameT :: Iso' (P.OpName a) Text
128+opNameT = iso P.runOpName P.OpName
129+
126prettyTypeT :: P.Type -> Text
130prettyTypeT :: P.Type -> Text
127prettyTypeT =
131prettyTypeT =
128 T.unwords
132 T.unwords
tests/Language/PureScript/Ide/SourceFileSpec.hs+28−2
@@ -16,7 +16,7 @@ span0 = P.SourceSpan "ModuleLevel" (P.SourcePos 0 0) (P.SourcePos 1 1)
16span1 = P.SourceSpan "" (P.SourcePos 1 1) (P.SourcePos 2 2)
16span1 = P.SourceSpan "" (P.SourcePos 1 1) (P.SourcePos 2 2)
17span2 = P.SourceSpan "" (P.SourcePos 2 2) (P.SourcePos 3 3)
17span2 = P.SourceSpan "" (P.SourcePos 2 2) (P.SourcePos 3 3)
18
18
19−typeAnnotation1, value1, synonym1, class1, class2, data1, data2, foreign1, foreign2, foreign3, member1 :: P.Declaration
19+typeAnnotation1, value1, synonym1, class1, class2, data1, data2, valueFixity, typeFixity, foreign1, foreign2, foreign3, member1 :: P.Declaration
20typeAnnotation1 = P.TypeDeclaration (P.Ident "value1") P.REmpty
20typeAnnotation1 = P.TypeDeclaration (P.Ident "value1") P.REmpty
21value1 = P.ValueDeclaration (P.Ident "value1") P.Public [] (Left [])
21value1 = P.ValueDeclaration (P.Ident "value1") P.Public [] (Left [])
22synonym1 = P.TypeSynonymDeclaration (P.ProperName "Synonym1") [] P.REmpty
22synonym1 = P.TypeSynonymDeclaration (P.ProperName "Synonym1") [] P.REmpty
@@ -25,6 +25,16 @@ class2 = P.TypeClassDeclaration (P.ProperName "Class2") [] [] []
25 [P.PositionedDeclaration span2 [] member1]
25 [P.PositionedDeclaration span2 [] member1]
26data1 = P.DataDeclaration P.Newtype (P.ProperName "Data1") [] []
26data1 = P.DataDeclaration P.Newtype (P.ProperName "Data1") [] []
27data2 = P.DataDeclaration P.Data (P.ProperName "Data2") [] [(P.ProperName "Cons1", [])]
27data2 = P.DataDeclaration P.Data (P.ProperName "Data2") [] [(P.ProperName "Cons1", [])]
28+valueFixity =
29+ P.ValueFixityDeclaration
30+ (P.Fixity P.Infix 0)
31+ (P.Qualified Nothing (Left (P.Ident "")))
32+ (P.OpName "<$>")
33+typeFixity =
34+ P.TypeFixityDeclaration
35+ (P.Fixity P.Infix 0)
36+ (P.Qualified Nothing (P.ProperName ""))
37+ (P.OpName "~>")
28foreign1 = P.ExternDeclaration (P.Ident "foreign1") P.REmpty
38foreign1 = P.ExternDeclaration (P.Ident "foreign1") P.REmpty
29foreign2 = P.ExternDataDeclaration (P.ProperName "Foreign2") P.kindType
39foreign2 = P.ExternDataDeclaration (P.ProperName "Foreign2") P.kindType
30foreign3 = P.ExternKindDeclaration (P.ProperName "Foreign3")
40foreign3 = P.ExternKindDeclaration (P.ProperName "Foreign3")
@@ -45,6 +55,10 @@ spec = do
45 extractSpans span0 (P.PositionedDeclaration span1 [] data1) `shouldBe` [(IdeNSType "Data1", span1)]
55 extractSpans span0 (P.PositionedDeclaration span1 [] data1) `shouldBe` [(IdeNSType "Data1", span1)]
46 it "extracts spans for a data declaration and its constructors" $
56 it "extracts spans for a data declaration and its constructors" $
47 extractSpans span0 (P.PositionedDeclaration span1 [] data2) `shouldBe` [(IdeNSType "Data2", span1), (IdeNSValue "Cons1", span1)]
57 extractSpans span0 (P.PositionedDeclaration span1 [] data2) `shouldBe` [(IdeNSType "Data2", span1), (IdeNSValue "Cons1", span1)]
58+ it "extracts a span for a value operator fixity declaration" $
59+ extractSpans span0 (P.PositionedDeclaration span1 [] valueFixity) `shouldBe` [(IdeNSValue "<$>", span1)]
60+ it "extracts a span for a type operator fixity declaration" $
61+ extractSpans span0 (P.PositionedDeclaration span1 [] typeFixity) `shouldBe` [(IdeNSType "~>", span1)]
48 it "extracts a span for a foreign declaration" $
62 it "extracts a span for a foreign declaration" $
49 extractSpans span0 (P.PositionedDeclaration span1 [] foreign1) `shouldBe` [(IdeNSValue "foreign1", span1)]
63 extractSpans span0 (P.PositionedDeclaration span1 [] foreign1) `shouldBe` [(IdeNSValue "foreign1", span1)]
50 it "extracts a span for a data foreign declaration" $
64 it "extracts a span for a data foreign declaration" $
@@ -67,6 +81,12 @@ spec = do
67 it "finds a class declaration" $ do
81 it "finds a class declaration" $ do
68 Just r <- getLocation "SFClass"
82 Just r <- getLocation "SFClass"
69 r `shouldBe` classSS
83 r `shouldBe` classSS
84+ it "finds a value operator declaration" $ do
85+ Just r <- getLocation "<$>"
86+ r `shouldBe` valueOpSS
87+ it "finds a type operator declaration" $ do
88+ Just r <- getLocation "~>"
89+ r `shouldBe` typeOpSS
70
90
71getLocation :: Text -> IO (Maybe P.SourceSpan)
91getLocation :: Text -> IO (Maybe P.SourceSpan)
72getLocation s = do
92getLocation s = do
@@ -83,14 +103,20 @@ getLocation s = do
83 , ideDtor "SFTwo" "SFData" Nothing `annLoc` typeSS
103 , ideDtor "SFTwo" "SFData" Nothing `annLoc` typeSS
84 , ideDtor "SFThree" "SFData" Nothing `annLoc` typeSS
104 , ideDtor "SFThree" "SFData" Nothing `annLoc` typeSS
85 , ideTypeClass "SFClass" [] `annLoc` classSS
105 , ideTypeClass "SFClass" [] `annLoc` classSS
106+ , ideValueOp "<$>" (P.Qualified Nothing (Left "")) 0 Nothing Nothing
107+ `annLoc` valueOpSS
108+ , ideTypeOp "~>" (P.Qualified Nothing "") 0 Nothing Nothing
109+ `annLoc` typeOpSS
86 ])
110 ])
87 ]
111 ]
88
112
89−valueSS, synonymSS, typeSS, classSS :: P.SourceSpan
113+valueSS, synonymSS, typeSS, classSS, valueOpSS, typeOpSS :: P.SourceSpan
90valueSS = ss 3 1
114valueSS = ss 3 1
91synonymSS = ss 5 1
115synonymSS = ss 5 1
92typeSS = ss 7 1
116typeSS = ss 7 1
93classSS = ss 8 1
117classSS = ss 8 1
118+valueOpSS = ss 12 1
119+typeOpSS = ss 13 1
94
120
95ss :: Int -> Int -> P.SourceSpan
121ss :: Int -> Int -> P.SourceSpan
96ss x y = P.SourceSpan "Test.purs" (P.SourcePos x y) (P.SourcePos x y)
122ss x y = P.SourceSpan "Test.purs" (P.SourcePos x y) (P.SourcePos x y)
tests/support/pscide/src/SourceFileSpec.pursdeleted−10
@@ -1,10 +0,0 @@
1−module SourceFileSpec where
2−
3−sfValue = "sfValue"
4−
5−type SFType = String
6−
7−data SFData = SFOne | SFTwo | SFThree
8−
9−class SFClass a where
10− sfShow :: a -> String