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.

chore: bump codemirror-languageserver, fix GitHub Copilot incremental updates (#4492)

Myles Scolnicke9be60339ad0
diff --git a/frontend/package.json b/frontend/package.json
index 1397425955..635a87f50c 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -43,7 +43,7 @@
"@lezer/markdown": "^1.4.2",
"@lezer/python": "^1.1.17",
"@marimo-team/codemirror-ai": "^0.1.11",
- "@marimo-team/codemirror-languageserver": "^1.15.7",
+ "@marimo-team/codemirror-languageserver": "^1.15.13",
"@marimo-team/marimo-api": "file:../openapi",
"@marimo-team/react-slotz": "^0.1.8",
"@open-rpc/client-js": "^1.8.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index a65126c669..f6adda518f 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -106,8 +106,8 @@ importers:
specifier: ^0.1.11
version: 0.1.11(@codemirror/[email protected])(@codemirror/[email protected])
'@marimo-team/codemirror-languageserver':
- specifier: ^1.15.7
- version: 1.15.7(@codemirror/[email protected])(@codemirror/[email protected])
+ specifier: ^1.15.13
+ version: 1.15.13(@codemirror/[email protected])(@codemirror/[email protected])
'@marimo-team/marimo-api':
specifier: file:../openapi
version: file:../openapi
@@ -1570,8 +1570,8 @@ packages:
'@codemirror/state': ^6
'@codemirror/view': ^6
- '@marimo-team/[email protected]':
- resolution: {integrity: sha512-g9p8mWemJcvFo8H3wzjrERKeDXzT+uVXj3q28kiMqMk92mnA/+mEZIYkl1aiPT87UZ7iTY5Uk8Gom0hCVsWAdw==}
+ '@marimo-team/[email protected]':
+ resolution: {integrity: sha512-Ff7ED3wI4TPyyZjEK//asxfaWHU+0Duhkg7n+dDUKOcOwnq0IsNrqYtWmKYTV2hb8KSIjZre9xfIwM3fh1FSug==}
peerDependencies:
'@codemirror/state': ^6
'@codemirror/view': ^6
@@ -10351,7 +10351,7 @@ snapshots:
'@codemirror/state': 6.5.2
'@codemirror/view': 6.36.5
- '@marimo-team/[email protected](@codemirror/[email protected])(@codemirror/[email protected])':
+ '@marimo-team/[email protected](@codemirror/[email protected])(@codemirror/[email protected])':
dependencies:
'@codemirror/autocomplete': 6.18.6
'@codemirror/lint': 6.8.5
diff --git a/frontend/src/core/codemirror/copilot/client.ts b/frontend/src/core/codemirror/copilot/client.ts
index d9d9182bd9..230c061340 100644
--- a/frontend/src/core/codemirror/copilot/client.ts
+++ b/frontend/src/core/codemirror/copilot/client.ts
@@ -113,5 +113,6 @@ export function copilotServer() {
codeActionsEnabled: false,
signatureHelpEnabled: false,
diagnosticsEnabled: false,
+ sendIncrementalChanges: false,
});
}
diff --git a/frontend/src/core/codemirror/copilot/language-server.ts b/frontend/src/core/codemirror/copilot/language-server.ts
index bf2dc949ed..16081a9ada 100644
--- a/frontend/src/core/codemirror/copilot/language-server.ts
+++ b/frontend/src/core/codemirror/copilot/language-server.ts
@@ -49,6 +49,7 @@ export interface LSPRequestMap {
*/
export class CopilotLanguageServerClient extends LanguageServerClient {
private documentVersion = 0;
+ private hasOpenedDocument = false;
private async _request<Method extends keyof LSPRequestMap>(
method: Method,
@@ -73,6 +74,7 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
if (this.isDisabled()) {
return params;
}
+ this.hasOpenedDocument = true;
return super.textDocumentDidOpen(params);
}
@@ -89,9 +91,37 @@ export class CopilotLanguageServerClient extends LanguageServerClient {
if (this.isDisabled()) {
return params;
}
+
+ if (!this.hasOpenedDocument) {
+ await this.textDocumentDidOpen({
+ textDocument: {
+ uri: params.textDocument.uri,
+ languageId: "python",
+ version: params.textDocument.version,
+ text: params.contentChanges[0].text,
+ },
+ });
+ }
+
+ const changes = params.contentChanges;
+ if (changes.length !== 1) {
+ Logger.warn(
+ "CopilotLanguageServerClient#textDocumentDidChange: Multiple changes detected. This is not supported.",
+ changes,
+ );
+ }
+ const change = changes[0];
+ if ("range" in change) {
+ Logger.warn(
+ "CopilotLanguageServerClient#textDocumentDidChange: Copilot doesn't support range changes.",
+ change,
+ );
+ }
+
+ const text = getCodes(change.text);
return super.textDocumentDidChange({
...params,
- contentChanges: [{ text: getCodes(params.contentChanges[0].text) }],
+ contentChanges: [{ text: text }],
textDocument: VersionedTextDocumentIdentifier.create(
params.textDocument.uri,
++this.documentVersion,
diff --git a/frontend/src/core/codemirror/language/python.ts b/frontend/src/core/codemirror/language/python.ts
index f8442f11b3..967f758754 100644
--- a/frontend/src/core/codemirror/language/python.ts
+++ b/frontend/src/core/codemirror/language/python.ts
@@ -185,6 +185,7 @@ export class PythonLanguageAdapter implements LanguageAdapter {
completionConfig: autocompleteOptions,
// Default to false
diagnosticsEnabled: lspConfig.diagnostics?.enabled ?? false,
+ sendIncrementalChanges: false,
signatureHelpEnabled: true,
signatureActivateOnTyping: false,
keyboardShortcuts: {
diff --git a/frontend/src/core/codemirror/lsp/notebook-lsp.ts b/frontend/src/core/codemirror/lsp/notebook-lsp.ts
index ba2583fa20..116f19ba2b 100644
--- a/frontend/src/core/codemirror/lsp/notebook-lsp.ts
+++ b/frontend/src/core/codemirror/lsp/notebook-lsp.ts
@@ -7,8 +7,8 @@ import { invariant } from "@/utils/invariant";
import { Logger } from "@/utils/Logger";
import { LRUCache } from "@/utils/lru";
import type { CellId } from "@/core/cells/ids";
-import { getFilenameFromDOM } from "@/core/dom/htmlUtils";
import type { EditorView } from "@codemirror/view";
+import { getLSPDocument } from "./utils";
export class NotebookLanguageServerClient implements ILanguageServerClient {
public readonly documentUri: LSP.DocumentUri;
@@ -33,7 +33,7 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
client: ILanguageServerClient,
initialSettings: Record<string, unknown>,
) {
- this.documentUri = `file://${getFilenameFromDOM() ?? "/__marimo_notebook__.py"}`;
+ this.documentUri = getLSPDocument();
this.client = client;
this.patchProcessNotification();
diff --git a/frontend/src/core/codemirror/lsp/utils.ts b/frontend/src/core/codemirror/lsp/utils.ts
new file mode 100644
index 0000000000..ffd54bd3a2
--- /dev/null
+++ b/frontend/src/core/codemirror/lsp/utils.ts
@@ -0,0 +1,6 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import { getFilenameFromDOM } from "@/core/dom/htmlUtils";
+
+export function getLSPDocument() {
+ return `file://${getFilenameFromDOM() ?? "/__marimo_notebook__.py"}`;
+}