From ba3c0a76d9341c5b8131411a9cffc897ecb82410 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Wed, 8 Jul 2020 18:55:11 +0400 Subject: [PATCH] Fix function stealing 'goto def's --- tools/lsp/squirrel/src/AST/Parser.hs | 27 ++++++++++++++------------- tools/lsp/squirrel/src/Parser.hs | 9 +++++++++ tools/lsp/squirrel/src/Range.hs | 4 ++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tools/lsp/squirrel/src/AST/Parser.hs b/tools/lsp/squirrel/src/AST/Parser.hs index f3920a3ad..7c9628dfc 100644 --- a/tools/lsp/squirrel/src/AST/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Parser.hs @@ -685,7 +685,7 @@ fun_call = do subtree "fun_call" do ranged do pure Apply - <*> ranged do pure Ident <*> inside "f" function_id + <*> inside "f" function_id <*> inside "arguments" arguments arguments :: Parser [Pascal ASTInfo] @@ -694,16 +694,17 @@ arguments = many do inside "argument" expr function_id :: Parser (Pascal ASTInfo) -function_id = select - [ qname - , do - subtree "module_field" do - ranged do - pure QualifiedName - <*> inside "module" capitalName - <*> do pure <$> ranged do - pure At <*> inside "method" do name <|> name' - ] +function_id = ranged do + pure Ident <*> select + [ qname + , do + subtree "module_field" do + ranged do + pure QualifiedName + <*> inside "module" capitalName + <*> do pure <$> ranged do + pure At <*> inside "method" do name <|> name' + ] opCall :: Parser (Pascal ASTInfo) opCall = do @@ -848,7 +849,7 @@ typeTuple = do -- example = "../../../src/test/contracts/amount.ligo" -- example = "../../../src/test/contracts/annotation.ligo" -- example = "../../../src/test/contracts/arithmetic.ligo" --- example = "../../../src/test/contracts/assign.ligo" +example = "../../../src/test/contracts/assign.ligo" -- example = "../../../src/test/contracts/attributes.ligo" -- example = "../../../src/test/contracts/bad_timestamp.ligo" -- example = "../../../src/test/contracts/bad_type_operator.ligo" @@ -864,7 +865,7 @@ typeTuple = do -- 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/includer.ligo" -- example = "../../../src/test/contracts/application.ligo" -- example = "../../../src/test/contracts/application.ligo" -- example = "../../../src/test/contracts/application.ligo" diff --git a/tools/lsp/squirrel/src/Parser.hs b/tools/lsp/squirrel/src/Parser.hs index 7d9dcb677..330b1b036 100644 --- a/tools/lsp/squirrel/src/Parser.hs +++ b/tools/lsp/squirrel/src/Parser.hs @@ -36,6 +36,7 @@ module Parser ( -- * Parser type Parser , runParser + , runParser' , debugParser -- * Combinators @@ -62,6 +63,8 @@ module Parser -- * Comments and ranges , ASTInfo(..) + , Source(..) + , module ParseTree ) where import Control.Monad.Writer hiding (Product) @@ -117,6 +120,12 @@ runParser parser fin = do (Cons Set.empty Nil))) +runParser' + :: Parser a + -> Source + -> IO a +runParser' parser fin = fst <$> runParser parser fin + restart :: Stubbed a ASTInfo => Parser a -> FilePath -> Parser a restart p fin = do dir <- get' @FilePath diff --git a/tools/lsp/squirrel/src/Range.hs b/tools/lsp/squirrel/src/Range.hs index cb7eb95d5..d2d2f36b7 100644 --- a/tools/lsp/squirrel/src/Range.hs +++ b/tools/lsp/squirrel/src/Range.hs @@ -7,6 +7,7 @@ module Range , HasRange(..) , diffRange , cutOut + , point ) where @@ -21,6 +22,9 @@ import Pretty import Lattice import Product +point :: Int -> Int -> Range +point l c = Range (l, c, 0) (l, c, 0) "" + -- | A continious location in text. data Range = Range { rStart :: (Int, Int, Int) -- ^ [Start: line, col, byte-offset...