[Lldb-commits] [lldb] r341124 - Use a CompletionRequest in the expression command completion [NFC]

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 30 14:26:32 PDT 2018


Author: teemperor
Date: Thu Aug 30 14:26:32 2018
New Revision: 341124

URL: http://llvm.org/viewvc/llvm-project?rev=341124&view=rev
Log:
Use a CompletionRequest in the expression command completion [NFC]

The patch was originally written before we had a CompletionRequest,
so it still used a StringList to pass back the completions to
the request.

Modified:
    lldb/trunk/include/lldb/Expression/ExpressionParser.h
    lldb/trunk/include/lldb/Expression/UserExpression.h
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h

Modified: lldb/trunk/include/lldb/Expression/ExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionParser.h?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ExpressionParser.h (original)
+++ lldb/trunk/include/lldb/Expression/ExpressionParser.h Thu Aug 30 14:26:32 2018
@@ -10,6 +10,7 @@
 #ifndef liblldb_ExpressionParser_h_
 #define liblldb_ExpressionParser_h_
 
+#include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-private-enumerations.h"
 #include "lldb/lldb-public.h"
@@ -53,8 +54,8 @@ public:
   /// Attempts to find possible command line completions for the given
   /// expression.
   ///
-  /// @param[out] matches
-  ///     The list of completions that should be appended with string
+  /// @param[out] request
+  ///     The completion request to fill out. The completion should be a string
   ///     that would complete the current token at the cursor position.
   ///     Note that the string in the list replaces the current token
   ///     in the command line.
@@ -81,7 +82,7 @@ public:
   ///     True if we added any completion results to the output;
   ///     false otherwise.
   //------------------------------------------------------------------
-  virtual bool Complete(StringList &matches, unsigned line, unsigned pos,
+  virtual bool Complete(CompletionRequest &request, unsigned line, unsigned pos,
                         unsigned typed_pos) = 0;
 
   //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Expression/UserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/UserExpression.h?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/UserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/UserExpression.h Thu Aug 30 14:26:32 2018
@@ -121,7 +121,7 @@ public:
   ///     True if we added any completion results to the output;
   ///     false otherwise.
   //------------------------------------------------------------------
-  virtual bool Complete(ExecutionContext &exe_ctx, StringList &matches,
+  virtual bool Complete(ExecutionContext &exe_ctx, CompletionRequest &request,
                         unsigned complete_pos) {
     return false;
   }

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Aug 30 14:26:32 2018
@@ -369,9 +369,7 @@ int CommandObjectExpression::HandleCompl
   if (error.Fail())
     return 0;
 
-  StringList matches;
-  expr->Complete(exe_ctx, matches, cursor_pos);
-  request.AddCompletions(matches);
+  expr->Complete(exe_ctx, request, cursor_pos);
   return request.GetNumberOfMatches();
 }
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Thu Aug 30 14:26:32 2018
@@ -563,7 +563,7 @@ class CodeComplete : public CodeComplete
 
   std::string m_expr;
   unsigned m_position = 0;
-  StringList &m_matches;
+  CompletionRequest &m_request;
 
   /// Returns true if the given character can be used in an identifier.
   /// This also returns true for numbers because for completion we usually
@@ -638,10 +638,10 @@ public:
   /// @param[out] position
   ///    The character position of the user cursor in the `expr` parameter.
   ///
-  CodeComplete(StringList &matches, std::string expr, unsigned position)
+  CodeComplete(CompletionRequest &request, std::string expr, unsigned position)
       : CodeCompleteConsumer(CodeCompleteOptions(), false),
         m_info(std::make_shared<GlobalCodeCompletionAllocator>()), m_expr(expr),
-        m_position(position), m_matches(matches) {}
+        m_position(position), m_request(request) {}
 
   /// Deregisters and destroys this code-completion consumer.
   virtual ~CodeComplete() {}
@@ -735,7 +735,7 @@ public:
         // with the kind of result the lldb API expects.
         std::string CompletionSuggestion =
             mergeCompletion(m_expr, m_position, ToInsert);
-        m_matches.AppendString(CompletionSuggestion);
+        m_request.AddCompletion(CompletionSuggestion);
       }
     }
   }
@@ -763,7 +763,7 @@ public:
 };
 } // namespace
 
-bool ClangExpressionParser::Complete(StringList &matches, unsigned line,
+bool ClangExpressionParser::Complete(CompletionRequest &request, unsigned line,
                                      unsigned pos, unsigned typed_pos) {
   DiagnosticManager mgr;
   // We need the raw user expression here because that's what the CodeComplete
@@ -773,7 +773,7 @@ bool ClangExpressionParser::Complete(Str
   // the LLVMUserExpression which exposes the right API. This should never fail
   // as we always have a ClangUserExpression whenever we call this.
   LLVMUserExpression &llvm_expr = *static_cast<LLVMUserExpression *>(&m_expr);
-  CodeComplete CC(matches, llvm_expr.GetUserText(), typed_pos);
+  CodeComplete CC(request, llvm_expr.GetUserText(), typed_pos);
   // We don't need a code generator for parsing.
   m_code_generator.reset();
   // Start parsing the expression with our custom code completion consumer.

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h Thu Aug 30 14:26:32 2018
@@ -62,7 +62,7 @@ public:
   //------------------------------------------------------------------
   ~ClangExpressionParser() override;
 
-  bool Complete(StringList &matches, unsigned line, unsigned pos,
+  bool Complete(CompletionRequest &request, unsigned line, unsigned pos,
                 unsigned typed_pos) override;
 
   //------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Thu Aug 30 14:26:32 2018
@@ -643,7 +643,8 @@ static void AbsPosToLineColumnPos(unsign
 }
 
 bool ClangUserExpression::Complete(ExecutionContext &exe_ctx,
-                                   StringList &matches, unsigned complete_pos) {
+                                   CompletionRequest &request,
+                                   unsigned complete_pos) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
 
   // We don't want any visible feedback when completing an expression. Mostly
@@ -709,7 +710,7 @@ bool ClangUserExpression::Complete(Execu
   // The actual column where we have to complete is the start column of the
   // user expression + the offset inside the user code that we were given.
   const unsigned completion_column = user_expr_column + complete_pos;
-  parser.Complete(matches, user_expr_line, completion_column, complete_pos);
+  parser.Complete(request, user_expr_line, completion_column, complete_pos);
 
   return true;
 }

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h?rev=341124&r1=341123&r2=341124&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h Thu Aug 30 14:26:32 2018
@@ -143,7 +143,7 @@ public:
              lldb_private::ExecutionPolicy execution_policy,
              bool keep_result_in_memory, bool generate_debug_info) override;
 
-  bool Complete(ExecutionContext &exe_ctx, StringList &matches,
+  bool Complete(ExecutionContext &exe_ctx, CompletionRequest &request,
                 unsigned complete_pos) override;
 
   ExpressionTypeSystemHelper *GetTypeSystemHelper() override {




More information about the lldb-commits mailing list