From 6501072d808e985e9edabda2fbfe40bab786f15f Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 10 May 2024 16:51:54 -0700 Subject: [PATCH] turn on formatting test now working (#2341) turn on test now working Signed-off-by: Jess Frazelle --- e2e/playwright/flow-tests.spec.ts | 29 ++++++++++++++++------------- src/editor/plugins/lsp/plugin.ts | 8 ++++++-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index 55ed20ccf..4e448ff18 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -299,12 +299,18 @@ test('if you click the format button it formats your code', async ({ test('if you use the format keyboard binding it formats your code', async ({ page, }) => { - test.skip( - true, - "I can't figure out how to get the keyboard shortcut to work (in playwright)" - ) - const u = getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `const part001 = startSketchOn('XY') +|> startProfileAt([-10, -10], %) +|> line([20, 0], %) +|> line([0, 20], %) +|> line([-20, 0], %) +|> close(%)` + ) + }) await page.setViewportSize({ width: 1000, height: 500 }) const lspStartPromise = page.waitForEvent('console', async (message) => { // it would be better to wait for a message that the kcl lsp has started by looking for the message message.text().includes('[lsp] [window/logMessage]') @@ -322,15 +328,12 @@ test('if you use the format keyboard binding it formats your code', async ({ // check no error to begin with await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() - await page.click('.cm-content') - await page.keyboard.type(`const part001 = startSketchOn('XY') -|> startProfileAt([-10, -10], %) -|> line([20, 0], %) -|> line([0, 20], %) -|> line([-20, 0], %) -|> close(%)`) + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() - await page.click('.cm-content') + // focus the editor + await page.click('.cm-line') // Hit alt+shift+f to format the code await page.keyboard.press('Alt+Shift+KeyF') diff --git a/src/editor/plugins/lsp/plugin.ts b/src/editor/plugins/lsp/plugin.ts index 09952786d..456782269 100644 --- a/src/editor/plugins/lsp/plugin.ts +++ b/src/editor/plugins/lsp/plugin.ts @@ -264,8 +264,12 @@ export class LanguageServerPlugin implements PluginValue { ) return null - this.sendChange({ - documentText: this.view.state.doc.toString(), + this.client.textDocumentDidChange({ + textDocument: { + uri: this.documentUri, + version: this.documentVersion++, + }, + contentChanges: [{ text: this.view.state.doc.toString() }], }) const result = await this.client.textDocumentFormatting({