Skip to content
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

chapel-py: fix "IDs available in scope" #24988

Merged
merged 11 commits into from
May 6, 2024

Conversation

DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented May 3, 2024

The doLookupInScope family of functions have special logic to introduce the symbol-to-be-imported into the search results. Specifically, use statements in the form use IO bring IO into scope in addition the symbols from IO. Prior to this PR, getSymbolsAvailableInScope did not handle this, assuming that iteration over scope->declared() was sufficient. This PR addresses that problem.

As a result, renaming modules now works properly with autocompletions in CLS, and the language server doesn't need to rely on findUsedImportedIds.

modulerename

Reviewed by @jabraham17 and @mppf -- thanks!

Testing

  • dyno tests
  • paratest

@DanilaFe DanilaFe marked this pull request as ready for review May 3, 2024 18:45
Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

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

Looks good. Could you please add a C++ test for getSymbolsAvailableInScope ? It'll be much easier to check that it's working correctly that way (make sure to check import Module.Item and use Module and use Module only Thing1 as Thing2). Also it'll be much easier to avoid future problems with the language server if we have a C++ test for this.

const IdAndFlags::FlagSet& excludeFilter,
const Scope* scope) {
auto scopeAst = parsing::idToAst(context, scope->id());
auto visibility = scopeAst->toDecl()->visibility();
Copy link
Member

Choose a reason for hiding this comment

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

I know you are just moving this code, but could you fix this issue with it?

It should use parsing::idIsPrivateDecl to avoid calling idToAst which is both slow and unlikely to be reusable from revision to revision

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't quite work because the argument expects a Visibility, not a boolean. But I'll add a new parsing query to retrieve the visibility.

Copy link
Member

@mppf mppf May 3, 2024

Choose a reason for hiding this comment

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

AFAIK, we don't need to distinguish here between default visibility and public. You could just write

auto visibility = idIsPrivateDecl(context, scope->id()) ? Decl::PRIVATE : Decl::Public

Distinguishing between public and default visibility is useful in the uAST but I can't imagine any reason it would matter in scope resolution (and in fact, if it does matter, it's probably a bug, because the default visibility is public).

Of course you could put this in a helper in parsing-queries.

if (kind == VisibilitySymbols::ONLY_CONTENTS ||
kind == VisibilitySymbols::CONTENTS_EXCEPT) {
auto& namePairs = inVisibilitySymbols->names();
// Should we even bother checking the names?
Copy link
Member

Choose a reason for hiding this comment

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

Maybe remove this comment? Checking the names seems reasonable to handle use X as Y etc. And it does check the names.

Copy link
Member

@jabraham17 jabraham17 left a comment

Choose a reason for hiding this comment

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

Just reviewing the changes in chpl-language-server.py, looks great

Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test! I think it'll really help us to maintain this functionality.


const ModuleVec& vec = parseToplevel(context, path);

checkScopeContents(context, vec[0], {"x", "f1", "f2"});
Copy link
Member

Choose a reason for hiding this comment

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

Arguably, it should also include M (but oddly enough, only for use in use / import). Also, arguably, it should include the included-by-default symbols. It's not important to me that it change behavior from what we have right now, but might be worth a comment here just to make updating the test easier.

Signed-off-by: Danila Fedorin <[email protected]>
@DanilaFe DanilaFe merged commit f51e663 into chapel-lang:main May 6, 2024
8 checks passed
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.

3 participants