Skip to content

Make projecttestutil.Setup generic, avoid casts. #1353

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 1 commit into from
Jul 3, 2025

Conversation

DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jul 2, 2025

Noticed the use of map[string]any in #1339, thought it was kind of fishy.

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 generalizes the projecttestutil.Setup and its helper to accept a map of any file-content type, and updates all existing tests to use map[string]string instead of map[string]any, removing the need for type assertions.

  • Make Setup and newProjectServiceHost generic over file content type.
  • Change all test files to use map[string]string and drop . (string) casts.
  • Ensure language/service tests pass with updated call signatures.

Reviewed Changes

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

Show a summary per file
File Description
internal/testutil/projecttestutil/projecttestutil.go Made Setup and newProjectServiceHost generic.
internal/project/service_test.go Switched from map[string]any to map[string]string.
internal/project/ata_test.go Switched from map[string]any to map[string]string.
internal/ls/signaturehelp_test.go Updated createLanguageService calls to use string maps.
internal/ls/findallreferences_test.go Same map[string]string update for references tests.
internal/ls/definition_test.go Updated definition tests to new map type.
internal/ls/completions_test.go Adjusted completions test helper to map[string]string.
Comments suppressed due to low confidence (2)

internal/testutil/projecttestutil/projecttestutil.go:89

  • [nitpick] Consider renaming the type parameter FileContents to a shorter conventional identifier like T or C to align with common Go generics style.
func Setup[FileContents any](files map[string]FileContents, testOptions *TestTypingsInstaller) (*project.Service, *ProjectServiceHost) {

internal/testutil/projecttestutil/projecttestutil.go:89

  • If only strings (or bytes) are supported for file contents, consider constraining FileContents to ~string or []byte to catch misuse at compile time.
func Setup[FileContents any](files map[string]FileContents, testOptions *TestTypingsInstaller) (*project.Service, *ProjectServiceHost) {

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Jul 3, 2025
Merged via the queue into main with commit 15def02 Jul 3, 2025
22 checks passed
@DanielRosenwasser DanielRosenwasser deleted the generics-wow branch July 3, 2025 02:39
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