Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Add Copilot language server (#39)

Myles Scolnick4740aba9921c
diff --git a/.gitignore b/.gitignore
index 1f76ed7a4b..e6a9ae912e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,5 +104,6 @@ yarn-error.log*
pnpm-debug.log*
marimo/_static/
+marimo/_lsp/
.vscode
diff --git a/MANIFEST.in b/MANIFEST.in
index de4bec6ada..0d079900b9 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,2 +1,3 @@
recursive-include marimo/_static *
+recursive-include marimo/_lsp *
include marimo/py.typed
diff --git a/Makefile b/Makefile
index 54d1e3a38a..e192ced7c8 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,11 @@ help:
.PHONY: fe
# install/build frontend
-fe: fe-install fe-build
+fe: fe-install fe-build lsp
+
+.PHONY: lsp
+# install/build lsp
+lsp: lsp-install lsp-build
.PHONY: py
# editable python install; only need to run once
@@ -66,6 +70,14 @@ fe-build:
fe-install:
cd frontend; pnpm install
+.PHONY: lsp-build
+lsp-build:
+ ./scripts/buildlsp.sh
+
+.PHONY: lsp-install
+lsp-install:
+ cd lsp; pnpm install
+
.PHONY: install-all
# install everything; takes a long time due to editable install
install-all: fe py
diff --git a/docs/getting_started/index.md b/docs/getting_started/index.md
index e0962c8e34..443fdb13c8 100644
--- a/docs/getting_started/index.md
+++ b/docs/getting_started/index.md
@@ -1,7 +1,6 @@
# Getting Started
-Installing marimo gets you the `marimo` command-line interface (CLI), the
-entry point to all things marimo.
+Installing marimo gets you the `marimo` command-line interface (CLI), the entry point to all things marimo.
## Installation
@@ -61,9 +60,19 @@ Automatically translate Jupyter notebooks to marimo notebooks with `marimo conve
marimo convert your_notebook.ipynb > your_notebook.py
```
-Because marimo is different from traditional notebooks, your converted
-notebook will likely have errors that you'll need to fix. marimo
-will guide you through fixing them when you open it with `marimo edit`.
+Because marimo is different from traditional notebooks, your converted notebook
+will likely have errors that you'll need to fix. marimo will guide you through
+fixing them when you open it with `marimo edit`.
+
+## Github Copilot
+
+The marimo editor natively supports [Github Copilot](https://copilot.github.com/),
+an AI pair programmer, similar to VS Code.
+
+_Get started with Copilot_:
+
+1. Install [Node.js](https://nodejs.org/en/download).
+2. Enable Copilot via the settings menu in the marimo editor.
## VS Code extension
diff --git a/frontend/package.json b/frontend/package.json
index b5f6d909bf..ba87ae0606 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -30,6 +30,7 @@
"@lezer/common": "^1.0.4",
"@lezer/highlight": "^1.1.6",
"@lezer/lr": "^1.3.10",
+ "@open-rpc/client-js": "^1.8.1",
"@radix-ui/colors": "^2.0.1",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.4",
@@ -61,6 +62,8 @@
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
"codemirror": "^6.0.1",
+ "codemirror-extension-inline-suggestion": "^0.0.1",
+ "codemirror-languageserver": "^1.11.0",
"cssnano": "^6.0.1",
"date-fns": "^2.30.0",
"eslint-plugin-header": "^3.1.1",
@@ -82,6 +85,7 @@
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"timestring": "^7.0.0",
+ "vscode-languageserver-protocol": "^3.17.3",
"web-vitals": "^3.4.0",
"zod": "^3.22.2"
},
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index ae505c6d58..e9017c9dc5 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -62,6 +62,9 @@ dependencies:
'@lezer/lr':
specifier: ^1.3.10
version: 1.3.10
+ '@open-rpc/client-js':
+ specifier: ^1.8.1
+ version: 1.8.1
'@radix-ui/colors':
specifier: ^2.0.1
version: 2.0.1
@@ -155,6 +158,12 @@ dependencies:
codemirror:
specifier: ^6.0.1
version: 6.0.1(@lezer/[email protected])
+ codemirror-extension-inline-suggestion:
+ specifier: ^0.0.1
+ version: 0.0.1(@codemirror/[email protected])(@codemirror/[email protected])
+ codemirror-languageserver:
+ specifier: ^1.11.0
+ version: 1.11.0(@codemirror/[email protected])(@lezer/[email protected])
cssnano:
specifier: ^6.0.1
version: 6.0.1([email protected])
@@ -218,6 +227,9 @@ dependencies:
timestring:
specifier: ^7.0.0
version: 7.0.0
+ vscode-languageserver-protocol:
+ specifier: ^3.17.3
+ version: 3.17.3
web-vitals:
specifier: ^3.4.0
version: 3.4.0
@@ -2886,6 +2898,19 @@ packages:
resolution: {integrity: sha512-Aq58f5HiWdyDlFffbbSjAlv596h/cOnt2DO1w3DOC7OJ5EHs0hd/nycJfiu9RJbT6Yk6F1knnRRXNSpxoIVZ9Q==}
dev: true
+ /@open-rpc/[email protected]:
+ resolution: {integrity: sha512-vV+Hetl688nY/oWI9IFY0iKDrWuLdYhf7OIKI6U1DcnJV7r4gAgwRJjEr1QVYszUc0gjkHoQJzqevmXMGLyA0g==}
+ dependencies:
+ isomorphic-fetch: 3.0.0
+ isomorphic-ws: 5.0.0([email protected])
+ strict-event-emitter-types: 2.0.0
+ ws: 7.5.9
+ transitivePeerDependencies:
+ - bufferutil
+ - encoding
+ - utf-8-validate
+ dev: false
+
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
engines: {node: '>=14'}
@@ -7294,6 +7319,33 @@ packages:
- '@types/react'
dev: false
+ resolution: {integrity: sha512-lwxsk365lspmv8ZDS3zQbzmKkVWMZFEHelqQo68HPEZustq1rYtR/D2s4XBNgTNYna6Mba7fU8UUXXqmFBNlpA==}
+ peerDependencies:
+ '@codemirror/state': ^6.2.0
+ '@codemirror/view': ^6.7.2
+ dependencies:
+ '@codemirror/state': 6.2.1
+ '@codemirror/view': 6.19.0
+ dev: false
+
+ resolution: {integrity: sha512-QtFEMc1yhi8wzKasE+OseMeikHpHdFt1wQdt5F4O3sKl7B1m56OcVuqmCAJipklbIPDkLecaXhd8oFvA72lfnw==}
+ dependencies:
+ '@codemirror/autocomplete': 6.9.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
+ '@codemirror/lint': 6.4.2
+ '@codemirror/state': 6.2.1
+ '@codemirror/view': 6.19.0
+ '@open-rpc/client-js': 1.8.1
+ vscode-languageserver-protocol: 3.17.3
+ transitivePeerDependencies:
+ - '@codemirror/language'
+ - '@lezer/common'
+ - bufferutil
+ - encoding
+ - utf-8-validate
+ dev: false
+
resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==}
dependencies:
@@ -9716,6 +9768,23 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
+ resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==}
+ dependencies:
+ node-fetch: 2.6.7
+ whatwg-fetch: 3.6.17
+ transitivePeerDependencies:
+ - encoding
+ dev: false
+
+ resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==}
+ peerDependencies:
+ ws: '*'
+ dependencies:
+ ws: 7.5.9
+ dev: false
+
resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==}
engines: {node: '>=8'}
@@ -12606,6 +12675,10 @@ packages:
resolution: {integrity: sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==}
dev: true
+ resolution: {integrity: sha512-Nk/brWYpD85WlOgzw5h173aci0Teyv8YdIAEtV+N88nDB0dLlazZyJMIsN6eo1/AR61l+p6CJTG1JIyFaoNEEA==}
+ dev: false
+
resolution: {integrity: sha512-KDf/ujU8Zud3YaLtMCcTI4xkZlZVIYxTLr+XIULexP+77EEVWixeXroLUXQXiVtH4XH2W7jr/3PT1v3zBuvc3A==}
dependencies:
@@ -13660,6 +13733,22 @@ packages:
- terser
dev: true
+ resolution: {integrity: sha512-6TDy/abTQk+zDGYazgbIPc+4JoXdwC8NHU9Pbn4UJP1fehUyZmM4RHp5IthX7A6L5KS30PRui+j+tbbMMMafdw==}
+ engines: {node: '>=14.0.0'}
+ dev: false
+
+ resolution: {integrity: sha512-924/h0AqsMtA5yK22GgMtCYiMdCOtWTSGgUOkgEDX+wk2b0x4sAfLiO4NxBxqbiVtz7K7/1/RgVrVI0NClZwqA==}
+ dependencies:
+ vscode-jsonrpc: 8.1.0
+ vscode-languageserver-types: 3.17.3
+ dev: false
+
+ resolution: {integrity: sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==}
+ dev: false
+
resolution: {integrity: sha512-tOhfEwEzFLJzf6d1ZPkYfGj+FWhIpBux9ppoP3rlclw3Z0BZv3N7b7030Z1kYth+6rDuAsXUFr+d0VE6Ed1ikw==}
dev: false
@@ -13765,6 +13854,10 @@ packages:
iconv-lite: 0.6.3
dev: true
+ resolution: {integrity: sha512-c4ghIvG6th0eudYwKZY5keb81wtFz9/WeAHAoy8+r18kcWlitUIrmGFQ2rWEl4UCKUilD3zCLHOIPheHx5ypRQ==}
+ dev: false
+
resolution: {integrity: sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==}
engines: {node: '>=12'}
@@ -13898,6 +13991,19 @@ packages:
async-limiter: 1.0.1
dev: true
+ resolution: {integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==}
+ engines: {node: '>=8.3.0'}
+ peerDependencies:
+ bufferutil: ^4.0.1
+ utf-8-validate: ^5.0.2
+ peerDependenciesMeta:
+ bufferutil:
+ optional: true
+ utf-8-validate:
+ optional: true
+ dev: false
+
resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==}
engines: {node: '>=10.0.0'}
diff --git a/frontend/src/components/app-config/theme-toggle.tsx b/frontend/src/components/app-config/theme-toggle.tsx
index 9c15467cbf..f218033c2b 100644
--- a/frontend/src/components/app-config/theme-toggle.tsx
+++ b/frontend/src/components/app-config/theme-toggle.tsx
@@ -12,16 +12,19 @@ export const ThemeToggle: React.FC = () => {
}
return (
- <FormItem className="flex flex-row items-start space-x-2 space-y-0">
- <FormControl>
- <Checkbox
- checked={theme === "dark"}
- onCheckedChange={(checked) => {
- return setTheme(checked === true ? "dark" : "light");
- }}
- />
- </FormControl>
- <FormLabel className="font-normal">Dark mode</FormLabel>
- </FormItem>
+ <>
+ <div className="h-px bg-gray-200 dark:bg-gray-700" />
+ <FormItem className="flex flex-row items-start space-x-2 space-y-0">
+ <FormControl>
+ <Checkbox
+ checked={theme === "dark"}
+ onCheckedChange={(checked) => {
+ return setTheme(checked === true ? "dark" : "light");
+ }}
+ />
+ </FormControl>
+ <FormLabel className="font-normal">Dark mode</FormLabel>
+ </FormItem>
+ </>
);
};
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index ed47ad97d5..066c14d071 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -19,6 +19,8 @@ import { useUserConfig } from "../../core/state/config";
import { ThemeToggle } from "./theme-toggle";
import { NativeSelect } from "../ui/native-select";
import { KEYMAP_PRESETS } from "@/core/codemirror/keymaps/keymaps";
+import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
+import { Switch } from "../ui/switch";
export const UserConfigForm: React.FC = () => {
const [config, setConfig] = useUserConfig();
@@ -133,6 +135,29 @@ export const UserConfigForm: React.FC = () => {
</FormItem>
)}
/>
+ <div className="h-px bg-gray-200 dark:bg-gray-700" />
+ <div className="text-sm font-medium">GitHub Copilot</div>
+ <FormField
+ control={form.control}
+ name="completion.copilot"
+ render={({ field }) => (
+ <div className="flex flex-col gap-2">
+ <FormItem className="flex flex-row items-center space-x-2 space-y-0">
+ <FormControl>
+ <Switch
+ size={"sm"}
+ checked={field.value}
+ onCheckedChange={(checked) => {
+ return field.onChange(Boolean(checked));
+ }}
+ />
+ </FormControl>
+ <FormLabel className="font-normal flex">Enable</FormLabel>
+ </FormItem>
+ {field.value && <CopilotConfig />}
+ </div>
+ )}
+ />
<ThemeToggle />
</form>
</Form>
diff --git a/frontend/src/components/ui/button.tsx b/frontend/src/components/ui/button.tsx
index 1171136c33..2b994ebc00 100644
--- a/frontend/src/components/ui/button.tsx
+++ b/frontend/src/components/ui/button.tsx
@@ -66,8 +66,8 @@ const buttonVariants = cva(
},
size: {
default: "h-10 py-2 px-4",
- sm: "h-9 px-3 rounded-md",
xs: "h-7 px-2 rounded-md",
+ sm: "h-9 px-3 rounded-md",
lg: "h-11 px-8 rounded-md",
icon: "h-6 w-6",
},
diff --git a/frontend/src/core/codemirror/__tests__/setup.test.ts b/frontend/src/core/codemirror/__tests__/setup.test.ts
index ce2e29fe5b..30a4866304 100644
--- a/frontend/src/core/codemirror/__tests__/setup.test.ts
+++ b/frontend/src/core/codemirror/__tests__/setup.test.ts
@@ -1,11 +1,16 @@
/* Copyright 2023 Marimo. All rights reserved. */
-import { describe, expect, test } from "vitest";
+import { describe, expect, test, vi } from "vitest";
import { CodeMirrorSetupOpts, setupCodeMirror } from "../cm";
import { EditorState, Extension } from "@codemirror/state";
import { keymap } from "@codemirror/view";
import { CellId } from "@/core/model/ids";
import { Objects } from "@/utils/objects";
+vi.mock("@/core/config/config", () => ({
+ parseAppConfig: () => ({}),
+ parseUserConfig: () => ({}),
+}));
+
function namedFunction(name: string) {
const fn = () => false;
Object.defineProperty(fn, "name", { value: name });
@@ -34,6 +39,7 @@ function setup(config: Partial<CodeMirrorSetupOpts> = {}): Extension[] {
},
completionConfig: {
activate_on_typing: false,
+ copilot: false,
},
keymapConfig: {
preset: "default",
diff --git a/frontend/src/core/codemirror/cm.ts b/frontend/src/core/codemirror/cm.ts
index 055c3f0837..be35ecd63c 100644
--- a/frontend/src/core/codemirror/cm.ts
+++ b/frontend/src/core/codemirror/cm.ts
@@ -62,6 +62,7 @@ import {
scrollActiveLineIntoView,
smartPlaceholderExtension,
} from "./extensions";
+import { copilotBundle } from "./copilot/extension";
export interface CodeMirrorSetupOpts {
cellId: CellId;
@@ -143,6 +144,7 @@ export const basicBundle = (
closeOnBlur: false,
override: [completer],
}),
+ copilotBundle(),
foldGutter(),
closeBrackets(),
keymap.of(closeBracketsKeymap),
diff --git a/frontend/src/core/codemirror/copilot/__tests__/createWsUrl.test.ts b/frontend/src/core/codemirror/copilot/__tests__/createWsUrl.test.ts
new file mode 100644
index 0000000000..eca76956e9
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/__tests__/createWsUrl.test.ts
@@ -0,0 +1,51 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { beforeAll, afterAll, expect, describe, it, vi } from "vitest";
+import { createWsUrl } from "../client";
+
+vi.mock("@/core/config/config", () => ({
+ parseAppConfig: () => ({}),
+ parseUserConfig: () => ({}),
+}));
+
+describe("createWsUrl", () => {
+ let originalWindow: Window & typeof globalThis;
+
+ beforeAll(() => {
+ // Save the original window object
+ originalWindow = global.window;
+ });
+
+ afterAll(() => {
+ // Restore the original window object after tests
+ global.window = originalWindow;
+ });
+
+ it("should create a WebSocket URL based on the window location", () => {
+ // Mock the window object
+ global.window = {
+ location: {
+ protocol: "http:",
+ hostname: "localhost",
+ port: "3000",
+ },
+ } as any;
+
+ const expectedUrl = "ws://localhost:30000/copilot";
+ expect(createWsUrl()).toBe(expectedUrl);
+ });
+
+ it("should use wss protocol when window location protocol is https", () => {
+ // Mock the window object
+ global.window = {
+ location: {
+ protocol: "https:",
+ hostname: "localhost",
+ port: "3000",
+ },
+ } as any;
+
+ const expectedUrl = "wss://localhost:30000/copilot";
+ expect(createWsUrl()).toBe(expectedUrl);
+ });
+});
diff --git a/frontend/src/core/codemirror/copilot/client.ts b/frontend/src/core/codemirror/copilot/client.ts
new file mode 100644
index 0000000000..29574d2bc4
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/client.ts
@@ -0,0 +1,87 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { once } from "@/utils/once";
+import { languageServerWithTransport } from "codemirror-languageserver";
+import { CopilotLanguageServerClient } from "./language-server";
+import { WebSocketTransport } from "@open-rpc/client-js";
+import { Transport } from "@open-rpc/client-js/build/transports/Transport";
+import { JSONRPCRequestData } from "@open-rpc/client-js/build/Request";
+import { waitForEnabledCopilot } from "./state";
+import { waitForWs } from "@/utils/waitForWs";
+
+// Dummy file for the copilot language server
+export const COPILOT_FILENAME = "/marimo.py";
+export const LANGUAGE_ID = "copilot";
+const FILE_URI = `file://${COPILOT_FILENAME}`;
+
+export const createWSTransport = once(() => {
+ return new LazyWebsocketTransport();
+});
+
+/**
+ * Custom WSTransport that:
+ * - waits for copilot to be enabled
+ * - wait for the websocket to be available
+ */
+class LazyWebsocketTransport extends Transport {
+ private delegate: WebSocketTransport | undefined;
+
+ constructor() {
+ super();
+ this.delegate = undefined;
+ }
+
+ override async connect() {
+ // Wait for copilot to be enabled
+ await waitForEnabledCopilot();
+ // Wait for ws to be available
+ await waitForWs(createWsUrl());
+
+ // Create delegate, if it doesn't exist
+ if (!this.delegate) {
+ this.delegate = new WebSocketTransport(createWsUrl());
+ }
+
+ // Connect
+ return this.delegate.connect();
+ }
+
+ override close() {
+ this.delegate?.close();
+ }
+
+ override async sendData(
+ data: JSONRPCRequestData,
+ timeout?: number | null | undefined
+ ) {
+ return this.delegate?.sendData(data, timeout);
+ }
+}
+
+export const getCopilotClient = once(
+ () =>
+ new CopilotLanguageServerClient({
+ rootUri: FILE_URI,
+ documentUri: FILE_URI,
+ languageId: LANGUAGE_ID,
+ workspaceFolders: null,
+ transport: createWSTransport(),
+ })
+);
+
+export function copilotServer() {
+ return languageServerWithTransport({
+ rootUri: FILE_URI,
+ documentUri: FILE_URI,
+ workspaceFolders: [],
+ transport: createWSTransport(),
+ client: getCopilotClient(),
+ languageId: LANGUAGE_ID,
+ });
+}
+
+export function createWsUrl(): string {
+ // TODO: this should be configurable, but instead we add a 0 and hope it is free
+ const LSP_PORT = window.location.port + 0;
+ const protocol = window.location.protocol === "https:" ? "wss" : "ws";
+ return `${protocol}://${window.location.hostname}:${LSP_PORT}/copilot`;
+}
diff --git a/frontend/src/core/codemirror/copilot/copilot-config.tsx b/frontend/src/core/codemirror/copilot/copilot-config.tsx
new file mode 100644
index 0000000000..e1759e0906
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/copilot-config.tsx
@@ -0,0 +1,194 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { useAtom } from "jotai";
+import { copilotSignedInState } from "./state";
+import { memo, useEffect, useState } from "react";
+import { getCopilotClient } from "./client";
+import { Button, buttonVariants } from "@/components/ui/button";
+import { CheckIcon, CopyIcon, Loader2Icon, XIcon } from "lucide-react";
+import { Label } from "@/components/ui/label";
+import { toast } from "@/components/ui/use-toast";
+
+type Step =
+ | "signedIn"
+ | "signingIn"
+ | "signInFailed"
+ | "signedOut"
+ | "notConnected";
+
+export const CopilotConfig = memo(() => {
+ const [copilotSignedIn, copilotChangeSignIn] = useAtom(copilotSignedInState);
+ const [step, setStep] = useState<Step>();
+
+ const [localData, setLocalData] = useState<{ url: string; code: string }>();
+ const [loading, setLoading] = useState(false);
+
+ // Check connection on mount
+ useEffect(() => {
+ const client = getCopilotClient();
+ client
+ .signedIn()
+ .then((signedIn) => {
+ copilotChangeSignIn(signedIn);
+ setStep(signedIn ? "signedIn" : "signedOut");
+ })
+ .catch(() => {
+ setStep("notConnected");
+ });
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ const trySignIn = async (evt: React.MouseEvent) => {
+ evt.preventDefault();
+ setLoading(true);
+ try {
+ const client = getCopilotClient();
+ const { verificationUri, status, userCode } =
+ await client.signInInitiate();
+
+ if (status === "OK" || status === "AlreadySignedIn") {
+ copilotChangeSignIn(true);
+ } else {
+ setStep("signingIn");
+ setLocalData({ url: verificationUri, code: userCode });
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const tryFinishSignIn = async (evt: React.MouseEvent) => {
+ evt.preventDefault();
+ if (!localData) {
+ return;
+ }
+ const client = getCopilotClient();
+ try {
+ setLoading(true);
+ const { status } = await client.signInConfirm({
+ userCode: localData.code,
+ });
+
+ if (status === "OK" || status === "AlreadySignedIn") {
+ copilotChangeSignIn(true);
+ } else {
+ setStep("signInFailed");
+ }
+ } catch {
+ // If request failed, try seeing if we're already signed in
+ // otherwise, show the error
+ const signedIn = await client.signedIn();
+ if (signedIn) {
+ copilotChangeSignIn(true);
+ } else {
+ setStep("signInFailed");
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const signOut = async (evt: React.MouseEvent) => {
+ evt.preventDefault();
+ const client = getCopilotClient();
+ copilotChangeSignIn(false);
+ await client.signOut();
+ };
+
+ const renderBody = () => {
+ // If we don't have a step set, infer it from the current state
+ const resolvedStep = step ?? (copilotSignedIn ? "signedIn" : "signedOut");
+
+ switch (resolvedStep) {
+ case "signedOut":
+ return (
+ <Button onClick={trySignIn} size="xs" variant="link">
+ Connect to GitHub Copilot
+ </Button>
+ );
+
+ case "signingIn":
+ return (
+ <ol className="ml-4 text-sm list-decimal [&>li]:mt-2">
+ <li>
+ <div className="flex items-center">
+ Copy this code:
+ <strong className="ml-2">{localData?.code}</strong>
+ <CopyIcon
+ className="ml-2 cursor-pointer opacity-60 hover:opacity-100 h-3 w-3"
+ onClick={() => {
+ if (!localData) {
+ return;
+ }
+ navigator.clipboard.writeText(localData.code);
+ toast({
+ description: "Copied to clipboard",
+ });
+ }}
+ />
+ </div>
+ </li>
+ <li>
+ Enter the code at this link:
+ <a
+ href={localData?.url}
+ target="_blank"
+ rel="noreferrer"
+ className={buttonVariants({ variant: "link", size: "xs" })}
+ >
+ {localData?.url}
+ </a>
+ </li>
+ <li>
+ Click here when done:
+ <Button size="xs" onClick={tryFinishSignIn} className="ml-1">
+ {loading && (
+ <Loader2Icon className="h-3 w-3 mr-1 animate-spin" />
+ )}
+ Done
+ </Button>
+ </li>
+ </ol>
+ );
+
+ case "signInFailed":
+ return (
+ <div className="flex flex-col gap-1">
+ <div className="text-destructive text-sm">
+ Sign in failed. Please try again.
+ </div>
+ {loading ? (
+ <Loader2Icon className="h-3 w-3 mr-1 animate-spin" />
+ ) : (
+ <Button onClick={trySignIn} size="xs" variant="link">
+ Connect to GitHub Copilot
+ </Button>
+ )}
+ </div>
+ );
+
+ case "signedIn":
+ return (
+ <div className="flex items-center justify-between">
+ <Label className="font-normal flex">
+ <CheckIcon className="h-4 w-4 mr-1" />
+ Connected
+ </Label>
+ <Button onClick={signOut} size="xs" variant="text">
+ Disconnect
+ </Button>
+ </div>
+ );
+
+ case "notConnected":
+ return (
+ <Label className="font-normal flex">
+ <XIcon className="h-4 w-4 mr-1" />
+ Unable to connect
+ </Label>
+ );
+ }
+ };
+
+ return renderBody();
+});
+CopilotConfig.displayName = "CopilotConfig";
diff --git a/frontend/src/core/codemirror/copilot/extension.ts b/frontend/src/core/codemirror/copilot/extension.ts
new file mode 100644
index 0000000000..2323f87155
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/extension.ts
@@ -0,0 +1,67 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { Extension, Text } from "@codemirror/state";
+import {
+ COPILOT_FILENAME,
+ LANGUAGE_ID,
+ copilotServer,
+ getCopilotClient,
+} from "./client";
+import { inlineSuggestion } from "codemirror-extension-inline-suggestion";
+import { isCopilotEnabled } from "./state";
+import { getCodes } from "./getCodes";
+
+export const copilotBundle = (): Extension => {
+ if (process.env.NODE_ENV === "test") {
+ return [];
+ }
+
+ return [
+ inlineSuggestion({
+ delay: 500, // default is 500ms
+ fetchFn: async (view) => {
+ if (!isCopilotEnabled()) {
+ return "";
+ }
+
+ // wait 10ms so that the view is updated first
+ await new Promise((resolve) => setTimeout(resolve, 10));
+
+ // We need to update the position of the cursor because added newlines
+ // from appending the other code
+ const currentCode = view.doc.toString();
+ const allCode = getCodes(currentCode);
+ const numberOfNewLines =
+ allCode.split("\n").length - currentCode.split("\n").length;
+
+ const position = offsetToPos(view.doc, view.selection.main.head);
+ position.line += numberOfNewLines;
+
+ const response = await getCopilotClient().getCompletion({
+ doc: {
+ source: allCode,
+ tabSize: view.tabSize,
+ indentSize: 1,
+ insertSpaces: true,
+ path: COPILOT_FILENAME,
+ version: 0,
+ uri: `file://${COPILOT_FILENAME}`,
+ relativePath: COPILOT_FILENAME,
+ languageId: LANGUAGE_ID,
+ position: position,
+ },
+ });
+ return response.completions.map((c) => c.displayText)[0] ?? "";
+ },
+ }),
+ // pop off last 2 elements of the array which are tooltip and autocompletion
+ copilotServer().slice(0, -2),
+ ];
+};
+
+function offsetToPos(doc: Text, offset: number) {
+ const line = doc.lineAt(offset);
+ return {
+ line: line.number - 1,
+ character: offset - line.from,
+ };
+}
diff --git a/frontend/src/core/codemirror/copilot/getCodes.ts b/frontend/src/core/codemirror/copilot/getCodes.ts
new file mode 100644
index 0000000000..538ae61cee
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/getCodes.ts
@@ -0,0 +1,27 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { getCells } from "@/core/state/cells";
+
+export function getCodes(otherCode: string) {
+ // Get all other cells' code
+ // Put `import` statements at the top, as it can help copilot give better suggestions
+ // TODO: we should sort this topologically
+ const codes = getCells()
+ .map((cell) => {
+ if (cell.ref.current?.editorView.state.doc.toString() === otherCode) {
+ return null;
+ }
+ return cell.ref.current?.editorView.state.doc.toString();
+ })
+ .filter(Boolean)
+ .sort((a, b) => {
+ if (a.startsWith("import") && !b.startsWith("import")) {
+ return -1;
+ }
+ if (!a.startsWith("import") && b.startsWith("import")) {
+ return 1;
+ }
+ return 0;
+ });
+
+ return [...codes, otherCode].join("\n");
+}
diff --git a/frontend/src/core/codemirror/copilot/language-server.ts b/frontend/src/core/codemirror/copilot/language-server.ts
new file mode 100644
index 0000000000..aaf17056ed
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/language-server.ts
@@ -0,0 +1,143 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import {
+ CompletionItem,
+ CompletionList,
+ CompletionParams,
+ DidChangeTextDocumentParams,
+ DidOpenTextDocumentParams,
+ Hover,
+ HoverParams,
+ VersionedTextDocumentIdentifier,
+} from "vscode-languageserver-protocol";
+
+import { LanguageServerClient } from "codemirror-languageserver";
+import {
+ CopilotStatus,
+ CopilotSignInInitiateParams,
+ CopilotSignInInitiateResult,
+ CopilotSignInConfirmParams,
+ CopilotSignInConfirmResult,
+ CopilotSignOutParams,
+ CopilotSignOutResult,
+ CopilotGetCompletionsParams,
+ CopilotGetCompletionsResult,
+ CopilotAcceptCompletionParams,
+ CopilotRejectCompletionParams,
+} from "./types";
+import { isCopilotEnabled } from "./state";
+import { getCodes } from "./getCodes";
+
+// A map of request methods and their parameters and return types
+export interface LSPRequestMap {
+ checkStatus: [{}, { status: CopilotStatus }];
+ signInInitiate: [CopilotSignInInitiateParams, CopilotSignInInitiateResult];
+ signInConfirm: [CopilotSignInConfirmParams, CopilotSignInConfirmResult];
+ signOut: [CopilotSignOutParams, CopilotSignOutResult];
+ notifyAccepted: [CopilotAcceptCompletionParams, unknown];
+ notifyRejected: [CopilotRejectCompletionParams, unknown];
+ getCompletions: [CopilotGetCompletionsParams, CopilotGetCompletionsResult];
+}
+
+/**
+ * A client for the Copilot language server.
+ */
+export class CopilotLanguageServerClient extends LanguageServerClient {
+ private documentVersion = 0;
+
+ private _request<Method extends keyof LSPRequestMap>(
+ method: Method,
+ params: LSPRequestMap[Method][0]
+ ): Promise<LSPRequestMap[Method][1]> {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ return (this as any).request(method, params);
+ }
+
+ private isDisabled() {
+ return !isCopilotEnabled();
+ }
+
+ override async textDocumentDidOpen(
+ params: DidOpenTextDocumentParams
+ ): Promise<DidOpenTextDocumentParams> {
+ if (this.isDisabled()) {
+ return params;
+ }
+ return super.textDocumentDidOpen(params);
+ }
+
+ override async textDocumentCompletion(
+ params: CompletionParams
+ ): Promise<CompletionList | CompletionItem[]> {
+ if (this.isDisabled()) {
+ return [];
+ }
+ return super.textDocumentCompletion(params);
+ }
+
+ override async textDocumentDidChange(
+ params: DidChangeTextDocumentParams
+ ): Promise<DidChangeTextDocumentParams> {
+ if (this.isDisabled()) {
+ return params;
+ }
+ return super.textDocumentDidChange({
+ ...params,
+ contentChanges: [{ text: getCodes(params.contentChanges[0].text) }],
+ textDocument: VersionedTextDocumentIdentifier.create(
+ params.textDocument.uri,
+ ++this.documentVersion
+ ),
+ });
+ }
+
+ override textDocumentHover(params: HoverParams): Promise<Hover> {
+ if (this.isDisabled()) {
+ return Promise.resolve({ contents: [] });
+ }
+ return super.textDocumentHover(params);
+ }
+
+ // AUTH
+ signOut() {
+ return this._request("signOut", {});
+ }
+
+ signInInitiate() {
+ return this._request("signInInitiate", {});
+ }
+
+ signInConfirm(params: CopilotSignInConfirmParams) {
+ return this._request("signInConfirm", params);
+ }
+
+ async signedIn() {
+ const { status } = await this._request("checkStatus", {});
+ return (
+ status === "SignedIn" || status === "AlreadySignedIn" || status === "OK"
+ );
+ }
+
+ // COMPLETIONS
+ acceptCompletion(params: CopilotAcceptCompletionParams) {
+ return this._request("notifyAccepted", params);
+ }
+
+ rejectCompletions(params: CopilotRejectCompletionParams) {
+ return this._request("notifyRejected", params);
+ }
+
+ async getCompletion(params: CopilotGetCompletionsParams) {
+ if (this.isDisabled()) {
+ return { completions: [] };
+ }
+
+ const version = this.documentVersion;
+
+ return this._request("getCompletions", {
+ doc: {
+ ...params.doc,
+ version: version,
+ },
+ });
+ }
+}
diff --git a/frontend/src/core/codemirror/copilot/state.ts b/frontend/src/core/codemirror/copilot/state.ts
new file mode 100644
index 0000000000..7fb5c9571a
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/state.ts
@@ -0,0 +1,25 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { getUserConfig, userConfigAtom } from "@/core/state/config";
+import { waitFor } from "@/core/state/jotai";
+import { atomWithStorage } from "jotai/utils";
+
+const KEY = "marimo:copilot:signedIn";
+
+export const copilotSignedInState = atomWithStorage<boolean | null>(KEY, null);
+
+function getIsLastSignedIn() {
+ const lastSignedIn = localStorage.getItem(KEY);
+ return lastSignedIn === "true";
+}
+
+export function isCopilotEnabled() {
+ const copilot = getIsLastSignedIn();
+ const userConfig = getUserConfig();
+ return copilot && userConfig.completion.copilot;
+}
+
+export function waitForEnabledCopilot() {
+ return waitFor(userConfigAtom, (value) => {
+ return value.completion.copilot === true;
+ });
+}
diff --git a/frontend/src/core/codemirror/copilot/types.ts b/frontend/src/core/codemirror/copilot/types.ts
new file mode 100644
index 0000000000..a586fef8ec
--- /dev/null
+++ b/frontend/src/core/codemirror/copilot/types.ts
@@ -0,0 +1,87 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+/* eslint-disable @typescript-eslint/no-empty-interface */
+
+export interface CopilotSignInInitiateParams {}
+export interface CopilotSignInInitiateResult {
+ verificationUri: string;
+ status: string;
+ userCode: string;
+ expiresIn: number;
+ interval: number;
+}
+export interface CopilotSignInConfirmParams {
+ userCode: string;
+}
+export type CopilotStatus =
+ | "SignedIn"
+ | "AlreadySignedIn"
+ | "MaybeOk"
+ | "NotAuthorized"
+ | "NotSignedIn"
+ | "OK";
+export interface CopilotSignInConfirmResult {
+ status: CopilotStatus;
+ user: string;
+}
+export interface CopilotSignOutParams {}
+export interface CopilotSignOutResult {
+ status: CopilotStatus;
+}
+export interface CopilotGetCompletionsParams {
+ doc: {
+ source: string;
+ tabSize: number;
+ indentSize: number;
+ insertSpaces: boolean;
+ path: string;
+ uri: string;
+ relativePath: string;
+ languageId: string;
+ version: number;
+ position: {
+ line: number;
+ character: number;
+ };
+ };
+}
+export interface CopilotGetCompletionsResult {
+ completions: Array<{
+ text: string;
+ position: {
+ line: number;
+ character: number;
+ };
+ uuid: string;
+ range: {
+ start: {
+ line: number;
+ character: number;
+ };
+ end: {
+ line: number;
+ character: number;
+ };
+ };
+ displayText: string;
+ point: {
+ line: number;
+ character: number;
+ };
+ region: {
+ start: {
+ line: number;
+ character: number;
+ };
+ end: {
+ line: number;
+ character: number;
+ };
+ };
+ }>;
+}
+export interface CopilotAcceptCompletionParams {
+ uuid: string;
+}
+export interface CopilotRejectCompletionParams {
+ uuids: string[];
+}
diff --git a/frontend/src/core/config/config.ts b/frontend/src/core/config/config.ts
index 7cd70a9d21..d0fbcc5352 100644
--- a/frontend/src/core/config/config.ts
+++ b/frontend/src/core/config/config.ts
@@ -6,6 +6,7 @@ export const UserConfigSchema = z
.object({
completion: z.object({
activate_on_typing: z.boolean(),
+ copilot: z.boolean(),
}),
save: z.object({
autosave: z.enum(["off", "after_delay"]).default("after_delay"),
diff --git a/frontend/src/core/state/__tests__/jotai.test.ts b/frontend/src/core/state/__tests__/jotai.test.ts
new file mode 100644
index 0000000000..86d180a6f6
--- /dev/null
+++ b/frontend/src/core/state/__tests__/jotai.test.ts
@@ -0,0 +1,25 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+
+import { expect, describe, it } from "vitest";
+import { store, waitFor } from "../jotai";
+import { atom } from "jotai";
+
+describe("waitFor function", () => {
+ it("should resolve when the atom satisfies the predicate", async () => {
+ const testAtom = atom(0);
+ store.set(testAtom, 10);
+
+ const result = await waitFor(testAtom, (value) => value === 10);
+ expect(result).toBe(10);
+ });
+
+ it("should resolve when the atom changes to satisfy the predicate", async () => {
+ const testAtom = atom(0);
+
+ setTimeout(() => store.set(testAtom, 15), 5);
+ setTimeout(() => store.set(testAtom, 20), 10);
+
+ const result = await waitFor(testAtom, (value) => value === 20);
+ expect(result).toBe(20);
+ });
+});
diff --git a/frontend/src/core/state/config.ts b/frontend/src/core/state/config.ts
index 408baa310f..d419289e29 100644
--- a/frontend/src/core/state/config.ts
+++ b/frontend/src/core/state/config.ts
@@ -11,7 +11,7 @@ import { store } from "./jotai";
/**
* Atom for storing the user config.
*/
-const userConfigAtom = atom<UserConfig>(parseUserConfig());
+export const userConfigAtom = atom<UserConfig>(parseUserConfig());
/**
* Returns the user config.
diff --git a/frontend/src/core/state/jotai.ts b/frontend/src/core/state/jotai.ts
index 80fa804a4e..26be589a59 100644
--- a/frontend/src/core/state/jotai.ts
+++ b/frontend/src/core/state/jotai.ts
@@ -1,7 +1,29 @@
/* Copyright 2023 Marimo. All rights reserved. */
-import { createStore } from "jotai";
+import { Atom, createStore } from "jotai";
/**
* Global store allows getting and setting global state outside of React components.
*/
export const store = createStore();
+
+/**
+ * Wait for an atom to satisfy a predicate.
+ */
+export async function waitFor<T>(
+ atom: Atom<T>,
+ predicate: (value: T) => boolean
+) {
+ if (predicate(store.get(atom))) {
+ return store.get(atom);
+ }
+
+ return new Promise<T>((resolve) => {
+ const unsubscribe = store.sub(atom, () => {
+ const value = store.get(atom);
+ if (predicate(value)) {
+ unsubscribe();
+ resolve(value);
+ }
+ });
+ });
+}
diff --git a/frontend/src/editor/Cell.tsx b/frontend/src/editor/Cell.tsx
index 8ec70ed057..f676c7ff00 100644
--- a/frontend/src/editor/Cell.tsx
+++ b/frontend/src/editor/Cell.tsx
@@ -39,6 +39,7 @@ import { CellId, HTMLCellId } from "../core/model/ids";
import { Theme } from "../theme/useTheme";
import { CellActionsDropdown } from "./cell/cell-actions";
import { CellActionsContextMenu } from "./cell/cell-context-menu";
+import { AppMode } from "@/core/mode";
/**
* Imperative interface of the cell.
@@ -87,7 +88,7 @@ export interface CellProps
cellId: CellId;
registerRunStart: () => void;
serializedEditorState: SerializedEditorState | null;
- editing: boolean;
+ mode: AppMode;
appClosed: boolean;
showDeleteButton: boolean;
/**
@@ -116,7 +117,7 @@ const CellComponent = (
stopped,
registerRunStart,
serializedEditorState,
- editing,
+ mode,
appClosed,
showDeleteButton,
updateCellCode,
@@ -142,6 +143,8 @@ const CellComponent = (
const needsRun = edited || interrupted;
const loading = status === "running" || status === "queued";
+ const editing = mode === "edit";
+ const reading = mode === "read";
const { sendToTop, sendToBottom } = useCellActions();
// Performs side-effects that must run whenever the cell is run, but doesn't
@@ -209,6 +212,10 @@ const CellComponent = (
);
useEffect(() => {
+ if (reading) {
+ return;
+ }
+
const deleteCellIfNotRunning = () => {
// Cannot delete running cells, since we're waiting for their output.
if (!runningOrQueuedRef.current) {
@@ -297,6 +304,7 @@ const CellComponent = (
// We don't want to re-run this effect when `allowFocus` or `code` changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
+ reading,
cellId,
userConfig.completion.activate_on_typing,
userConfig.keymap,
diff --git a/frontend/src/editor/renderers/CellArray.tsx b/frontend/src/editor/renderers/CellArray.tsx
index 3bfd15cdae..8521332833 100644
--- a/frontend/src/editor/renderers/CellArray.tsx
+++ b/frontend/src/editor/renderers/CellArray.tsx
@@ -54,7 +54,7 @@ export const CellArray: React.FC<CellArrayProps> = ({
const { theme } = useTheme();
const { togglePanel } = useChromeActions();
- const { invisible } = useDelayVisibility(cells.present);
+ const { invisible } = useDelayVisibility(cells.present, mode);
// HOTKEYS
useHotkey("global.focusTop", focusTopCell);
@@ -113,7 +113,7 @@ export const CellArray: React.FC<CellArrayProps> = ({
focusCell={focusCell}
moveToNextCell={moveToNextCell}
moveCell={moveCell}
- editing={mode === "edit"}
+ mode={mode}
appClosed={connStatus.state !== WebSocketState.OPEN}
ref={cell.ref}
userConfig={userConfig}
diff --git a/frontend/src/editor/renderers/vertical-layout/useDelayVisiblity.ts b/frontend/src/editor/renderers/vertical-layout/useDelayVisiblity.ts
index 240451e2ba..a29c4311a0 100644
--- a/frontend/src/editor/renderers/vertical-layout/useDelayVisiblity.ts
+++ b/frontend/src/editor/renderers/vertical-layout/useDelayVisiblity.ts
@@ -1,8 +1,9 @@
/* Copyright 2023 Marimo. All rights reserved. */
+import { AppMode } from "@/core/mode";
import { CellState } from "@/core/model/cells";
import { useState, useEffect } from "react";
-export function useDelayVisibility(cells: CellState[]) {
+export function useDelayVisibility(cells: CellState[], mode: AppMode) {
// Start the app as invisible and delay proportional to the number of cells,
// to avoid most of the flickering when the app is loaded (b/c it is
// streamed). Delaying also helps prevent cell editors from stealing focus.
@@ -12,9 +13,11 @@ export function useDelayVisibility(cells: CellState[]) {
const timeout = setTimeout(() => {
setInvisible(false);
// After 1 frame, focus on the first cell if it's been mounted
- requestAnimationFrame(() => {
- cells[0]?.ref.current?.editorView.focus();
- });
+ if (mode !== "read") {
+ requestAnimationFrame(() => {
+ cells[0]?.ref.current?.editorView.focus();
+ });
+ }
}, delay);
return () => clearTimeout(timeout);
// Delay only when app is first loaded
diff --git a/frontend/src/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/editor/renderers/vertical-layout/vertical-layout.tsx
index e195111660..a398f7622a 100644
--- a/frontend/src/editor/renderers/vertical-layout/vertical-layout.tsx
+++ b/frontend/src/editor/renderers/vertical-layout/vertical-layout.tsx
@@ -15,8 +15,9 @@ type VerticalLayoutProps = ICellRendererProps<VerticalLayout>;
const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({
cells,
appConfig,
+ mode,
}) => {
- const { invisible } = useDelayVisibility(cells);
+ const { invisible } = useDelayVisibility(cells, mode);
return (
<VerticalLayoutWrapper invisible={invisible} appConfig={appConfig}>
{cells.map((cell) => (
diff --git a/frontend/src/stories/cell.stories.tsx b/frontend/src/stories/cell.stories.tsx
index d58aeefb42..604772da53 100644
--- a/frontend/src/stories/cell.stories.tsx
+++ b/frontend/src/stories/cell.stories.tsx
@@ -30,7 +30,7 @@ const props: CellProps = {
registerRunStart: console.log,
runElapsedTimeMs: 10,
serializedEditorState: null,
- editing: true,
+ mode: "edit",
appClosed: false,
showDeleteButton: true,
allowFocus: false,
@@ -43,6 +43,7 @@ const props: CellProps = {
userConfig: {
completion: {
activate_on_typing: true,
+ copilot: false,
},
save: {
autosave: "off",
diff --git a/frontend/src/stories/editor.stories.tsx b/frontend/src/stories/editor.stories.tsx
index 5c07a84b33..994aa5644d 100644
--- a/frontend/src/stories/editor.stories.tsx
+++ b/frontend/src/stories/editor.stories.tsx
@@ -5,6 +5,8 @@ import { EditorState, Extension } from "@codemirror/state";
import { EditorView, basicSetup } from "codemirror";
import { basicBundle } from "../core/codemirror/cm";
import { python } from "@codemirror/lang-python";
+import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
+import { copilotBundle } from "@/core/codemirror/copilot/extension";
const meta: Meta = {
title: "Editor",
@@ -58,7 +60,7 @@ export const Primary: Story = {
<div className="Cell m-20 w-[60%] overflow-hidden">
<Editor
extensions={basicBundle(
- { activate_on_typing: false },
+ { activate_on_typing: false, copilot: false },
ctx.globals.theme
)}
/>
@@ -69,7 +71,8 @@ export const Primary: Story = {
export const DefaultPython: Story = {
render: () => (
<div className="m-20 w-[60%] overflow-hidden">
- <Editor extensions={[basicSetup, python()]} />
+ <Editor extensions={[basicSetup, python(), copilotBundle()]} />
+ <CopilotConfig />
</div>
),
};
diff --git a/frontend/src/utils/__tests__/waitForWs.ts b/frontend/src/utils/__tests__/waitForWs.ts
new file mode 100644
index 0000000000..6293827976
--- /dev/null
+++ b/frontend/src/utils/__tests__/waitForWs.ts
@@ -0,0 +1,57 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { beforeAll, afterAll, expect, describe, it, vi } from "vitest";
+import { waitForWs } from "../waitForWs";
+
+describe("waitForWs", () => {
+ let originalWebSocket: any;
+
+ beforeAll(() => {
+ // Save the original WebSocket object
+ originalWebSocket = global.WebSocket;
+ });
+
+ afterAll(() => {
+ // Restore the original WebSocket object after tests
+ global.WebSocket = originalWebSocket;
+ });
+
+ it("should resolve when the WebSocket connection is successful", async () => {
+ // Mock the WebSocket object
+ global.WebSocket = vi.fn().mockImplementation((url) => ({
+ onopen: null,
+ onerror: null,
+ close: vi.fn(),
+ })) as any;
+
+ const url = "ws://localhost:3000";
+ await expect(waitForWs(url)).resolves.toBe(url);
+
+ // Verify that WebSocket was called with the correct URL
+ expect(global.WebSocket).toHaveBeenCalledWith(url);
+ });
+
+ it("should reject when the WebSocket connection fails", async () => {
+ // Mock the WebSocket object
+ global.WebSocket = vi.fn().mockImplementation((url) => ({
+ onopen: null,
+ onerror: null,
+ close: vi.fn(),
+ // Simulate a connection error
+ simulateError: function () {
+ if (this.onerror) {
+ this.onerror(new Error("Connection error"));
+ }
+ },
+ })) as any;
+
+ const url = "ws://localhost:3000";
+ const ws = new global.WebSocket(url);
+ (ws as any).simulateError();
+
+ await expect(waitForWs(url)).rejects.toThrow(`Failed to connect to ${url}`);
+
+ // Verify that WebSocket was called with the correct URL
+ expect(global.WebSocket).toHaveBeenCalledWith(url);
+ });
+});
diff --git a/frontend/src/utils/waitForWs.ts b/frontend/src/utils/waitForWs.ts
new file mode 100644
index 0000000000..c691d210f2
--- /dev/null
+++ b/frontend/src/utils/waitForWs.ts
@@ -0,0 +1,31 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+
+/**
+ * Wait for a websocket to be available, with linear backoff.
+ */
+export async function waitForWs(url: string, tries = 10) {
+ for (let i = 0; i < tries; i++) {
+ try {
+ return await tryConnection(url);
+ } catch {
+ // wait a second * i
+ // linear backoff
+ await new Promise((resolve) => setTimeout(resolve, 1000 * (i + 1)));
+ }
+ }
+ throw new Error(`Failed to connect to ${url}`);
+}
+
+async function tryConnection(url: string) {
+ return new Promise<string>((resolve, reject) => {
+ const ws = new WebSocket(url);
+ ws.onopen = () => {
+ ws.close();
+ resolve(url);
+ };
+ ws.onerror = (err) => {
+ ws.close();
+ reject(err);
+ };
+ });
+}
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index f39b6fc2db..f083f8d503 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -16,6 +16,7 @@ const htmlDevPlugin = (): Plugin => {
JSON.stringify({
completion: {
activate_on_typing: false,
+ copilot: true,
},
save: {
autosave: "off",
diff --git a/lsp/index.ts b/lsp/index.ts
new file mode 100644
index 0000000000..a3bad7e38e
--- /dev/null
+++ b/lsp/index.ts
@@ -0,0 +1,79 @@
+import * as http from "http";
+import parseArgs from "minimist";
+import ws, { WebSocketServer } from "ws";
+import * as rpc from "@sourcegraph/vscode-ws-jsonrpc";
+import * as rpcServer from "@sourcegraph/vscode-ws-jsonrpc/lib/server";
+import path from "path";
+
+// Adapted from https://github.com/wylieconlon/jsonrpc-ws-proxy
+
+let argv = parseArgs(process.argv.slice(2));
+
+if (argv.help) {
+ console.log(`Usage: index.js --port 3000`);
+ process.exit(1);
+}
+
+let serverPort: number = parseInt(argv.port) || 3000;
+
+let languageServers: Record<string, string[]> = {
+ copilot: ["node", path.join(__dirname, "copilot", "dist", "agent.js")],
+};
+
+const wss = new WebSocketServer(
+ {
+ port: serverPort,
+ perMessageDeflate: false,
+ },
+ () => {
+ console.log(`Listening to http and ws requests on ${serverPort}`);
+ }
+);
+
+function toSocket(webSocket: ws): rpc.IWebSocket {
+ return {
+ send: (content) => webSocket.send(content),
+ onMessage: (cb) => (webSocket.onmessage = (event) => cb(event.data)),
+ onError: (cb) =>
+ (webSocket.onerror = (event) => {
+ if ("message" in event) {
+ cb(event.message);
+ }
+ }),
+ onClose: (cb) =>
+ (webSocket.onclose = (event) => cb(event.code, event.reason)),
+ dispose: () => webSocket.close(),
+ };
+}
+
+wss.on("connection", (client: ws, request: http.IncomingMessage) => {
+ let langServer: string[] | undefined;
+
+ Object.keys(languageServers).forEach((key) => {
+ if (request.url === "/" + key) {
+ langServer = languageServers[key];
+ }
+ });
+
+ if (!langServer || !langServer.length) {
+ console.error("Invalid language server", request.url);
+ client.close();
+ return;
+ }
+
+ const localConnection = rpcServer.createServerProcess(
+ "local",
+ langServer[0],
+ langServer.slice(1)
+ );
+ const socket = toSocket(client);
+ const connection = rpcServer.createWebSocketConnection(socket);
+
+ rpcServer.forward(connection, localConnection);
+ console.log(`Forwarding new client`);
+
+ socket.onClose((code, reason) => {
+ console.log("Client closed", reason);
+ localConnection.dispose();
+ });
+});
diff --git a/lsp/package.json b/lsp/package.json
new file mode 100644
index 0000000000..5160c03c57
--- /dev/null
+++ b/lsp/package.json
@@ -0,0 +1,22 @@
+{
+ "scripts": {
+ "build:ts": "tsup index.ts --format cjs --minify",
+ "build:deps": "cp -LR node_modules/copilot-node-server/copilot dist/",
+ "typecheck": "tsc --noEmit",
+ "build": "pnpm run build:ts && pnpm run build:deps"
+ },
+ "dependencies": {
+ "copilot-node-server": "1.10.1"
+ },
+ "devDependencies": {
+ "@sourcegraph/vscode-ws-jsonrpc": "0.0.3-fork",
+ "@types/minimist": "^1.2.2",
+ "@types/node": "^20.6.3",
+ "@types/ws": "^8.5.5",
+ "jsonrpc-ws-proxy": "^0.0.5",
+ "minimist": "^1.2.8",
+ "tsup": "^7.2.0",
+ "typescript": "^5.1.6",
+ "ws": "^8.14.2"
+ }
+}
diff --git a/lsp/pnpm-lock.yaml b/lsp/pnpm-lock.yaml
new file mode 100644
index 0000000000..34582b4900
--- /dev/null
+++ b/lsp/pnpm-lock.yaml
@@ -0,0 +1,996 @@
+lockfileVersion: '6.0'
+
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
+
+dependencies:
+ copilot-node-server:
+ specifier: 1.10.1
+ version: 1.10.1
+
+devDependencies:
+ '@sourcegraph/vscode-ws-jsonrpc':
+ specifier: 0.0.3-fork
+ version: 0.0.3-fork
+ '@types/minimist':
+ specifier: ^1.2.2
+ version: 1.2.2
+ '@types/node':
+ specifier: ^20.6.3
+ version: 20.6.3
+ '@types/ws':
+ specifier: ^8.5.5
+ version: 8.5.5
+ jsonrpc-ws-proxy:
+ specifier: ^0.0.5
+ version: 0.0.5
+ minimist:
+ specifier: ^1.2.8
+ version: 1.2.8
+ tsup:
+ specifier: ^7.2.0
+ version: 7.2.0([email protected])
+ typescript:
+ specifier: ^5.1.6
+ version: 5.1.6
+ ws:
+ specifier: ^8.14.2
+ version: 8.14.2
+
+packages:
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==}
+ engines: {node: '>=12'}
+ cpu: [arm64]
+ os: [android]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==}
+ engines: {node: '>=12'}
+ cpu: [arm]
+ os: [android]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [android]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==}
+ engines: {node: '>=12'}
+ cpu: [arm64]
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==}
+ engines: {node: '>=12'}
+ cpu: [arm64]
+ os: [freebsd]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [freebsd]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==}
+ engines: {node: '>=12'}
+ cpu: [arm64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==}
+ engines: {node: '>=12'}
+ cpu: [arm]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==}
+ engines: {node: '>=12'}
+ cpu: [ia32]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==}
+ engines: {node: '>=12'}
+ cpu: [loong64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==}
+ engines: {node: '>=12'}
+ cpu: [mips64el]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==}
+ engines: {node: '>=12'}
+ cpu: [ppc64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==}
+ engines: {node: '>=12'}
+ cpu: [riscv64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==}
+ engines: {node: '>=12'}
+ cpu: [s390x]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [netbsd]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [openbsd]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [sunos]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==}
+ engines: {node: '>=12'}
+ cpu: [arm64]
+ os: [win32]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==}
+ engines: {node: '>=12'}
+ cpu: [ia32]
+ os: [win32]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@esbuild/[email protected]:
+ resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==}
+ engines: {node: '>=12'}
+ cpu: [x64]
+ os: [win32]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==}
+ engines: {node: '>=6.0.0'}
+ dependencies:
+ '@jridgewell/set-array': 1.1.2
+ '@jridgewell/sourcemap-codec': 1.4.15
+ '@jridgewell/trace-mapping': 0.3.19
+ dev: true
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==}
+ engines: {node: '>=6.0.0'}
+ dev: true
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==}
+ engines: {node: '>=6.0.0'}
+ dev: true
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==}
+ dev: true
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==}
+ dependencies:
+ '@jridgewell/resolve-uri': 3.1.1
+ '@jridgewell/sourcemap-codec': 1.4.15
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
+ engines: {node: '>= 8'}
+ dependencies:
+ '@nodelib/fs.stat': 2.0.5
+ run-parallel: 1.2.0
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==}
+ engines: {node: '>= 8'}
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
+ engines: {node: '>= 8'}
+ dependencies:
+ '@nodelib/fs.scandir': 2.1.5
+ fastq: 1.15.0
+ dev: true
+
+ /@sourcegraph/[email protected]:
+ resolution: {integrity: sha512-EJLq/ni66glk3xYyOZtUIEbjTCw8kMI6RvO0YQtPd+4um2+aTSM1LfN4NrsiVrRkG7EG/U2OkFlKqT8mGo6w4Q==}
+ dependencies:
+ vscode-jsonrpc: 4.0.0
+ dev: true
+
+ resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==}
+ dev: true
+
+ resolution: {integrity: sha512-HksnYH4Ljr4VQgEy2lTStbCKv/P590tmPe5HqOnv9Gprffgv5WXAY+Y5Gqniu0GGqeTCUdBnzC3QSrzPkBkAMA==}
+ dev: true
+
+ resolution: {integrity: sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==}
+ dependencies:
+ '@types/node': 20.6.3
+ dev: true
+
+ resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==}
+ dev: true
+
+ resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
+ engines: {node: '>= 8'}
+ dependencies:
+ normalize-path: 3.0.0
+ picomatch: 2.3.1
+ dev: true
+
+ resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
+ dependencies:
+ sprintf-js: 1.0.3
+ dev: true
+
+ resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==}
+ dev: true
+
+ resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
+ dev: true
+
+ resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
+ dependencies:
+ balanced-match: 1.0.2
+ concat-map: 0.0.1
+ dev: true
+
+ resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==}
+ engines: {node: '>=8'}
+ dependencies:
+ fill-range: 7.0.1
+ dev: true
+
+ resolution: {integrity: sha512-9NQkRHlNdNpDBGmLpngF3EFDcwodhMUuLz9PaWYciVcQF9SE4LFjM2DB/xV1Li5JiuDMv7ZUWuC3rGbqR0MAXQ==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ peerDependencies:
+ esbuild: '>=0.17'
+ dependencies:
+ esbuild: 0.18.20
+ load-tsconfig: 0.2.5
+ dev: true
+
+ resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==}
+ engines: {node: '>= 8.10.0'}
+ dependencies:
+ anymatch: 3.1.3
+ braces: 3.0.2
+ glob-parent: 5.1.2
+ is-binary-path: 2.1.0
+ is-glob: 4.0.3
+ normalize-path: 3.0.0
+ readdirp: 3.6.0
+ optionalDependencies:
+ fsevents: 2.3.3
+ dev: true
+
+ resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==}
+ engines: {node: '>= 6'}
+ dev: true
+
+ resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=}
+ dev: true
+
+ resolution: {integrity: sha512-WpMEcSzL8ftVI74FQZisMzMI6slfmgX/8ByIo2Uvxfy2s1nPoqRBp8q3Y18+QrG6xreh8eRzZx70NcHH3QVAWA==}
+ hasBin: true
+ dev: false
+
+ resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
+ engines: {node: '>= 8'}
+ dependencies:
+ path-key: 3.1.1
+ shebang-command: 2.0.0
+ which: 2.0.2
+ dev: true
+
+ resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
+ engines: {node: '>=6.0'}
+ peerDependencies:
+ supports-color: '*'
+ peerDependenciesMeta:
+ supports-color:
+ optional: true
+ dependencies:
+ ms: 2.1.2
+ dev: true
+
+ resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
+ engines: {node: '>=8'}
+ dependencies:
+ path-type: 4.0.0
+ dev: true
+
+ resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==}
+ engines: {node: '>=12'}
+ hasBin: true
+ requiresBuild: true
+ optionalDependencies:
+ '@esbuild/android-arm': 0.18.20
+ '@esbuild/android-arm64': 0.18.20
+ '@esbuild/android-x64': 0.18.20
+ '@esbuild/darwin-arm64': 0.18.20
+ '@esbuild/darwin-x64': 0.18.20
+ '@esbuild/freebsd-arm64': 0.18.20
+ '@esbuild/freebsd-x64': 0.18.20
+ '@esbuild/linux-arm': 0.18.20
+ '@esbuild/linux-arm64': 0.18.20
+ '@esbuild/linux-ia32': 0.18.20
+ '@esbuild/linux-loong64': 0.18.20
+ '@esbuild/linux-mips64el': 0.18.20
+ '@esbuild/linux-ppc64': 0.18.20
+ '@esbuild/linux-riscv64': 0.18.20
+ '@esbuild/linux-s390x': 0.18.20
+ '@esbuild/linux-x64': 0.18.20
+ '@esbuild/netbsd-x64': 0.18.20
+ '@esbuild/openbsd-x64': 0.18.20
+ '@esbuild/sunos-x64': 0.18.20
+ '@esbuild/win32-arm64': 0.18.20
+ '@esbuild/win32-ia32': 0.18.20
+ '@esbuild/win32-x64': 0.18.20
+ dev: true
+
+ resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==}
+ engines: {node: '>=4'}
+ hasBin: true
+ dev: true
+
+ resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==}
+ engines: {node: '>=10'}
+ dependencies:
+ cross-spawn: 7.0.3
+ get-stream: 6.0.1
+ human-signals: 2.1.0
+ is-stream: 2.0.1
+ merge-stream: 2.0.0
+ npm-run-path: 4.0.1
+ onetime: 5.1.2
+ signal-exit: 3.0.7
+ strip-final-newline: 2.0.0
+ dev: true
+
+ resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==}
+ engines: {node: '>=8.6.0'}
+ dependencies:
+ '@nodelib/fs.stat': 2.0.5
+ '@nodelib/fs.walk': 1.2.8
+ glob-parent: 5.1.2
+ merge2: 1.4.1
+ micromatch: 4.0.5
+ dev: true
+
+ resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==}
+ dependencies:
+ reusify: 1.0.4
+ dev: true
+
+ resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
+ engines: {node: '>=8'}
+ dependencies:
+ to-regex-range: 5.0.1
+ dev: true
+
+ resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
+ dev: true
+
+ resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
+ engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
+ engines: {node: '>=10'}
+ dev: true
+
+ resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
+ engines: {node: '>= 6'}
+ dependencies:
+ is-glob: 4.0.3
+ dev: true
+
+ resolution: {integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==}
+ dependencies:
+ fs.realpath: 1.0.0
+ inflight: 1.0.6
+ inherits: 2.0.4
+ minimatch: 3.1.2
+ once: 1.4.0
+ path-is-absolute: 1.0.1
+ dev: true
+
+ resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==}
+ engines: {node: '>=10'}
+ dependencies:
+ array-union: 2.1.0
+ dir-glob: 3.0.1
+ fast-glob: 3.3.1
+ ignore: 5.2.4
+ merge2: 1.4.1
+ slash: 3.0.0
+ dev: true
+
+ resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==}
+ engines: {node: '>=10.17.0'}
+ dev: true
+
+ resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
+ engines: {node: '>= 4'}
+ dev: true
+
+ resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
+ dependencies:
+ once: 1.4.0
+ wrappy: 1.0.2
+ dev: true
+
+ resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
+ dev: true
+
+ resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==}
+ engines: {node: '>=8'}
+ dependencies:
+ binary-extensions: 2.2.0
+ dev: true
+
+ resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
+ engines: {node: '>=0.10.0'}
+ dependencies:
+ is-extglob: 2.1.1
+ dev: true
+
+ resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
+ engines: {node: '>=0.12.0'}
+ dev: true
+
+ resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
+ dev: true
+
+ resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
+ engines: {node: '>=10'}
+ dev: true
+
+ resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==}
+ hasBin: true
+ dependencies:
+ argparse: 1.0.10
+ esprima: 4.0.1
+ dev: true
+
+ resolution: {integrity: sha512-Gz3Njkc4LdJ+wEtrgG5acZWKTH78kYRHCYwN/QKzoJjdQw1jEepwkWTXLRa3JifcIpxh+WjA6OJw8A8RvejzXw==}
+ hasBin: true
+ dependencies:
+ '@sourcegraph/vscode-ws-jsonrpc': 0.0.3-fork
+ js-yaml: 3.14.1
+ minimist: 1.2.8
+ ws: 6.2.2
+ transitivePeerDependencies:
+ - bufferutil
+ - utf-8-validate
+ dev: true
+
+ resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==}
+ engines: {node: '>=10'}
+ dev: true
+
+ resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
+ dev: true
+
+ resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ dev: true
+
+ resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==}
+ dev: true
+
+ resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==}
+ dev: true
+
+ resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
+ engines: {node: '>= 8'}
+ dev: true
+
+ resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==}
+ engines: {node: '>=8.6'}
+ dependencies:
+ braces: 3.0.2
+ picomatch: 2.3.1
+ dev: true
+
+ resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
+ engines: {node: '>=6'}
+ dev: true
+
+ resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
+ dependencies:
+ brace-expansion: 1.1.11
+ dev: true
+
+ resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
+ dev: true
+
+ resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
+ dev: true
+
+ resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==}
+ dependencies:
+ any-promise: 1.3.0
+ object-assign: 4.1.1
+ thenify-all: 1.6.0
+ dev: true
+
+ resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==}
+ engines: {node: '>=8'}
+ dependencies:
+ path-key: 3.1.1
+ dev: true
+
+ resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
+ dependencies:
+ wrappy: 1.0.2
+ dev: true
+
+ resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==}
+ engines: {node: '>=6'}
+ dependencies:
+ mimic-fn: 2.1.0
+ dev: true
+
+ resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
+ engines: {node: '>=8.6'}
+ dev: true
+
+ resolution: {integrity: sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==}
+ engines: {node: '>= 6'}
+ dev: true
+
+ resolution: {integrity: sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==}
+ engines: {node: '>= 14'}
+ peerDependencies:
+ postcss: '>=8.0.9'
+ ts-node: '>=9.0.0'
+ peerDependenciesMeta:
+ postcss:
+ optional: true
+ ts-node:
+ optional: true
+ dependencies:
+ lilconfig: 2.1.0
+ yaml: 2.3.2
+ dev: true
+
+ resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
+ engines: {node: '>=6'}
+ dev: true
+
+ resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
+ dev: true
+
+ resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
+ engines: {node: '>=8.10.0'}
+ dependencies:
+ picomatch: 2.3.1
+ dev: true
+
+ resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==}
+ engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-CJouHoZ27v6siztc21eEQGo0kIcE5D1gVPA571ez0mMYb25LGYGKnVNXpEj5MGlepmDWGXNjDB5q7uNiPHC11A==}
+ engines: {node: '>=14.18.0', npm: '>=8.0.0'}
+ hasBin: true
+ optionalDependencies:
+ fsevents: 2.3.3
+ dev: true
+
+ resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
+ dependencies:
+ queue-microtask: 1.2.3
+ dev: true
+
+ resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
+ engines: {node: '>=8'}
+ dependencies:
+ shebang-regex: 3.0.0
+ dev: true
+
+ resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==}
+ dev: true
+
+ resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==}
+ engines: {node: '>=8'}
+ dev: true
+
+ resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==}
+ engines: {node: '>= 8'}
+ dependencies:
+ whatwg-url: 7.1.0
+ dev: true
+
+ resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}
+ dev: true
+
+ resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==}
+ engines: {node: '>=6'}
+ dev: true
+
+ resolution: {integrity: sha512-70/LQEZ07TEcxiU2dz51FKaE6hCTWC6vr7FOk3Gr0U60C3shtAN+H+BFr9XlYe5xqf3RA8nrc+VIwzCfnxuXJw==}
+ engines: {node: '>=8'}
+ hasBin: true
+ dependencies:
+ '@jridgewell/gen-mapping': 0.3.3
+ commander: 4.1.1
+ glob: 7.1.6
+ lines-and-columns: 1.2.4
+ mz: 2.7.0
+ pirates: 4.0.6
+ ts-interface-checker: 0.1.13
+ dev: true
+
+ resolution: {integrity: sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==}
+ engines: {node: '>=0.8'}
+ dependencies:
+ thenify: 3.3.1
+ dev: true
+
+ resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==}
+ dependencies:
+ any-promise: 1.3.0
+ dev: true
+
+ resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
+ engines: {node: '>=8.0'}
+ dependencies:
+ is-number: 7.0.0
+ dev: true
+
+ resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==}
+ dependencies:
+ punycode: 2.3.0
+ dev: true
+
+ resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}
+ hasBin: true
+ dev: true
+
+ resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==}
+ dev: true
+
+ resolution: {integrity: sha512-vDHlczXbgUvY3rWvqFEbSqmC1L7woozbzngMqTtL2PGBODTtWlRwGDDawhvWzr5c1QjKe4OAKqJGfE1xeXUvtQ==}
+ engines: {node: '>=16.14'}
+ hasBin: true
+ peerDependencies:
+ '@swc/core': ^1
+ postcss: ^8.4.12
+ typescript: '>=4.1.0'
+ peerDependenciesMeta:
+ '@swc/core':
+ optional: true
+ postcss:
+ optional: true
+ typescript:
+ optional: true
+ dependencies:
+ bundle-require: 4.0.1([email protected])
+ cac: 6.7.14
+ chokidar: 3.5.3
+ debug: 4.3.4
+ esbuild: 0.18.20
+ execa: 5.1.1
+ globby: 11.1.0
+ joycon: 3.1.1
+ postcss-load-config: 4.0.1
+ resolve-from: 5.0.0
+ rollup: 3.29.2
+ source-map: 0.8.0-beta.0
+ sucrase: 3.34.0
+ tree-kill: 1.2.2
+ typescript: 5.1.6
+ transitivePeerDependencies:
+ - supports-color
+ - ts-node
+ dev: true
+
+ resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==}
+ engines: {node: '>=14.17'}
+ hasBin: true
+ dev: true
+
+ resolution: {integrity: sha512-perEnXQdQOJMTDFNv+UF3h1Y0z4iSiaN9jIlb0OqIYgosPCZGYh/MCUlkFtV2668PL69lRDO32hmvL2yiidUYg==}
+ engines: {node: '>=8.0.0 || >=10.0.0'}
+ dev: true
+
+ resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==}
+ dev: true
+
+ resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==}
+ dependencies:
+ lodash.sortby: 4.7.0
+ tr46: 1.0.1
+ webidl-conversions: 4.0.2
+ dev: true
+
+ resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
+ engines: {node: '>= 8'}
+ hasBin: true
+ dependencies:
+ isexe: 2.0.0
+ dev: true
+
+ resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
+ dev: true
+
+ resolution: {integrity: sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==}
+ peerDependencies:
+ bufferutil: ^4.0.1
+ utf-8-validate: ^5.0.2
+ peerDependenciesMeta:
+ bufferutil:
+ optional: true
+ utf-8-validate:
+ optional: true
+ dependencies:
+ async-limiter: 1.0.1
+ dev: true
+
+ resolution: {integrity: sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==}
+ engines: {node: '>=10.0.0'}
+ peerDependencies:
+ bufferutil: ^4.0.1
+ utf-8-validate: '>=5.0.2'
+ peerDependenciesMeta:
+ bufferutil:
+ optional: true
+ utf-8-validate:
+ optional: true
+ dev: true
+
+ resolution: {integrity: sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==}
+ engines: {node: '>= 14'}
+ dev: true
diff --git a/lsp/tsconfig.json b/lsp/tsconfig.json
new file mode 100644
index 0000000000..3e4bff18ab
--- /dev/null
+++ b/lsp/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "compilerOptions": {
+ "esModuleInterop": true,
+ "strict": true
+ }
+}
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index a59e532d3a..bdf0367cbc 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -26,10 +26,13 @@ class CompletionConfig(TypedDict, total=False):
- `activate_on_typing`: if `False`, completion won't activate
until the completion hotkey is entered
+ - `copilot`: if `True`, enable the GitHub Copilot language server
"""
activate_on_typing: bool
+ copilot: bool
+
@mddoc
class SaveConfig(TypedDict, total=False):
@@ -91,7 +94,7 @@ class MarimoConfig(TypedDict, total=False):
DEFAULT_CONFIG: MarimoConfig = {
- "completion": {"activate_on_typing": True},
+ "completion": {"activate_on_typing": True, "copilot": False},
"save": {"autosave": "after_delay", "autosave_delay": 1000},
"keymap": {"preset": "default"},
}
diff --git a/marimo/_config/test_config.py b/marimo/_config/test_config.py
index 6e33f86132..7163dcedfe 100644
--- a/marimo/_config/test_config.py
+++ b/marimo/_config/test_config.py
@@ -14,7 +14,7 @@ def test_configure_partial_keymap() -> None:
def test_configure_full() -> None:
assert_config(
MarimoConfig(
- completion={"activate_on_typing": False},
+ completion={"activate_on_typing": False, "copilot": False},
save={"autosave": "after_delay", "autosave_delay": 2},
keymap={"preset": "vim"},
)
diff --git a/marimo/_server/api/save_user_config.py b/marimo/_server/api/save_user_config.py
index 9b763caa43..732cac8cad 100644
--- a/marimo/_server/api/save_user_config.py
+++ b/marimo/_server/api/save_user_config.py
@@ -69,6 +69,9 @@ class SaveUserConfigurationHandler(tornado.web.RequestHandler):
) from e
# Update the server's view of the config
- configure(args.config)
+ config = configure(args.config)
+ LOGGER.debug("Starting copilot server")
+ if config["completion"]["copilot"]:
+ sessions.get_manager().start_lsp_server()
# Update the kernel's view of the config
session.queue.put(requests.ConfigurationRequest(str(args.config)))
diff --git a/marimo/_server/server.py b/marimo/_server/server.py
index 0639d17ac5..a8be625e97 100644
--- a/marimo/_server/server.py
+++ b/marimo/_server/server.py
@@ -62,7 +62,7 @@ def shutdown(with_error: bool = False) -> None:
"\033[32mThanks for using marimo!\033[0m %s" % _utf8("🌊🍃")
)
print()
- mgr.close_all_sessions()
+ mgr.shutdown()
tornado.ioloop.IOLoop.current().stop()
if with_error:
sys.exit(1)
@@ -133,50 +133,11 @@ class ShutdownHandler(tornado.web.RequestHandler):
shutdown()
-async def start_server(
- port: Optional[int] = None,
- headless: bool = False,
- filename: Optional[str] = None,
- run: bool = False,
- development_mode: bool = False,
- quiet: bool = False,
-) -> None:
- """Start the server.
-
- Args:
- ----
- port: port on which to listen
- headless: if False, opens a client connection in user's browser
- filename: path to marimo app to serve; if None, opens a blank app
- run: if True, starts the server in run (read-only) mode; if False, runs
- in edit (read-write) mode.
- development_mode: if True, enables tornado debug logging and autoreloading
- """
- # Initialization
- logger = _loggers.marimo_logger()
- _loggers.initialize_tornado_loggers(development_mode)
- session_mgr = sessions.initialize_manager(
- filename=filename,
- mode=(
- sessions.SessionMode.EDIT if not run else sessions.SessionMode.RUN
- ),
- development_mode=development_mode,
- quiet=quiet,
- )
- try:
- load_config()
- except Exception as e:
- logger.fatal("Error parsing the marimo configuration file: ")
- logger.fatal(type(e).__name__ + ": " + str(e))
- shutdown(with_error=True)
-
- signal.signal(signal.SIGINT, interrupt_handler)
-
- root = os.path.realpath(
- importlib_resources.files("marimo").joinpath("_static")
- )
+def construct_app(
+ root: str, development_mode: bool
+) -> tornado.web.Application:
static_dir = os.path.join(root, "assets")
- app = tornado.web.Application(
+ return tornado.web.Application(
[
(r"/", MainHandler),
(r"/iosocket", sessions.IOSocketHandler),
@@ -268,6 +229,11 @@ async def start_server(
websocket_ping_timeout=60,
)
+
+def connect_app(app: tornado.web.Application, port: Optional[int]) -> int:
+ from marimo import _loggers
+
+ logger = _loggers.marimo_logger()
port_requested_by_user = port is not None
if port is None:
port = DEFAULT_PORT
@@ -294,9 +260,58 @@ async def start_server(
raise RuntimeError(
f"Could not find a free port (tried {max_attempts} ports)."
)
+ return port
- url = f"http://localhost:{port}"
+async def start_server(
+ port: Optional[int] = None,
+ headless: bool = False,
+ filename: Optional[str] = None,
+ run: bool = False,
+ development_mode: bool = False,
+ quiet: bool = False,
+) -> None:
+ """Start the server.
+
+ Args:
+ ----
+ port: port on which to listen
+ headless: if False, opens a client connection in user's browser
+ filename: path to marimo app to serve; if None, opens a blank app
+ run: if True, starts the server in run (read-only) mode; if False, runs
+ in edit (read-write) mode.
+ development_mode: if True, enables tornado debug logging and autoreloading
+ """
+ logger = _loggers.marimo_logger()
+ _loggers.initialize_tornado_loggers(development_mode)
+ signal.signal(signal.SIGINT, interrupt_handler)
+
+ root = os.path.realpath(
+ importlib_resources.files("marimo").joinpath("_static")
+ )
+ app = construct_app(root=root, development_mode=development_mode)
+ port = connect_app(app, port)
+ session_mgr = sessions.initialize_manager(
+ filename=filename,
+ mode=(
+ sessions.SessionMode.EDIT if not run else sessions.SessionMode.RUN
+ ),
+ port=port,
+ development_mode=development_mode,
+ quiet=quiet,
+ )
+
+ try:
+ load_config()
+ except Exception as e:
+ logger.fatal("Error parsing the marimo configuration file: ")
+ logger.fatal(type(e).__name__ + ": " + str(e))
+ shutdown(with_error=True)
+
+ if not run and get_configuration()["completion"]["copilot"]:
+ session_mgr.start_lsp_server()
+
+ url = f"http://localhost:{port}"
if not headless:
if which("xdg-open") is not None:
with open(os.devnull, "w") as devnull:
diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.py
index 4ecee59871..c484ad13fe 100644
--- a/marimo/_server/sessions.py
+++ b/marimo/_server/sessions.py
@@ -19,12 +19,14 @@ import multiprocessing as mp
import os
import queue
import signal
+import subprocess
import sys
import threading
from enum import Enum
from multiprocessing import connection
from typing import Any, Callable, Optional
+import importlib_resources
import tornado.httputil
import tornado.ioloop
import tornado.web
@@ -368,11 +370,15 @@ class SessionManager:
self,
filename: Optional[str],
mode: SessionMode,
+ port: int,
development_mode: bool,
quiet: bool,
) -> None:
self.filename = filename
self.mode = mode
+ self.port = port
+ self.lsp_port = int(self.port * 10)
+ self.lsp_process: Optional[subprocess.Popen[bytes]] = None
self.development_mode = development_mode
self.quiet = quiet
self.sessions: dict[str, Session] = {}
@@ -426,6 +432,32 @@ class SessionManager:
return True
return False
+ def start_lsp_server(self) -> None:
+ """Starts the lsp server if it is not already started.
+
+ Doesn't start in run mode.
+ """
+ if self.lsp_process is not None or self.mode == SessionMode.RUN:
+ return
+
+ lsp_bin = os.path.join(
+ str(importlib_resources.files("marimo").joinpath("_lsp")),
+ "index.js",
+ )
+ cmd = f"node {lsp_bin} --port {self.lsp_port}"
+ try:
+ self.lsp_process = subprocess.Popen(
+ cmd.split(),
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ stdin=subprocess.DEVNULL,
+ )
+ LOGGER.debug("Starting LSP server at port %s", self.lsp_port)
+ except Exception as e:
+ LOGGER.error(
+ "When starting language server (%s), got error: %s", cmd, e
+ )
+
def close_session(self, session_id: str) -> None:
LOGGER.debug("closing session %s", session_id)
session = self.get_session(session_id)
@@ -440,6 +472,11 @@ class SessionManager:
LOGGER.debug("All sessions closed.")
self.sessions = {}
+ def shutdown(self) -> None:
+ self.close_all_sessions()
+ if self.lsp_process is not None:
+ self.lsp_process.terminate()
+
def requires_edit(handler: Callable[..., Any]) -> Callable[..., Any]:
"""Mark a function as requiring edit permissions.
@@ -462,6 +499,7 @@ def requires_edit(handler: Callable[..., Any]) -> Callable[..., Any]:
def initialize_manager(
filename: Optional[str],
mode: SessionMode,
+ port: int,
development_mode: bool,
quiet: bool,
) -> SessionManager:
@@ -470,6 +508,7 @@ def initialize_manager(
SESSION_MANAGER = SessionManager(
filename=filename,
mode=mode,
+ port=port,
development_mode=development_mode,
quiet=quiet,
)
diff --git a/scripts/buildlsp.sh b/scripts/buildlsp.sh
new file mode 100755
index 0000000000..e70ac5c0ab
--- /dev/null
+++ b/scripts/buildlsp.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+cd lsp
+if pnpm build; then
+ echo "Removing old lsp files..."
+ rm -rf ../marimo/_lsp/
+ echo "Copying new lsp files..."
+ mkdir -p ../marimo/_lsp/
+ cp -R dist/* ../marimo/_lsp/
+ echo "Compilation succeeded.\n"
+else
+ echo "LSP compilation failed.\n"
+fi