[vala/wip/ricotz/lsp: 3/13] langserver: Parse incomplete MethodCalls.



commit f163a0c5064c434854f11db82060e6991bea2829
Author: Princeton Ferro <princetonferro gmail com>
Date:   Mon Dec 23 21:15:02 2019 -0500

    langserver: Parse incomplete MethodCalls.

 vala/valamethodcall.vala |  5 +++++
 vala/valaparser.vala     | 23 +++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 1c6e2b404..95cc41a42 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -48,6 +48,11 @@ public class Vala.MethodCall : Expression {
 
        public bool is_chainup { get; private set; }
 
+       /**
+        * For language servers, the number of completed arguments from the left.
+        */
+       public int initial_argument_count { get; set; }
+
        private Expression _call;
 
        private List<Expression> argument_list = new ArrayList<Expression> ();
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index bc54dc80a..d44b61154 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -567,7 +567,19 @@ public class Vala.Parser : CodeVisitor {
                var list = new ArrayList<Expression> ();
                if (current () != TokenType.CLOSE_PARENS) {
                        do {
-                               list.add (parse_argument ());
+                               try {
+                                       list.add (parse_argument ());
+                               } catch (ParseError e) {
+                                       if (context.keep_going) {
+                                               report_parse_error (e);
+                                               // exit this loop, since language server uses
+                                               // number of correctly-supplied arguments from
+                                               // the left to determine which argument to complete
+                                               break;
+                                       } else {
+                                               throw e;        // rethrow
+                                       }
+                               }
                        } while (accept (TokenType.COMMA));
                }
                return list;
@@ -792,7 +804,13 @@ public class Vala.Parser : CodeVisitor {
        Expression parse_method_call (SourceLocation begin, Expression inner) throws ParseError {
                expect (TokenType.OPEN_PARENS);
                var arg_list = parse_argument_list ();
-               expect (TokenType.CLOSE_PARENS);
+               if (context.keep_going) {
+                       if (!accept (TokenType.CLOSE_PARENS)) {
+                               report_parse_error (new ParseError.SYNTAX ("expected %s".printf 
(TokenType.CLOSE_PARENS.to_string ())), false);
+                       }
+               } else {
+                       expect (TokenType.CLOSE_PARENS);
+               }
                var src = get_src (begin);
 
                var init_list = parse_object_initializer ();
@@ -816,6 +834,7 @@ public class Vala.Parser : CodeVisitor {
                        foreach (Expression arg in arg_list) {
                                expr.add_argument (arg);
                        }
+                       expr.initial_argument_count = arg_list.size;
                        return expr;
                }
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]