Skip to content

Conversation

mattmasson
Copy link
Member

Resolves #253.

@mattmasson mattmasson requested a review from Copilot September 10, 2025 20:48
Copy link

@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 adds enhanced cancellation support to the validate() function by introducing more opportunities for cancellation throughout the validation process. The key change is implementing sequential processing with cancellation checks rather than using Promise.all(), allowing validation operations to be cancelled more responsively.

  • Implements sequential processing for validation operations with cancellation support
  • Adds cancellation checks at multiple points throughout the validation pipeline
  • Introduces a new processSequentiallyWithCancellation utility function for better async cancellation patterns

Reviewed Changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/powerquery-language-services/promiseUtils.ts New utility module providing sequential processing with cancellation support
src/powerquery-language-services/validate/validate.ts Refactored to use sequential validation operations with cancellation checks
src/powerquery-language-services/validate/validateInvokeExpression.ts Updated to use sequential processing and added cancellation checks
src/powerquery-language-services/validate/validateDuplicateIdentifiers.ts Converted to async with sequential processing and cancellation support
src/powerquery-language-services/validate/validateFunctionExpression.ts Made async and added cancellation checks with yielding
src/powerquery-language-services/inspection/invokeExpression/invokeExpression.ts Added cancellation checks at key inspection points
src/test/validation/asyncValidation.test.ts Comprehensive test suite for validation cancellation behavior
src/test/utils/promiseUtils.test.ts Unit tests for the new promise utility functions
src/test/testUtils/validationTestUtils.ts Helper functions for testing validation cancellation scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

readonly library: Library.ILibrary;
readonly source: string;
// Keep cancellationToken here for backward compatibility
readonly cancellationToken: PQP.ICancellationToken | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

@JordanBoltonMN can I move cancellationToken up to InspectionSettings and rmove it from here? Or do we need to keep it here for back compat?

Copy link
Contributor

Choose a reason for hiding this comment

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

ValidationSettings extends InspectionSettings, so we can safely promote properties from ValidationSettings to InspectionSettings.

@mattmasson
Copy link
Member Author

needs version bump

Copy link

@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

Copilot reviewed 15 out of 17 changed files in this pull request and generated 8 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

readonly library: Library.ILibrary;
readonly source: string;
// Keep cancellationToken here for backward compatibility
readonly cancellationToken: PQP.ICancellationToken | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

ValidationSettings extends InspectionSettings, so we can safely promote properties from ValidationSettings to InspectionSettings.

validationSettings.cancellationToken?.throwIfCancelled();

const analysis: Analysis = AnalysisUtils.analysis(textDocument, analysisSettings);

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove whitespace?

import { Trace } from "@microsoft/powerquery-parser/lib/powerquery-parser/common/trace";

import * as PromiseUtils from "../promiseUtils";

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we remove whitespace?

import { Trace } from "@microsoft/powerquery-parser/lib/powerquery-parser/common/trace";

import * as PromiseUtils from "../promiseUtils";

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: whitespace

cancellationToken,
),
// Create an array of validation functions to process sequentially
const validationFunctions: Array<() => Promise<ReadonlyArray<Diagnostic>>> = [
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ReadonlyArray<T>

import { Trace } from "@microsoft/powerquery-parser/lib/powerquery-parser/common/trace";

import * as PromiseUtils from "../promiseUtils";

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: whitespace

import type { Range } from "vscode-languageserver-textdocument";

import * as PromiseUtils from "../promiseUtils";

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: whitespace

@@ -0,0 +1,111 @@
// Copyright (c) Microsoft Corporation.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: mark every property that can be as readonly

trackProcessed: true,
});

await expectCancellationAfterTimeout(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you convert this to the params style arguments? As an outside reader (especially if I'm reading online and can't drill down into the function definition), it makes it more immediately apparent what those arguments are for.

* Creates common test setup for string processing tests
*/
function testSetup(options?: {
items?: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: readonly

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.

[Enhancement] Improve cancellation opportunities in Validation code paths
2 participants