Skip to content

Misc LSP server / fourslash testing improvements #1591

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Aug 15, 2025

  • Set the LSP stderr to t.Output(), which means tests will actually get logging.
  • Pass a context into the LSP server to control its lifetime.
  • Ensure we wait for the LS to close in tests, and log errors before the test fully exits.

I moved the main context all the way up to main, since eventually we'll plumb it downward to the other commands. The movement means the LSP tests are not watching signals (which was an oops and caused weirdness).

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 improves the testing infrastructure for the LSP server and fourslash tests by enhancing lifecycle management and logging capabilities. The changes focus on proper context handling, test cleanup, and error reporting.

Key changes:

  • Added context-based lifecycle management to the LSP server
  • Improved test logging by directing LSP stderr to test output
  • Enhanced test cleanup with proper LSP server shutdown and error handling

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/lsp/server.go Modified Run method to accept context parameter and removed signal handling
internal/fourslash/fourslash.go Added context management, improved error handling, and redirected LSP stderr to test output
cmd/tsgo/main.go Added signal context creation at main entry point
cmd/tsgo/lsp.go Updated runLSP to accept and pass context to server

select {
case <-ctx.Done():
// do nothing
case err := <-lspErrChan:
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

There's a potential race condition where the LSP server might complete before the test cleanup runs, causing the channel read to block indefinitely. Consider using a select with a timeout or making the channel read non-blocking with a default case.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

The channel is buffered above. And if the server never exits, that's a bug and the test should time out / report a deadlock.

@jakebailey

This comment was marked as outdated.

@jakebailey jakebailey marked this pull request as draft August 15, 2025 17:17
@jakebailey
Copy link
Member Author

No, I just caused a race. Will figure it out.

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