Skip to content

Conversation

@melnikalex
Copy link

Summary

Implements autocomplete support for the outer keyword in the pkl-intellij plugin.

Changes

  • New file: ComputeOuterType.kt - Computes the type of outer references by walking up the PSI tree to find the enclosing object scope
  • Modified: ComputeExprType.kt - Updated to use computeOuterType() instead of returning Type.Unknown for PklOuterExpr
  • Test: Added unit test test complete from outer in CompletionTest.kt

Implementation Details

The computeOuterType() function follows the same pattern as computeThisType():

  1. Walks up the PSI tree from the current element
  2. Identifies the immediate enclosing object (skip it)
  3. Continues to find the next enclosing object
  4. Returns the type of that outer object

This enables autocomplete to work when typing outer. inside nested object expressions, showing members of the enclosing scope.

Testing

  • All existing tests pass
  • New test case validates that outer. shows correct members (methods and properties) from the enclosing object
  • Manually tested with the example from the issue

Example Usage

class BirdSpec {
  name: String
  songs: Listing<Song>
  function generateSong(_tune: String): Song = new {
    tune = _tune
  }
}

peacock: BirdSpec = new {
  name = "peacock"
  songs {
    outer.generateSong("beep")  // autocomplete now works\!
  }
}

Implements type computation for the 'outer' keyword, allowing
autocomplete to work when accessing members of the enclosing object
scope.

Changes:
- Add ComputeOuterType.kt to compute the type of outer references
- Update ComputeExprType.kt to use computeOuterType() for outer
  expressions
- Add test case for outer completion in CompletionTest.kt

The implementation walks up the PSI tree to find the immediate
enclosing object, then continues to the next enclosing object
and returns its type, enabling proper member resolution.
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.

1 participant