mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Make object literals optional
For example, non-Darwin platforms probably don't want `#colorLiteral(red:green:blue":alpha:)` and `#imageLiteral(named:)`. Add an completion option to include them, which is "on" by default. rdar://75620636
This commit is contained in:
@@ -121,7 +121,7 @@ static bool swiftCodeCompleteImpl(
|
||||
unsigned Offset, SwiftCodeCompletionConsumer &SwiftConsumer,
|
||||
ArrayRef<const char *> Args,
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
|
||||
bool annotateDescription, std::string &Error) {
|
||||
const CodeCompletion::Options &opts, std::string &Error) {
|
||||
return Lang.performCompletionLikeOperation(
|
||||
UnresolvedInputFile, Offset, Args, FileSystem, Error,
|
||||
[&](CompilerInstance &CI, bool reusingASTContext) {
|
||||
@@ -130,7 +130,8 @@ static bool swiftCodeCompleteImpl(
|
||||
auto swiftCache = Lang.getCodeCompletionCache(); // Pin the cache.
|
||||
ide::CodeCompletionContext CompletionContext(swiftCache->getCache());
|
||||
CompletionContext.ReusingASTContext = reusingASTContext;
|
||||
CompletionContext.setAnnotateResult(annotateDescription);
|
||||
CompletionContext.setAnnotateResult(opts.annotatedDescription);
|
||||
CompletionContext.setIncludeObjectLiterals(opts.includeObjectLiterals);
|
||||
std::unique_ptr<CodeCompletionCallbacksFactory> callbacksFactory(
|
||||
ide::makeCodeCompletionCallbacksFactory(CompletionContext,
|
||||
SwiftConsumer));
|
||||
@@ -214,8 +215,7 @@ void SwiftLangSupport::codeComplete(
|
||||
|
||||
std::string Error;
|
||||
if (!swiftCodeCompleteImpl(*this, UnresolvedInputFile, Offset, SwiftConsumer,
|
||||
Args, fileSystem,
|
||||
CCOpts.annotatedDescription, Error)) {
|
||||
Args, fileSystem, CCOpts, Error)) {
|
||||
SKConsumer.failed(Error);
|
||||
}
|
||||
}
|
||||
@@ -728,6 +728,7 @@ static void translateCodeCompletionOptions(OptionsDictionary &from,
|
||||
static UIdent KeyFuzzyWeight("key.codecomplete.sort.fuzzyweight");
|
||||
static UIdent KeyPopularityBonus("key.codecomplete.sort.popularitybonus");
|
||||
static UIdent KeyAnnotatedDescription("key.codecomplete.annotateddescription");
|
||||
static UIdent KeyIncludeObjectLiterals("key.codecomplete.includeobjectliterals");
|
||||
|
||||
from.valueForOption(KeySortByName, to.sortByName);
|
||||
from.valueForOption(KeyUseImportDepth, to.useImportDepth);
|
||||
@@ -753,6 +754,7 @@ static void translateCodeCompletionOptions(OptionsDictionary &from,
|
||||
from.valueForOption(KeyHideByName, to.hideByNameStyle);
|
||||
from.valueForOption(KeyTopNonLiteral, to.showTopNonLiteralResults);
|
||||
from.valueForOption(KeyAnnotatedDescription, to.annotatedDescription);
|
||||
from.valueForOption(KeyIncludeObjectLiterals, to.includeObjectLiterals);
|
||||
}
|
||||
|
||||
/// Canonicalize a name that is in the format of a reference to a function into
|
||||
@@ -1023,7 +1025,7 @@ static void transformAndForwardResults(
|
||||
std::string error;
|
||||
if (!swiftCodeCompleteImpl(lang, buffer.get(), str.size(), swiftConsumer,
|
||||
cargs, session->getFileSystem(),
|
||||
options.annotatedDescription, error)) {
|
||||
options, error)) {
|
||||
consumer.failed(error);
|
||||
return;
|
||||
}
|
||||
@@ -1123,8 +1125,7 @@ void SwiftLangSupport::codeCompleteOpen(
|
||||
|
||||
// Invoke completion.
|
||||
if (!swiftCodeCompleteImpl(*this, inputBuf, offset, swiftConsumer,
|
||||
extendedArgs, fileSystem,
|
||||
CCOpts.annotatedDescription, error)) {
|
||||
extendedArgs, fileSystem, CCOpts, error)) {
|
||||
consumer.failed(error);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user