Skip to content

Use synchronize-request in LSP tests on 6.2 #1461

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
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { WorkspaceContext } from "../../../src/WorkspaceContext";
import { testAssetUri } from "../../fixtures";
import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities/tasks";
import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider";
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
import {
activateExtensionForSuite,
folderInRootWorkspace,
updateSettings,
} from "../utilities/testutilities";
import { waitForClientState, waitForIndex } from "../utilities/lsputilities";

async function buildProject(ctx: WorkspaceContext, name: string) {
Expand All @@ -42,11 +46,22 @@ suite("Language Client Integration Suite @slow", function () {
async setup(ctx) {
workspaceContext = ctx;

const resetSettings = await updateSettings({
"swift.sourcekit-lsp.serverArguments": [
"--experimental-feature",
"synchronize-request",
],
Comment on lines +50 to +53
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding the to specify this as part of initializationOptions during the initialize request? As a general direction, I would like to move away from taking command line arguments to SourceKit-LSP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does that look like? Adding "workspace/synchronize-request": true to the options here? https://github.com/swiftlang/vscode-swift/blob/main/src/sourcekit-lsp/LanguageClientManager.ts#L650

Copy link
Member

Choose a reason for hiding this comment

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

It should be adding "experimentalFeatures": ["synchronize-request"] there. Though it would be nice to only enable that experimental feature for tests that need it. If that’s not possible, let me know and we can try to prioritize making the request non-experimental.

Copy link
Contributor Author

@plemarquand plemarquand Mar 26, 2025

Choose a reason for hiding this comment

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

Thanks, I've addressed this in #1463

});

// Restart the LSP after changing its settings
await ctx.languageClientManager.restart();

await buildProject(ctx, "defaultPackage");

// Ensure lsp client is ready
clientManager = ctx.languageClientManager;
await waitForClientState(clientManager, langclient.State.Running);
return resetSettings;
},
});

Expand Down
31 changes: 28 additions & 3 deletions test/integration-tests/utilities/lsputilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import * as vscode from "vscode";
import * as langclient from "vscode-languageclient/node";
import { LanguageClientManager } from "../../../src/sourcekit-lsp/LanguageClientManager";
import { Version } from "../../../src/utilities/version";

export async function waitForClient<Result>(
languageClientManager: LanguageClientManager,
Expand All @@ -41,10 +42,34 @@ export namespace PollIndexRequest {
export const type = new langclient.RequestType<object, object, never>(method);
}

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace WorkspaceSynchronizeRequest {
export const method = "workspace/_synchronize" as const;
export const messageDirection: langclient.MessageDirection =
langclient.MessageDirection.clientToServer;
export const type = new langclient.RequestType<object, object, never>(method);
}

export async function waitForIndex(languageClientManager: LanguageClientManager): Promise<void> {
await languageClientManager.useLanguageClient(async (client, token) =>
client.sendRequest(PollIndexRequest.type, {}, token)
);
if (
languageClientManager.workspaceContext.swiftVersion.isGreaterThanOrEqual(
new Version(6, 2, 0)
)
) {
await languageClientManager.useLanguageClient(async (client, token) =>
client.sendRequest(
WorkspaceSynchronizeRequest.type,
{
index: true,
},
token
)
);
} else {
await languageClientManager.useLanguageClient(async (client, token) =>
client.sendRequest(PollIndexRequest.type, {}, token)
);
}
}

export async function waitForClientState(
Expand Down
Loading