Skip to content

Port global completions #858

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 18 commits into from
May 14, 2025
Merged

Port global completions #858

merged 18 commits into from
May 14, 2025

Conversation

gabritto
Copy link
Member

This PR ports global completions, a.k.a. completions you get from symbols collected by tryGetGlobalSymbols.

@Copilot Copilot AI review requested due to automatic review settings May 12, 2025 15:22
@gabritto gabritto marked this pull request as draft May 12, 2025 15:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ports global completions by updating the logic to use the symbols gathered via tryGetGlobalSymbols. Key changes include:

  • Introducing the use of maps.Copy in scanner initialization.
  • Refactoring utility functions (e.g. in ls/utilities.go and symbol_display.go) and renaming some checker functions to their exported forms.
  • Adding a new test setup for processing marker ranges.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/scanner/scanner.go Uses maps.Copy to copy token text mappings during initialization.
internal/ls/utilities.go Adds and refactors helper functions for token scanning and child traversal.
internal/ls/symbol_display.go Modifies the logic determining local variable/function context.
internal/ls/testsetup.go Introduces new test setup and marker parsing functions.
internal/checker/* Renames several internal checker functions to exported forms and updates calls accordingly.
internal/astnav/tokens.go, internal/ast/* Adjustments to AST utilities and token visitor functions to support new patterns.
Comments suppressed due to low confidence (2)

internal/ls/symbol_display.go:290

  • The change from using 'continue' to 'break' in the loop over parent nodes may alter the original iteration logic used to determine local variable/function context. Please verify that breaking out of the loop upon encountering a SourceFile or ModuleBlock is the intended behavior for all cases.
for ; !ast.IsFunctionBlock(parent); parent = parent.Parent { if parent.Kind == ast.KindSourceFile || parent.Kind == ast.KindModuleBlock { break } }

internal/scanner/scanner.go:6

  • The introduction of maps.Copy to copy token mappings is a clean use of the new Go functionality; please ensure that our build and runtime environments support the required Go version.
import (
	"fmt"
	"iter"
	"maps"
	"strconv"

@gabritto gabritto force-pushed the gabritto/globalcompletion branch from 263cc4d to a101a6e Compare May 12, 2025 16:11
@gabritto gabritto marked this pull request as ready for review May 12, 2025 16:33
@andrewbranch
Copy link
Member

Are there any notable deviations from Strada that should get special attention in a code review?

@gabritto
Copy link
Member Author

Are there any notable deviations from Strada that should get special attention in a code review?

Good question. I don't think there are any for this PR, at least not that I can think of. I'll try to keep that in mind and call it out on future PRs.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

I think that something must be missing from the response; I'm doing global completions and VS Code is saying that there aren't any matches:

image

@@ -333,7 +333,7 @@ func (c *Checker) narrowTypeByAssertion(f *FlowState, t *Type, expr *ast.Node) *
return c.narrowTypeByAssertion(f, c.narrowTypeByAssertion(f, t, node.AsBinaryExpression().Left), node.AsBinaryExpression().Right)
}
if node.AsBinaryExpression().OperatorToken.Kind == ast.KindBarBarToken {
return c.getUnionType([]*Type{c.narrowTypeByAssertion(f, t, node.AsBinaryExpression().Left), c.narrowTypeByAssertion(f, t, node.AsBinaryExpression().Right)})
return c.GetUnionType([]*Type{c.narrowTypeByAssertion(f, t, node.AsBinaryExpression().Left), c.narrowTypeByAssertion(f, t, node.AsBinaryExpression().Right)})
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but maybe we should just declare a new one and keep the existing calls internal to reduce the diff? Maybe it's pointless.

Copy link
Member

Choose a reason for hiding this comment

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

Though it is a lot of lines in this PR...

@gabritto
Copy link
Member Author

gabritto commented May 13, 2025

I think that something must be missing from the response; I'm doing global completions and VS Code is saying that there aren't any matches:

image

Yeah, for some reason the insert/replace positions are messed up I think, I don't know yet where the positions go wrong. I'll debug and update with a fix tomorrow.

Update: fixed by #866.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Before we merge this, I believe that @ahejlsberg wanted to see about not renaming the methods but instead declaring exported wrappers in a new file in the checker package. Would probably be good to do that now instead of churning back and forth.

@gabritto gabritto enabled auto-merge May 14, 2025 20:33
@gabritto gabritto added this pull request to the merge queue May 14, 2025
Merged via the queue into main with commit 29b98d2 May 14, 2025
23 checks passed
@gabritto gabritto deleted the gabritto/globalcompletion branch May 14, 2025 21:12
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.

None yet

4 participants