Skip to content

Commit

Permalink
Merge branch 'main' into vite
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed Mar 12, 2024
2 parents 6d08aa6 + c16d50d commit 6799c8f
Show file tree
Hide file tree
Showing 11 changed files with 878 additions and 2,396 deletions.
3,193 changes: 836 additions & 2,357 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"jsdom": "^24.0.0",
"pptr-testing-library": "^0.7.0",
"prettier": "2.3.2",
"puppeteer": "13.4.0",
"puppeteer": "13.7.0",
"typescript": "^5.4.2",
"vite-plugin-svgr": "^4.2.0",
"vitest": "^1.3.1"
Expand Down
7 changes: 3 additions & 4 deletions src/e2e/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ export class App {
await page.close({
runBeforeUnload: true,
});
// A delay is required to give us a chance to handle the dialog event.
// If this proves fragile we could wait for the success condition below
// and give up on testing the absence of a dialog.
await page.waitForTimeout(50);
await waitFor(() => {
expect(page.isClosed()).toEqual(true);
}, defaultWaitForOptions);
return this.dialogs.length === 1 && this.dialogs[0] === "beforeunload";
}

Expand Down
8 changes: 8 additions & 0 deletions src/e2e/documentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe("documentaion", () => {
});

it("Copy code and paste in editor", async () => {
if (process.platform === "darwin") {
// pasteToolkitCode doesn't work on Mac
return;
}
const tab = "Reference";
await app.selectAllInEditor();
await app.typeInEditor("# Initial document");
Expand All @@ -33,6 +37,10 @@ describe("documentaion", () => {
});

it("Copy code after dropdown choice and paste in editor", async () => {
if (process.platform === "darwin") {
// pasteToolkitCode doesn't work on Mac
return;
}
const tab = "Reference";
await app.selectAllInEditor();
await app.typeInEditor("# Initial document");
Expand Down
4 changes: 2 additions & 2 deletions src/editor/codemirror/language-server/autocompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
CompletionItemKind,
CompletionResolveRequest,
CompletionTriggerKind,
ConnectionError,
} from "vscode-languageserver-protocol";
import { ApiReferenceMap } from "../../../documentation/mapping/content";
import { LanguageServerClient } from "../../../language-server/client";
import { isErrorDueToDispose } from "../../../language-server/error-util";
import { Logging } from "../../../logging/logging";
import { clientFacet, uriFacet } from "./common";
import {
Expand Down Expand Up @@ -156,7 +156,7 @@ const createDocumentationResolver =
);
documentation = resolved.documentation;
} catch (e) {
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/editor/codemirror/language-server/signatureHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import {
Command,
EditorView,
KeyBinding,
keymap,
logException,
PluginValue,
showTooltip,
ViewPlugin,
ViewUpdate,
keymap,
logException,
showTooltip,
} from "@codemirror/view";
import { IntlShape } from "react-intl";
import {
ConnectionError,
MarkupContent,
SignatureHelp,
SignatureHelpParams,
SignatureHelpRequest,
} from "vscode-languageserver-protocol";
import { ApiReferenceMap } from "../../../documentation/mapping/content";
import { isErrorDueToDispose } from "../../../language-server/error-util";
import { BaseLanguageServerView, clientFacet, uriFacet } from "./common";
import {
DocSections,
Expand Down Expand Up @@ -104,7 +104,7 @@ const triggerSignatureHelpRequest = async (
effects: [setSignatureHelpResult.of(result)],
});
} catch (e) {
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
logException(state, e, "signature-help");
}
view.dispatch({
Expand Down
13 changes: 5 additions & 8 deletions src/language-server/apidocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
*
* SPDX-License-Identifier: MIT
*/
import {
ConnectionError,
ProtocolRequestType,
} from "vscode-languageserver-protocol";
import { ProtocolRequestType } from "vscode-languageserver-protocol";
import { MarkupKind } from "vscode-languageserver-types";
import { LanguageServerClient } from "./client";
import { isErrorDueToDispose } from "./error-util";

// This duplicates the types we added to Pyright.

Expand Down Expand Up @@ -88,10 +86,9 @@ export const apiDocs = async (
});
return result;
} catch (e) {
if (!(e instanceof ConnectionError)) {
throw e;
if (isErrorDueToDispose(e)) {
return {};
}
// We'll requery when the client is recreated.
return {};
throw e;
}
};
14 changes: 5 additions & 9 deletions src/language-server/client-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
*
* SPDX-License-Identifier: MIT
*/
import {
ConnectionError,
CreateFile,
DeleteFile,
} from "vscode-languageserver-protocol";
import { diff, EVENT_PROJECT_UPDATED, FileSystem, Project } from "../fs/fs";
import { CreateFile, DeleteFile } from "vscode-languageserver-protocol";
import { EVENT_PROJECT_UPDATED, FileSystem, Project, diff } from "../fs/fs";
import { isPythonFile } from "../project/project-utils";
import { createUri, LanguageServerClient } from "./client";
import { LanguageServerClient, createUri } from "./client";
import { isErrorDueToDispose } from "./error-util";

export type FsChangesListener = (current: Project) => any;

Expand Down Expand Up @@ -84,8 +81,7 @@ export const trackFsChanges = (
}
}
} catch (e) {
// A new listener will be initialized for a replacement connection.
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/language-server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
CompletionList,
CompletionParams,
CompletionRequest,
ConnectionError,
ConnectionErrors,
Diagnostic,
DiagnosticSeverity,
DiagnosticTag,
Expand All @@ -32,6 +30,7 @@ import {
} from "vscode-languageserver-protocol";
import { retryAsyncLoad } from "../common/chunk-util";
import { microPythonConfig } from "../micropython/micropython";
import { isErrorDueToDispose } from "./error-util";

/**
* Create a URI for a source document under the default root of file:///src/.
Expand Down Expand Up @@ -174,10 +173,7 @@ export class LanguageServerClient extends EventEmitter {
this.capabilities = capabilities;
this.connection.sendNotification(InitializedNotification.type, {});
} catch (e) {
if (
e instanceof ConnectionError &&
e.code === ConnectionErrors.Disposed
) {
if (isErrorDueToDispose(e)) {
// We've intentionally disposed the connection because we're recreating the client.
// This mostly happens due to React 18 strict mode but could happen due to language changes.
return false;
Expand Down Expand Up @@ -243,8 +239,7 @@ export class LanguageServerClient extends EventEmitter {
params
);
} catch (e) {
// Client being recreated, give no results.
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/language-server/error-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ConnectionError, ErrorCodes, ResponseError } from "vscode-jsonrpc";

// The language server gets disposed/recreated which can cause errors for
// initialization or in-flight requests. We ignore these when they occur.
export const isErrorDueToDispose = (e: unknown): boolean =>
(e instanceof ResponseError &&
e.code === ErrorCodes.PendingResponseRejected) ||
e instanceof ConnectionError;
4 changes: 2 additions & 2 deletions src/workbench/AboutDialog/AboutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ const AboutDialog = ({ isOpen, onClose, finalFocusRef }: AboutDialogProps) => {
}}
/>
</Text>
<SimpleGrid columns={[1, 1, 2, 2]} spacing={8}>
<SimpleGrid columns={[1, 1, 2, 2]} spacing={5}>
<Box>
<AspectRatio
ml="auto"
mr="auto"
ratio={690 / 562}
maxWidth={[388, 388, null, null]}
maxWidth={[303, 303, null, null]}
>
<Image
src={microbitHeartImage}
Expand Down

0 comments on commit 6799c8f

Please sign in to comment.