Commit Graph

80 Commits

Author SHA1 Message Date
Douglas Gregor 52ce62f069 Improve the sorting of code-completion results. We now always sort by
the "typed" text, first, then take into account
nested-name-specifiers, name hiding, etc. This means that the
resulting sort is actually alphabetical :)

llvm-svn: 93370
2010-01-13 23:24:38 +00:00
Douglas Gregor 504a6ae83e Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for

  static_cast<type>(expr)

when we can have an expression, or

  using namespace identifier;

when we can have a using directive.

Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.

llvm-svn: 93134
2010-01-10 23:08:15 +00:00
Douglas Gregor b3fa919c2d Extend code-completion results with the type of each result
llvm-svn: 91702
2009-12-18 18:53:37 +00:00
Jeffrey Yasskin 1615d45daa Un-namespace-qualify llvm_unreachable. It's a macro, so the qualification gave
no extra safety anyway.

llvm-svn: 91207
2009-12-12 05:05:38 +00:00
Douglas Gregor f09935f16c Switch the clang-to-CIndex interface for code-completion to a binary format, for a massive speedup
llvm-svn: 90209
2009-12-01 05:55:20 +00:00
Benjamin Kramer 337e3a5fea Remove remaining VISIBILITY_HIDDEN from anonymous namespaces.
llvm-svn: 90044
2009-11-28 19:45:26 +00:00
Douglas Gregor 45f83ee87d Improve code-completion results for the flags in an @property
declaration by providing patterns for "getter = <method>" and "setter
= <method>". As part of this, invented a new "pattern" result kind
that is merely a semantic string. The "pattern" result kind should
help with other kinds of code templates.

llvm-svn: 89277
2009-11-19 00:01:57 +00:00
Douglas Gregor ab6ccb5f88 StringRef'ify CodeCompletionString
llvm-svn: 89102
2009-11-17 16:43:05 +00:00
Daniel Dunbar 242ea9a05a Rework Sema code completion interface.
- Provide Sema in callbacks, instead of requiring it in constructor. This
   eliminates the need for a factory function. Clients now just pass the object
   to consume the results in directly.

 - CodeCompleteConsumer is cheap to construct, so building it whenever we are
   doing code completion is reasonable.

Doug, please review.

llvm-svn: 87099
2009-11-13 08:58:20 +00:00
Daniel Dunbar b0a1942196 Spell empty StringRef correctly (0 is a null StringRef, which is not the same).
llvm-svn: 87011
2009-11-12 18:40:12 +00:00
Douglas Gregor 9eb7701dff Various improvements to Clang's code-completion infrastructure:
- Introduce more code-completion string "chunk" kinds that describe
  symbols, the actual text that the user is expected to type, etc.
  - Make the generation of macro results optional, since it can be
  slow
  - Make code-completion accessible through the C API, marshalling the
  code-completion results through a temporary file (ick) to maintain
  process separation.

The last doesn't have tests yet.

llvm-svn: 86306
2009-11-07 00:00:49 +00:00
Douglas Gregor f329c7c3c0 Include macros in code-completion results
llvm-svn: 85594
2009-10-30 16:50:04 +00:00
Douglas Gregor 58acf32af2 Minor tweaks for code-completion:
- Filter out unnamed declarations
  - Filter out declarations whose names are reserved for the
  implementation (e.g., __bar, _Foo) 
  - Place OVERLOAD: or COMPLETION: at the beginning of each
  code-completion result, so we can easily separate them from other
  compilation results.

llvm-svn: 83680
2009-10-09 22:16:47 +00:00
Douglas Gregor 78f0fa518c Make sure to flush raw_string_ostream, from John Thompson
llvm-svn: 83066
2009-09-29 15:13:39 +00:00
Douglas Gregor f0f51985a1 Print the results of code-completion for overloading by displaying the
signature of the function with the current parameter highlighted as a
placeholder.

llvm-svn: 82593
2009-09-23 00:34:09 +00:00
Douglas Gregor 05f477c177 Separate the code-completion results for call completion from the
results for other, textual completion. For call completion, we now
produce enough information to show the function call argument that we
are currently on.

