mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CodeCompletion] Implement completions in using declaration's specifier position
(cherry picked from commit 816ea9fda6)
This commit is contained in:
@@ -190,6 +190,7 @@ enum class CodeCompletionKeywordKind : uint8_t {
|
||||
enum class CompletionKind : uint8_t {
|
||||
None,
|
||||
Import,
|
||||
Using,
|
||||
UnresolvedMember,
|
||||
DotExpr,
|
||||
StmtOrExpr,
|
||||
|
||||
@@ -325,6 +325,8 @@ public:
|
||||
|
||||
void addImportModuleNames();
|
||||
|
||||
void addUsingSpecifiers();
|
||||
|
||||
SemanticContextKind getSemanticContext(const Decl *D,
|
||||
DeclVisibilityKind Reason,
|
||||
DynamicLookupInfo dynamicLookupInfo);
|
||||
|
||||
@@ -255,6 +255,10 @@ public:
|
||||
virtual void
|
||||
completeImportDecl(ImportPath::Builder &Path) {};
|
||||
|
||||
/// Complete the 'using' decl with supported specifiers.
|
||||
virtual void
|
||||
completeUsingDecl() {};
|
||||
|
||||
/// Complete unresolved members after dot.
|
||||
virtual void completeUnresolvedMember(CodeCompletionExpr *E,
|
||||
SourceLoc DotLoc) {};
|
||||
|
||||
@@ -283,6 +283,7 @@ public:
|
||||
|
||||
void completePoundAvailablePlatform() override;
|
||||
void completeImportDecl(ImportPath::Builder &Path) override;
|
||||
void completeUsingDecl() override;
|
||||
void completeUnresolvedMember(CodeCompletionExpr *E,
|
||||
SourceLoc DotLoc) override;
|
||||
void completeCallArg(CodeCompletionExpr *E) override;
|
||||
@@ -550,6 +551,11 @@ void CodeCompletionCallbacksImpl::completeImportDecl(
|
||||
Path.pop_back();
|
||||
}
|
||||
|
||||
void CodeCompletionCallbacksImpl::completeUsingDecl() {
|
||||
Kind = CompletionKind::Using;
|
||||
CurDeclContext = P.CurDeclContext;
|
||||
}
|
||||
|
||||
void CodeCompletionCallbacksImpl::completeUnresolvedMember(CodeCompletionExpr *E,
|
||||
SourceLoc DotLoc) {
|
||||
Kind = CompletionKind::UnresolvedMember;
|
||||
@@ -990,6 +996,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
|
||||
case CompletionKind::AttributeBegin:
|
||||
case CompletionKind::PoundAvailablePlatform:
|
||||
case CompletionKind::Import:
|
||||
case CompletionKind::Using:
|
||||
case CompletionKind::UnresolvedMember:
|
||||
case CompletionKind::AfterPoundExpr:
|
||||
case CompletionKind::AfterPoundDirective:
|
||||
@@ -1915,7 +1922,10 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
|
||||
Lookup.addImportModuleNames();
|
||||
break;
|
||||
}
|
||||
|
||||
case CompletionKind::Using: {
|
||||
Lookup.addUsingSpecifiers();
|
||||
break;
|
||||
}
|
||||
case CompletionKind::AfterPoundDirective: {
|
||||
addPoundDirectives(CompletionContext.getResultSink());
|
||||
|
||||
|
||||
@@ -315,6 +315,7 @@ ContextFreeCodeCompletionResult::getCodeCompletionDeclKind(const Decl *D) {
|
||||
case DeclKind::OpaqueType:
|
||||
case DeclKind::BuiltinTuple:
|
||||
case DeclKind::MacroExpansion:
|
||||
case DeclKind::Using:
|
||||
llvm_unreachable("not expecting such a declaration result");
|
||||
case DeclKind::Module:
|
||||
return CodeCompletionDeclKind::Module;
|
||||
|
||||
@@ -387,6 +387,23 @@ void CompletionLookup::addImportModuleNames() {
|
||||
}
|
||||
}
|
||||
|
||||
void CompletionLookup::addUsingSpecifiers() {
|
||||
for (unsigned i = 0,
|
||||
n = static_cast<unsigned>(UsingSpecifier::LastSpecifier) + 1;
|
||||
i != n; ++i) {
|
||||
CodeCompletionResultBuilder Builder = makeResultBuilder(
|
||||
CodeCompletionResultKind::Keyword, SemanticContextKind::None);
|
||||
switch (static_cast<UsingSpecifier>(i)) {
|
||||
case UsingSpecifier::MainActor:
|
||||
Builder.addTextChunk("@MainActor");
|
||||
break;
|
||||
case UsingSpecifier::nonisolated:
|
||||
Builder.addTextChunk("nonisolated");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SemanticContextKind
|
||||
CompletionLookup::getSemanticContext(const Decl *D, DeclVisibilityKind Reason,
|
||||
DynamicLookupInfo dynamicLookupInfo) {
|
||||
|
||||
@@ -489,6 +489,8 @@ swiftide_completion_result_get_kind(swiftide_completion_response_t _response) {
|
||||
return SWIFTIDE_COMPLETION_KIND_NONE;
|
||||
case CompletionKind::Import:
|
||||
return SWIFTIDE_COMPLETION_KIND_IMPORT;
|
||||
case CompletionKind::Using:
|
||||
return SWIFTIDE_COMPLETION_KIND_USING;
|
||||
case CompletionKind::UnresolvedMember:
|
||||
return SWIFTIDE_COMPLETION_KIND_UNRESOLVEDMEMBER;
|
||||
case CompletionKind::DotExpr:
|
||||
|
||||
@@ -123,6 +123,7 @@ typedef enum swiftide_completion_kind_t: uint32_t {
|
||||
SWIFTIDE_COMPLETION_KIND_TYPEPOSSIBLEFUNCTIONPARAMBEGINNING = 42,
|
||||
SWIFTIDE_COMPLETION_KIND_TYPEATTRINHERITANCEBEGINNING = 43,
|
||||
SWIFTIDE_COMPLETION_KIND_TYPESIMPLEINVERTED = 44,
|
||||
SWIFTIDE_COMPLETION_KIND_USING = 45,
|
||||
} swiftide_completion_kind_t;
|
||||
|
||||
typedef enum swiftide_completion_item_kind_t: uint32_t {
|
||||
|
||||
Reference in New Issue
Block a user