unsigned complete_line,
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.
*
* \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
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.
/// \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,
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,
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();
Clang.takeInvocation();
Clang.takeDiagnosticClient();
Clang.takeCodeCompletionConsumer();
+ CCInvocation.getLangOpts().SpellChecking = SpellChecking;
}
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,
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();
// 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);
return Results;
}
+unsigned clang_defaultCodeCompleteOptions(void) {
+ return CXCodeComplete_IncludeMacros;
+}
+
void clang_disposeCodeCompleteResults(CXCodeCompleteResults *ResultsIn) {
if (!ResultsIn)
return;
_clang_createIndex
_clang_createTranslationUnit
_clang_createTranslationUnitFromSourceFile
+_clang_defaultCodeCompleteOptions
_clang_defaultDiagnosticDisplayOptions
_clang_disposeCodeCompleteResults
_clang_disposeDiagnostic
clang_createIndex
clang_createTranslationUnit
clang_createTranslationUnitFromSourceFile
+clang_defaultCodeCompleteOptions
clang_defaultDiagnosticDisplayOptions
clang_disposeCodeCompleteResults
clang_disposeDiagnostic