diff --git a/src/test/contracts/blocks.ligo b/src/test/contracts/blocks.ligo index 74243006b..d1d541e9e 100644 --- a/src/test/contracts/blocks.ligo +++ b/src/test/contracts/blocks.ligo @@ -1,7 +1,7 @@ function main() : int is - block - var j := 1; + block { + var j : int := 1; j := j + 1; - j := j - 1; - with j \ No newline at end of file + j := j - 1 + } with j \ No newline at end of file diff --git a/tools/lsp/squirrel/src/AST/Find.hs b/tools/lsp/squirrel/src/AST/Find.hs index 7fe815c68..f1b8544a4 100644 --- a/tools/lsp/squirrel/src/AST/Find.hs +++ b/tools/lsp/squirrel/src/AST/Find.hs @@ -12,13 +12,19 @@ import Range import Pretty import Product +import Data.Text (Text) -- import Debug.Trace +type CanSearch xs = + ( Contains [ScopedDecl] xs + , Contains Range xs + , Contains (Maybe Category) xs + , Contains [Text] xs + , Pretty (Product xs) + ) + findScopedDecl - :: ( Contains [ScopedDecl] xs - , Contains Range xs - , Contains (Maybe Category) xs - ) + :: CanSearch xs => Range -> Pascal (Product xs) -> Maybe ScopedDecl @@ -32,10 +38,7 @@ findScopedDecl pos tree = do lookupEnv (ppToText $ void pt) filtered definitionOf - :: ( Contains [ScopedDecl] xs - , Contains Range xs - , Contains (Maybe Category) xs - ) + :: CanSearch xs => Range -> Pascal (Product xs) -> Maybe Range @@ -43,10 +46,7 @@ definitionOf pos tree = _sdOrigin <$> findScopedDecl pos tree typeOf - :: ( Contains [ScopedDecl] xs - , Contains Range xs - , Contains (Maybe Category) xs - ) + :: CanSearch xs => Range -> Pascal (Product xs) -> Maybe (Either (Pascal ()) Kind) @@ -54,10 +54,7 @@ typeOf pos tree = _sdType =<< findScopedDecl pos tree implementationOf - :: ( Contains [ScopedDecl] xs - , Contains Range xs - , Contains (Maybe Category) xs - ) + :: CanSearch xs => Range -> Pascal (Product xs) -> Maybe Range @@ -65,10 +62,7 @@ implementationOf pos tree = _sdBody =<< findScopedDecl pos tree referencesOf - :: ( Contains [ScopedDecl] xs - , Contains Range xs - , Contains (Maybe Category) xs - ) + :: CanSearch xs => Range -> Pascal (Product xs) -> Maybe [Range] diff --git a/tools/lsp/squirrel/src/AST/Parser.hs b/tools/lsp/squirrel/src/AST/Parser.hs index 3600baa46..ce861c16f 100644 --- a/tools/lsp/squirrel/src/AST/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Parser.hs @@ -15,7 +15,8 @@ import Range import Product import Tree hiding (skip) --- import Debug.Trace +import Pretty +import Debug.Trace ranged :: ( Functor f @@ -779,11 +780,12 @@ letExpr = do -> Pascal ASTInfo -> Pascal ASTInfo -> Pascal ASTInfo - let'' r decl b = mk (Cons r' rest) $ Let decl b + let'' r decl b = + mk (Cons r' rest) $ Let decl b where r' = Range start end f Range _ end f = r - Cons (Range start _ _) rest = infoOf b + Cons (Range start _ _) rest = infoOf decl statement :: Parser (Pascal ASTInfo) statement = ranged do pure Action <*> expr @@ -913,12 +915,12 @@ example :: FilePath -- example = "../../../src/test/contracts/bytes_arithmetic.ligo" -- example = "../../../src/test/contracts/bytes_unpack.ligo" -- example = "../../../src/test/contracts/chain_id.ligo" --- example = "../../../src/test/contracts/coase.ligo" +example = "../../../src/test/contracts/coase.ligo" -- example = "../../../src/test/contracts/failwith.ligo" -- example = "../../../src/test/contracts/loop.ligo" -- example = "../../../src/test/contracts/redeclaration.ligo" -- example = "../../../src/test/contracts/includer.ligo" -- example = "../../../src/test/contracts/namespaces.ligo" -example = "../../../src/test/contracts/application.ligo" +-- example = "../../../src/test/contracts/blocks.ligo" -- example = "../../../src/test/contracts/application.ligo" -- example = "../../../src/test/contracts/application.ligo" diff --git a/tools/lsp/squirrel/src/AST/Scope.hs b/tools/lsp/squirrel/src/AST/Scope.hs index 58ca29b0c..f62d79f3a 100644 --- a/tools/lsp/squirrel/src/AST/Scope.hs +++ b/tools/lsp/squirrel/src/AST/Scope.hs @@ -220,6 +220,10 @@ instance Pretty ScopedDecl where instance Pretty Kind where pp _ = "TYPE" +instance Pretty Category where + pp Variable = "Variable" + pp Type = "Type" + -- | Search for a name inside a local scope. lookupEnv :: Text -> [ScopedDecl] -> Maybe ScopedDecl lookupEnv name = listToMaybe . filter ((name ==) . ppToText . _sdName) diff --git a/tools/lsp/squirrel/src/Tree.hs b/tools/lsp/squirrel/src/Tree.hs index a6ccd6c3e..3f1535f45 100644 --- a/tools/lsp/squirrel/src/Tree.hs +++ b/tools/lsp/squirrel/src/Tree.hs @@ -34,7 +34,7 @@ import Pretty import Error import Range --- import Debug.Trace +import Debug.Trace -- | A tree, where each layer is one of @layers@ `Functor`s. -- @@ -115,6 +115,9 @@ lookupTree . ( Apply Foldable fs , Apply Functor fs , HasRange info + -- , HasComments info + -- , Pretty1 (Sum fs) + -- , Pretty info ) => Range -> Tree fs info