Skip to content

[Parse][CodeCompletion] Completions for precedencegroup decls #17649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/AttrKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ enum class Associativity : uint8_t {
Right
};

/// Returns the in-source spelling of the given associativity.
StringRef getAssociativitySpelling(Associativity value);

/// The kind of unary operator, if any.
enum class UnaryOperatorKind : uint8_t {
None,
Expand Down
16 changes: 16 additions & 0 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
/// The order of the results is not guaranteed to be meaningful.
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const;

/// Finds all precedence group decls of this module.
///
/// This does a simple local lookup, not recursively looking through imports.
/// The order of the results is not guaranteed to be meaningful.
void getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const;

/// Finds all top-level decls that should be displayed to a client of this
/// module.
///
Expand Down Expand Up @@ -690,6 +696,13 @@ class FileUnit : public DeclContext {
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {}


/// Finds all precedence group decls in this file.
///
/// This does a simple local lookup, not recursively looking through imports.
/// The order of the results is not guaranteed to be meaningful.
virtual void
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {}

/// Finds all local type decls in this file.
///
/// This does a simple local lookup, not recursively looking through imports.
Expand Down Expand Up @@ -985,6 +998,9 @@ class SourceFile final : public FileUnit {

virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;

virtual void
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &results) const override;

virtual void
getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &results) const override;

Expand Down
4 changes: 3 additions & 1 deletion include/swift/IDE/CodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ enum class CompletionKind {
PlatformConditon,
AfterIfStmtElse,
GenericParams,
PrecedenceGroup,
};

/// \brief A single code completion result.
Expand Down Expand Up @@ -891,7 +892,8 @@ void lookupCodeCompletionResultsFromModule(CodeCompletionResultSink &targetSink,
/// restricting by \p onlyTypes.
void copyCodeCompletionResults(CodeCompletionResultSink &targetSink,
CodeCompletionResultSink &sourceSink,
bool onlyTypes);
bool onlyTypes,
bool onlyPrecedenceGroups);

} // end namespace ide
} // end namespace swift
Expand Down
1 change: 1 addition & 0 deletions include/swift/IDE/CodeCompletionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct RequestedCachedModule {
CodeCompletionCache::Key Key;
const ModuleDecl *TheModule;
bool OnlyTypes;
bool OnlyPrecedenceGroups;
};

} // end namespace ide
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Parse/CodeCompletionCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class CodeCompletionCallbacks {
/// @available.
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) = 0;

/// Complete within a precedence group decl or after a colon in an
/// operator decl.
virtual void completeInPrecedenceGroup(SyntaxKind SK) = 0;

/// Complete the platform names inside #available statements.
virtual void completePoundAvailablePlatform() = 0;

Expand Down
4 changes: 2 additions & 2 deletions include/swift/Parse/SyntaxParsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
/// are supported. See the implementation.
void createNodeInPlace(SyntaxKind Kind);

/// Squshing nodes from the back of the pending syntax list to a given syntax
/// collection kind. If there're no nodes can fit into the collection kind,
/// Squashing nodes from the back of the pending syntax list to a given syntax
/// collection kind. If there're no nodes that can fit into the collection kind,
/// this function does nothing. Otherwise, it creates a collection node in place
/// to contain all sequential suitable nodes from back.
void collectNodesInPlace(SyntaxKind ColletionKind);
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ class ModuleFile
/// Adds all top-level decls to the given vector.
void getTopLevelDecls(SmallVectorImpl<Decl*> &Results);

/// Adds all precedence groups to the given vector.
void getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results);

/// Adds all local type decls to the given vector.
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results);

Expand Down
3 changes: 3 additions & 0 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ class SerializedASTFile final : public LoadedFile {

virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;

virtual void
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const override;

virtual void
getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &results) const override;

Expand Down
9 changes: 9 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6062,6 +6062,15 @@ SourceRange DestructorDecl::getSourceRange() const {
return { getDestructorLoc(), getBody()->getEndLoc() };
}

StringRef swift::getAssociativitySpelling(Associativity value) {
switch (value) {
case Associativity::None: return "none";
case Associativity::Left: return "left";
case Associativity::Right: return "right";
}
llvm_unreachable("Unhandled Associativity in switch.");
}

PrecedenceGroupDecl *
PrecedenceGroupDecl::create(DeclContext *dc,
SourceLoc precedenceGroupLoc,
Expand Down
14 changes: 14 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,20 @@ void SourceFile::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
Results.append(Decls.begin(), Decls.end());
}

void ModuleDecl::getPrecedenceGroups(
SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {
FORWARD(getPrecedenceGroups, (Results));
}

void SourceFile::getPrecedenceGroups(
SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {
for (auto pair : PrecedenceGroups) {
if (pair.second.getPointer() && pair.second.getInt()) {
Results.push_back(pair.second.getPointer());
}
}
}

void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
Results.append(LocalTypeDecls.begin(), LocalTypeDecls.end());
}
Expand Down
Loading