Skip to content

Commit

Permalink
Expand completion support for language server (chapel-lang#25991)
Browse files Browse the repository at this point in the history
This PR expands upon our existing completion support to be location
specific. Prior to this PR, only the module level scope was used to
provide completion symbols. This PR changes that, so that visible
symbols are computed based upon the users cursor.


With this PR, users will get an auto-complete suggestion of 'myVariable'
when 'myV' is typed.
```chapel
record myRecord {
  var  myVariable = 1;
  proc foo() {
    myV
  }
}
```

Implementation details

This PR uses the fact that the FileInfo visits nodes in order when
building segments. So in the above example, the scope for `myRecord` is
visited before `foo`. As each scope is entered, we keep track of the
location, its Scope object, and the parent scopes. This is precomputed
before a user ever requests a completion, so that when that occurs it is
just a simple lookup.

[Reviewed by @DanilaFe]
  • Loading branch information
jabraham17 authored Oct 21, 2024
2 parents 0dfd163 + 960f232 commit 8337447
Show file tree
Hide file tree
Showing 3 changed files with 405 additions and 63 deletions.
2 changes: 2 additions & 0 deletions tools/chapel-py/src/method-tables/uast-methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ CLASS_BEGIN(AstNode)
std::optional<ScopeObject*>,

return ScopeObject::tryCreate(contextObject, resolution::scopeForId(context, node->id())))
PLAIN_GETTER(AstNode, creates_scope, "Returns true if this AST node creates a scope",
bool, return chpl::resolution::createsScope(node->tag()))
PLAIN_GETTER(AstNode, type, "Get the type of this AST node, as a 3-tuple of (kind, type, param).",
std::optional<QualifiedTypeTuple>,

Expand Down
Loading

0 comments on commit 8337447

Please sign in to comment.