llvm-svn: 82592
2009-09-23 00:16:58 +00:00
Douglas Gregor 5bf52697b0 Tweak the code-completion results ranking and formation, so that
members found in base classes have the same ranking as members found
in derived classes. However, we will introduce an informative note for
members found in base classes, showing (as a nested-name-specifier)
the qualification to name the base class, to make it clear which
members are from bases.
 

llvm-svn: 82586
2009-09-22 23:15:58 +00:00
Douglas Gregor 3545ff43f4 Refactor and simplify the CodeCompleteConsumer, so that all of the
real work is performed within Sema. Addresses Chris's comments, but
still retains the heavyweight list-of-multimaps data structure.

llvm-svn: 82459
2009-09-21 16:56:56 +00:00
Douglas Gregor b5c738b434 In C++ code completion, only suggest the "template" keyword after ".",
"->", or "::" if we will be looking into a dependent context. It's not
wrong to use the "template" keyword, but it's to needed, either.

llvm-svn: 82307
2009-09-18 23:55:56 +00:00
Douglas Gregor ce23bae4f8 Make the construction of the code-completion string for a function
template smarter, by taking into account which function template
parameters are deducible from the call arguments. For example,

  template<typename RandomAccessIterator>
  void sort(RandomAccessIterator first, RandomAccessIterator last);

will have a code-completion string like

  sort({RandomAccessIterator first}, {RandomAccessIterator last})

since the template argument for its template parameter is
deducible. On the other hand,

  template<class X, class Y>
  X* dyn_cast(Y *Val);

will have a code-completion string like

  dyn_cast<{class X}>({Y *Val})

since the template type parameter X is not deducible from the function
call.

llvm-svn: 82306
2009-09-18 23:21:38 +00:00
Douglas Gregor 3f6ca38927 Introduce code completion patterns for templates, which provide the
angle brackets < > along with placeholder template arguments.

llvm-svn: 82304
2009-09-18 22:47:56 +00:00
Douglas Gregor fedc328ae9 Introduce code completion strings, which describe how to *use* the
results of code completion, e.g., by providing function call syntax
with placeholders for each of the parameters.

llvm-svn: 82293
2009-09-18 22:15:54 +00:00
Douglas Gregor c811ede9b7 C++ code completion after the "operator" keyword. Provide overloaded
operators, type specifiers, type names, and nested-name-specifiers.

llvm-svn: 82264
2009-09-18 20:05:18 +00:00
Douglas Gregor 7e90c6db18 Introduce four new code-completion hooks for C++:
- after "using", show anything that can be a nested-name-specifier.
  - after "using namespace", show any visible namespaces or namespace aliases
  - after "namespace", show any namespace definitions in the current scope
  - after "namespace identifier = ", show any visible namespaces or
    namespace aliases

llvm-svn: 82251
2009-09-18 19:03:04 +00:00
Douglas Gregor 2ecab75739 Don't perform name lookup into a given declaration context more than once during code completion
llvm-svn: 82234
2009-09-18 18:07:23 +00:00
Douglas Gregor 56c2dbcfe7 Handle using declarations and overload sets in code completion.
llvm-svn: 82233
2009-09-18 17:54:00 +00:00
Douglas Gregor 945e8d9762 For code completion in C++ member access expressions and tag names,
look into the current scope for anything that could start a
nested-names-specifier. These results are ranked worse than any of the
results actually found in the lexical scope.

Perform a little more pruning of the result set, eliminating
constructors, __va_list_tag, and any duplication of declarations in
the result set. For the latter, implemented
NamespaceDecl::getCanonicalDecl.

llvm-svn: 82231
2009-09-18 17:42:29 +00:00
Douglas Gregor 2da11086f3 When gathering results for code completion, only include hidden
results when there is some way to refer to them in the language, such
as with a qualified name in C++.

llvm-svn: 82223
2009-09-18 15:51:54 +00:00
Douglas Gregor f45b0cf389 Implement code completion for tags, e.g., code completion after "enum"
will provide the names of various enumerations currently
visible. Introduced filtering of code-completion results when we build
the result set, so that we can identify just the kinds of declarations
we want.

This implementation is incomplete for C++, since we don't consider
that the token after the tag keyword could start a
nested-name-specifier. 

llvm-svn: 82222
2009-09-18 15:37:17 +00:00
Douglas Gregor 2436e7116b Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.

Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.

This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.

[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".

llvm-svn: 82166
2009-09-17 21:32:03 +00:00