[cfe-commits] r110319 - in /cfe/trunk: include/clang-c/Index.h include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/c-index-test/c-index-test.c tools/libclang/CIndexCodeCompletion.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports
Douglas Gregor
dgregor at apple.com
Thu Aug 5 02:09:24 PDT 2010
Author: dgregor
Date: Thu Aug 5 04:09:23 2010
New Revision: 110319
URL: http://llvm.org/viewvc/llvm-project?rev=110319&view=rev
Log:
Give clang_codeCompleteAt() an "options" parameter, and add a new
flags enumeration + default-generating function that allows
code-completion to be customized via the libclang API.
Plus, turn on spell-checking when performing code completion.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/libclang.darwin.exports
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 5 04:09:23 2010
@@ -2079,6 +2079,33 @@
unsigned complete_column);
/**
+ * \brief Flags that can be passed to \c clang_codeCompleteAt() to
+ * modify its behavior.
+ *
+ * The enumerators in this enumeration can be bitwise-OR'd together to
+ * provide multiple options to \c clang_codeCompleteAt().
+ */
+enum CXCodeComplete_Flags {
+ /**
+ * \brief Whether to include macros within the set of code
+ * completions returned.
+ */
+ CXCodeComplete_IncludeMacros = 0x01,
+
+ /**
+ * \brief Whether to include code patterns for language constructs
+ * within the set of code completions, e.g., for loops.
+ */
+ CXCodeComplete_IncludeCodePatterns = 0x02
+};
+
+/**
+ * \brief Returns a default set of code-completion options that can be
+ * passed to\c clang_codeCompleteAt().
+ */
+CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
+
+/**
* \brief Perform code completion at a given location in a translation unit.
*
* This function performs code completion at a particular file, line, and
@@ -2135,6 +2162,12 @@
* \param num_unsaved_files The number of unsaved file entries in \p
* unsaved_files.
*
+ * \param options Extra options that control the behavior of code
+ * completion, expressed as a bitwise OR of the enumerators of the
+ * CXCodeComplete_Flags enumeration. The
+ * \c clang_defaultCodeCompleteOptions() function returns a default set
+ * of code-completion options.
+ *
* \returns If successful, a new \c CXCodeCompleteResults structure
* containing code-completion results, which should eventually be
* freed with \c clang_disposeCodeCompleteResults(). If code
@@ -2146,7 +2179,8 @@
unsigned complete_line,
unsigned complete_column,
struct CXUnsavedFile *unsaved_files,
- unsigned num_unsaved_files);
+ unsigned num_unsaved_files,
+ unsigned options);
/**
* \brief Free the given set of code-completion results.
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Aug 5 04:09:23 2010
@@ -389,16 +389,24 @@
/// \brief Perform code completion at the given file, line, and
/// column within this translation unit.
///
- /// \brief File The file in which code completion will occur.
- /// \brief Line The line at which code completion will occur.
- /// \brief Column The column at which code completion will occur.
- /// \brief Consumer The consumer that will receive code-completion results.
+ /// \param File The file in which code completion will occur.
+ ///
+ /// \param Line The line at which code completion will occur.
+ ///
+ /// \param Column The column at which code completion will occur.
+ ///
+ /// \param IncludeMacros Whether to include macros in the code-completion
+ /// results.
+ ///
+ /// \param IncludeCodePatterns Whether to include code patterns (such as a
+ /// for loop) in the code-completion results.
///
/// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, and
/// StoredDiagnostics parameters are all disgusting hacks. They will
/// go away.
void CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
RemappedFile *RemappedFiles, unsigned NumRemappedFiles,
+ bool IncludeMacros, bool IncludeCodePatterns,
CodeCompleteConsumer &Consumer,
Diagnostic &Diag, LangOptions &LangOpts,
SourceManager &SourceMgr, FileManager &FileMgr,
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Aug 5 04:09:23 2010
@@ -1154,6 +1154,8 @@
void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
+ bool IncludeMacros,
+ bool IncludeCodePatterns,
CodeCompleteConsumer &Consumer,
Diagnostic &Diag, LangOptions &LangOpts,
SourceManager &SourceMgr, FileManager &FileMgr,
@@ -1164,13 +1166,18 @@
CompilerInvocation CCInvocation(*Invocation);
FrontendOptions &FrontendOpts = CCInvocation.getFrontendOpts();
PreprocessorOptions &PreprocessorOpts = CCInvocation.getPreprocessorOpts();
-
- FrontendOpts.ShowMacrosInCodeCompletion = 1;
- FrontendOpts.ShowCodePatternsInCodeCompletion = 1;
+
+ FrontendOpts.ShowMacrosInCodeCompletion = IncludeMacros;
+ FrontendOpts.ShowCodePatternsInCodeCompletion = IncludeCodePatterns;
FrontendOpts.CodeCompletionAt.FileName = File;
FrontendOpts.CodeCompletionAt.Line = Line;
FrontendOpts.CodeCompletionAt.Column = Column;
+ // Turn on spell-checking when performing code completion. It leads
+ // to better results.
+ unsigned SpellChecking = CCInvocation.getLangOpts().SpellChecking;
+ CCInvocation.getLangOpts().SpellChecking = 1;
+
// Set the language options appropriately.
LangOpts = CCInvocation.getLangOpts();
@@ -1235,4 +1242,5 @@
Clang.takeInvocation();
Clang.takeDiagnosticClient();
Clang.takeCodeCompletionConsumer();
+ CCInvocation.getLangOpts().SpellChecking = SpellChecking;
}
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Aug 5 04:09:23 2010
@@ -896,7 +896,8 @@
num_unsaved_files,
getDefaultParsingOptions());
results = clang_codeCompleteAt(TU, filename, line, column,
- unsaved_files, num_unsaved_files);
+ unsaved_files, num_unsaved_files,
+ clang_defaultCodeCompleteOptions());
} else
results = clang_codeComplete(CIdx,
argv[argc - 1], argc - num_unsaved_files - 3,
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Thu Aug 5 04:09:23 2010
@@ -569,7 +569,8 @@
unsigned complete_line,
unsigned complete_column,
struct CXUnsavedFile *unsaved_files,
- unsigned num_unsaved_files) {
+ unsigned num_unsaved_files,
+ unsigned options) {
#ifdef UDP_CODE_COMPLETION_LOGGER
#ifdef UDP_CODE_COMPLETION_LOGGER_PORT
const llvm::TimeRecord &StartTime = llvm::TimeRecord::getCurrentTime();
@@ -611,7 +612,10 @@
// Perform completion.
AST->CodeComplete(complete_filename, complete_line, complete_column,
- RemappedFiles.data(), RemappedFiles.size(), Capture,
+ RemappedFiles.data(), RemappedFiles.size(),
+ (options & CXCodeComplete_IncludeMacros),
+ (options & CXCodeComplete_IncludeCodePatterns),
+ Capture,
*Results->Diag, Results->LangOpts, Results->SourceMgr,
Results->FileMgr, Results->Diagnostics);
@@ -692,6 +696,10 @@
return Results;
}
+unsigned clang_defaultCodeCompleteOptions(void) {
+ return CXCodeComplete_IncludeMacros;
+}
+
void clang_disposeCodeCompleteResults(CXCodeCompleteResults *ResultsIn) {
if (!ResultsIn)
return;
Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Thu Aug 5 04:09:23 2010
@@ -13,6 +13,7 @@
_clang_createIndex
_clang_createTranslationUnit
_clang_createTranslationUnitFromSourceFile
+_clang_defaultCodeCompleteOptions
_clang_defaultDiagnosticDisplayOptions
_clang_disposeCodeCompleteResults
_clang_disposeDiagnostic
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=110319&r1=110318&r2=110319&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 5 04:09:23 2010
@@ -13,6 +13,7 @@
clang_createIndex
clang_createTranslationUnit
clang_createTranslationUnitFromSourceFile
+clang_defaultCodeCompleteOptions
clang_defaultDiagnosticDisplayOptions
clang_disposeCodeCompleteResults
clang_disposeDiagnostic
More information about the cfe-commits
mailing list