git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-ide] Also detect location information for operators (#2602)
commit43c133fbf00d88da67d07a6a730a4cd543921b0c authorChristoph Hegemann <kRITZCREEK@users.noreply.github.com> dateFri 27 Jan 2017, 18:10 (10 years ago) parent220e6ae
6 files changed+42−18
src/Language/PureScript/Ide/Externs.hs+2−2 src/Language/PureScript/Ide/SourceFile.hs+4 src/Language/PureScript/Ide/Types.hs+4−4 src/Language/PureScript/Ide/Util.hs+4 tests/Language/PureScript/Ide/SourceFileSpec.hs+28−2 tests/support/pscide/src/SourceFileSpec.purs−10
src/Language/PureScript/Ide/Externs.hs+2−2
@@ -138,9 +138,9 @@ annotateModule (defs, types) decls =
138138 IdeDeclTypeClass tc ->
139139 annotateType (tc ^. ideTCName . properNameT) (IdeDeclTypeClass tc)
140140 IdeDeclValueOperator op ->
141− annotateValue (op ^. ideValueOpAlias & valueOperatorAliasT) (IdeDeclValueOperator op)
141+ annotateValue (op ^. ideValueOpName . opNameT) (IdeDeclValueOperator op)
142142 IdeDeclTypeOperator op ->
143− annotateType (op ^. ideTypeOpAlias & typeOperatorAliasT) (IdeDeclTypeOperator op)
143+ annotateType (op ^. ideTypeOpName . opNameT) (IdeDeclTypeOperator op)
144144 IdeDeclKind i ->
145145 annotateKind (i ^. properNameT) (IdeDeclKind i)
146146 where
src/Language/PureScript/Ide/SourceFile.hs+4
@@ -106,6 +106,10 @@ extractSpans ss d = case d of
106106 P.DataDeclaration _ name _ ctors ->
107107 (IdeNSType (P.runProperName name), ss)
108108 : 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)]
109113 P.ExternDeclaration ident _ ->
110114 [(IdeNSValue (P.runIdent ident), ss)]
111115 P.ExternDataDeclaration name _ ->
src/Language/PureScript/Ide/Types.hs+4−4
@@ -145,7 +145,7 @@ data IdeState = IdeState
145145 { ideStage1 :: Stage1
146146 , ideStage2 :: Stage2
147147 , ideStage3 :: Stage3
148− }
148+ } deriving (Show)
149149
150150emptyIdeState :: IdeState
151151emptyIdeState = IdeState emptyStage1 emptyStage2 emptyStage3
@@ -162,16 +162,16 @@ emptyStage3 = Stage3 M.empty Nothing
162162data Stage1 = Stage1
163163 { s1Externs :: ModuleMap P.ExternsFile
164164 , s1Modules :: ModuleMap (P.Module, FilePath)
165− }
165+ } deriving (Show)
166166
167167data Stage2 = Stage2
168168 { s2AstData :: AstData P.SourceSpan
169− }
169+ } deriving (Show, Eq)
170170
171171data Stage3 = Stage3
172172 { s3Declarations :: ModuleMap [IdeDeclarationAnn]
173173 , s3CachedRebuild :: Maybe (P.ModuleName, P.ExternsFile)
174− }
174+ } deriving (Show)
175175
176176newtype Match a = Match (P.ModuleName, a)
177177 deriving (Show, Eq, Functor)
src/Language/PureScript/Ide/Util.hs+4
@@ -27,6 +27,7 @@ module Language.PureScript.Ide.Util
2727 , prettyTypeT
2828 , properNameT
2929 , identT
30+ , opNameT
3031 , module Language.PureScript.Ide.Logging
3132 ) where
3233
@@ -123,6 +124,9 @@ properNameT = iso P.runProperName P.ProperName
123124identT :: Iso' P.Ident Text
124125identT = iso P.runIdent P.Ident
125126
127+opNameT :: Iso' (P.OpName a) Text
128+opNameT = iso P.runOpName P.OpName
129+
126130prettyTypeT :: P.Type -> Text
127131prettyTypeT =
128132 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)
1616span1 = P.SourceSpan "" (P.SourcePos 1 1) (P.SourcePos 2 2)
1717span2 = P.SourceSpan "" (P.SourcePos 2 2) (P.SourcePos 3 3)
1818
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
2020typeAnnotation1 = P.TypeDeclaration (P.Ident "value1") P.REmpty
2121value1 = P.ValueDeclaration (P.Ident "value1") P.Public [] (Left [])
2222synonym1 = P.TypeSynonymDeclaration (P.ProperName "Synonym1") [] P.REmpty
@@ -25,6 +25,16 @@ class2 = P.TypeClassDeclaration (P.ProperName "Class2") [] [] []
2525 [P.PositionedDeclaration span2 [] member1]
2626data1 = P.DataDeclaration P.Newtype (P.ProperName "Data1") [] []
2727data2 = 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 "~>")
2838foreign1 = P.ExternDeclaration (P.Ident "foreign1") P.REmpty
2939foreign2 = P.ExternDataDeclaration (P.ProperName "Foreign2") P.kindType
3040foreign3 = P.ExternKindDeclaration (P.ProperName "Foreign3")
@@ -45,6 +55,10 @@ spec = do
4555 extractSpans span0 (P.PositionedDeclaration span1 [] data1) `shouldBe` [(IdeNSType "Data1", span1)]
4656 it "extracts spans for a data declaration and its constructors" $
4757 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)]
4862 it "extracts a span for a foreign declaration" $
4963 extractSpans span0 (P.PositionedDeclaration span1 [] foreign1) `shouldBe` [(IdeNSValue "foreign1", span1)]
5064 it "extracts a span for a data foreign declaration" $
@@ -67,6 +81,12 @@ spec = do
6781 it "finds a class declaration" $ do
6882 Just r <- getLocation "SFClass"
6983 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
7090
7191getLocation :: Text -> IO (Maybe P.SourceSpan)
7292getLocation s = do
@@ -83,14 +103,20 @@ getLocation s = do
83103 , ideDtor "SFTwo" "SFData" Nothing `annLoc` typeSS
84104 , ideDtor "SFThree" "SFData" Nothing `annLoc` typeSS
85105 , 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
86110 ])
87111 ]
88112
89−valueSS, synonymSS, typeSS, classSS :: P.SourceSpan
113+valueSS, synonymSS, typeSS, classSS, valueOpSS, typeOpSS :: P.SourceSpan
90114valueSS = ss 3 1
91115synonymSS = ss 5 1
92116typeSS = ss 7 1
93117classSS = ss 8 1
118+valueOpSS = ss 12 1
119+typeOpSS = ss 13 1
94120
95121ss :: Int -> Int -> P.SourceSpan
96122ss 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