Skip to content

[SourceKit][IDE] New SourceKit request to retrieve context type information #21377

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 11 commits into from
Jan 14, 2019

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Dec 17, 2018

This is a new SourceKit request which receives a position in the source file, returns possible expected types and their members which can be referenced by "implicit member expression" syntax.

rdar://problem/44698136

@rintaro rintaro requested a review from akyrtzi December 17, 2018 10:07
@akyrtzi akyrtzi requested a review from benlangmuir December 18, 2018 01:21
@benlangmuir
Copy link
Contributor

The name "context info" is fairly general; do you think "type context info" would work? Right now all the results are related to the semantic type of the context. On the other hand, if you foresee us adding non-type information here it might be misleading.

}
llvm::outs() << "found code completion token " << CodeCompletionToken
<< " at offset " << Offset << "\n";
llvm::errs() << "found code completion token " << CodeCompletionToken
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I wonder why we write this to both outs() and errs(). Seems silly. I guess it's fine to copy what code-completion does for now though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just copied from code-completion code.
I believe outs() is for FileCheck and errs() is to see which test case failed from failure log.

@rintaro
Copy link
Member Author

rintaro commented Dec 19, 2018

One possible enhancement in my mind is adding "kind" of context. Like

foo(x: #TOKEN#)  // -> call argument
return #TOKEN#   // -> return value
if #TOKEN# {     // -> statement condition

But I'm not sure it's valuable. And I think "type context info" still works even after adding it.
Let's change it to typecontextinfo.

Now that this passes all test cases we currently have. Stop analyzing
outer contexts because it may emit invalid context type.
We don't need to keep ExprFinder beyond analysis.
Just refactoring.
ExprContextInfo automatically construct analyzer and analyze().
This replaces shouldHideDeclFromCompletionResults() in IDE.
TypeContextInfo is for new SourceKit request which receives source
location, and returns context type and members which can be referenced
by "implicit member expression" syntax.

Implement that as a code completion callbacks.
@rintaro
Copy link
Member Author

rintaro commented Jan 10, 2019

@swift-ci Please smoke test

@rintaro rintaro changed the title [WIP][SourceKit][IDE] New SourceKit request to retrieve context type information [SourceKit][IDE] New SourceKit request to retrieve context type information Jan 10, 2019
This is a new SourceKit request which receives a position in the source
file, returns possible expected types and their members which can be
referenced by "implicit member expression" syntax.
@rintaro
Copy link
Member Author

rintaro commented Jan 10, 2019

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Jan 11, 2019

@benlangmuir @akyrtzi I think this PR is ready for reviewing.

@rintaro rintaro merged commit b446d6b into swiftlang:master Jan 14, 2019
@@ -2412,6 +2412,10 @@ class ValueDecl : public Decl {

bool isUsableFromInline() const;

/// Returns \c true if this declaration is *not* intended to be used directly
/// by application developers despite of the visibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"despite of" -> "despite", or "in spite of"

@@ -2550,6 +2550,34 @@ bool ValueDecl::isUsableFromInline() const {
return false;
}

/// Returns \c true if this declaration is *not* intended to be used directly
/// by application developers despite of the visibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually copy doc comments to the definition since then we have two places to keep up to date separately.

@@ -2116,7 +2049,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
void addVarDeclRef(const VarDecl *VD, DeclVisibilityKind Reason) {
if (!VD->hasName() ||
!VD->isAccessibleFrom(CurrDeclContext) ||
shouldHideDeclFromCompletionResults(VD))
VD->shouldHideFromEditor())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the function shouldHideDeclFromCompletionResults removed? I can't find it in this patch.


// Ignore callbacks for suffix completions
// {
void completeDotExpr(Expr *E, SourceLoc DotLoc) override{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: should have a space before {}.

}
CI.performSema();

return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should copy over the trace::TracedOperation code from code-completion as well so that this action shows up in compilation traces such as the Index Log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants