Skip to content

Conversation

@ultmaster
Copy link
Contributor

Summary

  • add VS Code LSP server test suite covering diagnostics, hover and completion

Testing

  • npm test
  • npm run test-vscode (fails: ENOENT or large output)

https://chatgpt.com/codex/tasks/task_e_686242735268832e9463f9c2adbea89d

Copilot AI review requested due to automatic review settings June 30, 2025 08:08

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Completion Test Fails on Unexpected Return Types

The completion test (test('completion suggests attributes')) contains two related bugs:

  1. The result of vscode.commands.executeCommand('vscode.executeCompletionItemProvider') is incorrectly assumed to be a CompletionList with an items property. If the command returns CompletionItem[] or null/undefined, accessing .items will cause a runtime error.
  2. Within the mapping of completion item labels, item.label.label is accessed without ensuring item.label is an object with a label property, which can lead to a TypeError.

packages/poml-vscode/tests/lsp.test.ts#L91-L93

const pos = new vscode.Position(0, doc.getText().length);
const list = (await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', doc.uri, pos)) as vscode.CompletionList;
const labels = list.items.map(item => (typeof item.label === 'string' ? item.label : item.label.label));

Fix in Cursor


Bug: Unprotected Array Access Causes TypeError

The code attempts to access hovers[0].contents[0] without verifying that hovers[0].contents exists or contains elements. This can lead to a TypeError if contents is undefined or an empty array, as the index access [0] will fail before the nullish coalescing operator can be applied.

packages/poml-vscode/tests/lsp.test.ts#L81-L82

assert.ok(hovers && hovers.length > 0, 'No hover result');
const text = (hovers[0].contents[0] as any).value ?? '';

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@ultmaster ultmaster requested a review from Copilot June 30, 2025 09:51
Copy link
Contributor

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 adds a VS Code LSP server test suite to validate diagnostics, hover, and completion functionality.

  • Introduces new tests for LSP diagnostics, hover responses, and completions
  • Includes tests to verify preview features and behavior with bad syntax files
  • Adds teardown steps to close editors after tests to avoid interference between tests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/poml-vscode/tests/preview.test.ts Added preview feature tests with improved teardown handling
packages/poml-vscode/tests/lsp.test.ts New LSP server tests for diagnostics, hover, completion, preview
packages/poml-vscode/test-fixtures/badSyntaxLsp.poml Fixture file with intentionally bad syntax for diagnostics

suite('Preview Feature', () => {
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await new Promise(resolve => setTimeout(resolve, 500));
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

Consider replacing this fixed delay with an event-based or promise-driven approach to ensure editors are fully closed before tests continue.

Suggested change
await new Promise(resolve => setTimeout(resolve, 500));
await new Promise(resolve => {
const interval = setInterval(() => {
if (vscode.workspace.textDocuments.length === 0) {
clearInterval(interval);
resolve();
}
}, 100);
});

Copilot uses AI. Check for mistakes.
};
client = new LanguageClient('poml-test', 'POML Language Server', serverOptions, clientOptions);
await client.start();
await new Promise(resolve => setTimeout(resolve, 3000));
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

Consider using event-based synchronization for the LSP server startup instead of relying on a fixed timeout, which may lead to flaky tests.

Suggested change
await new Promise(resolve => setTimeout(resolve, 3000));
await client.onReady();

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster merged commit 6b281dc into main Jun 30, 2025
4 checks passed
@ultmaster ultmaster deleted the codex/add-tests-for-vscode-lsp-server branch July 9, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants