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.

fix: LSP reconfiguration missing cell-id (#8050)

Myles Scolnick19d830a30f4c
diff --git a/frontend/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts b/frontend/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts
index 9316d064bb..9ad232afe2 100644
--- a/frontend/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts
+++ b/frontend/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts
@@ -44,6 +44,7 @@ function createMockEditorView(code: string): EditorView {
lspConfig: {},
}),
cellConfigExtension({
+ cellId: "cell1" as CellId,
completionConfig: {
copilot: false,
activate_on_typing: true,
diff --git a/frontend/src/core/codemirror/cm.ts b/frontend/src/core/codemirror/cm.ts
index a858754f68..8ec91eb252 100644
--- a/frontend/src/core/codemirror/cm.ts
+++ b/frontend/src/core/codemirror/cm.ts
@@ -115,6 +115,7 @@ export const setupCodeMirror = (opts: CodeMirrorSetupOpts): Extension[] => {
jupyterHelpExtension(),
// Cell editing
cellConfigExtension({
+ cellId,
completionConfig,
hotkeys,
placeholderType,
diff --git a/frontend/src/core/codemirror/config/extension.ts b/frontend/src/core/codemirror/config/extension.ts
index 42d3762f19..71b1f61a11 100644
--- a/frontend/src/core/codemirror/config/extension.ts
+++ b/frontend/src/core/codemirror/config/extension.ts
@@ -41,12 +41,14 @@ export const lspConfigState = singleFacet<
* Extension for cell config
*/
export function cellConfigExtension({
+ cellId,
completionConfig,
hotkeys,
placeholderType,
lspConfig,
diagnosticsConfig,
}: {
+ cellId: CellId;
completionConfig: CompletionConfig;
hotkeys: HotkeyProvider;
placeholderType: PlaceholderType;
@@ -55,6 +57,7 @@ export function cellConfigExtension({
}) {
return [
// Store state
+ cellIdState.of(cellId),
completionConfigState.of(completionConfig),
hotkeysProviderState.of(hotkeys),
placeholderState.of(placeholderType),
diff --git a/frontend/src/core/codemirror/copilot/__tests__/getCodes.test.ts b/frontend/src/core/codemirror/copilot/__tests__/getCodes.test.ts
index eda71b10ab..67fd9d7869 100644
--- a/frontend/src/core/codemirror/copilot/__tests__/getCodes.test.ts
+++ b/frontend/src/core/codemirror/copilot/__tests__/getCodes.test.ts
@@ -45,6 +45,7 @@ function createMockEditorView(code: string) {
lspConfig: {},
}),
cellConfigExtension({
+ cellId: "cell1" as CellId,
completionConfig: {
copilot: false,
activate_on_typing: true,
diff --git a/frontend/src/core/codemirror/facet.ts b/frontend/src/core/codemirror/facet.ts
index 8a347e8cae..8943a7b5e7 100644
--- a/frontend/src/core/codemirror/facet.ts
+++ b/frontend/src/core/codemirror/facet.ts
@@ -14,6 +14,9 @@ import { Facet } from "@codemirror/state";
*/
export function singleFacet<T>() {
return Facet.define<T, T>({
- combine: (values) => values[0],
+ combine: (values) => {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return values.find((v) => v !== undefined)!;
+ },
});
}
diff --git a/frontend/src/core/codemirror/language/__tests__/extension.test.ts b/frontend/src/core/codemirror/language/__tests__/extension.test.ts
index d1aa109711..c5d8e29508 100644
--- a/frontend/src/core/codemirror/language/__tests__/extension.test.ts
+++ b/frontend/src/core/codemirror/language/__tests__/extension.test.ts
@@ -49,6 +49,7 @@ function createState(content: string, selection?: { anchor: number }) {
placeholderType: "marimo-import",
}),
cellConfigExtension({
+ cellId: "cell1" as CellId,
completionConfig: {
copilot: false,
activate_on_typing: true,
diff --git a/frontend/src/core/codemirror/language/__tests__/utils.test.ts b/frontend/src/core/codemirror/language/__tests__/utils.test.ts
index 304d91a0e7..7aae643cf0 100644
--- a/frontend/src/core/codemirror/language/__tests__/utils.test.ts
+++ b/frontend/src/core/codemirror/language/__tests__/utils.test.ts
@@ -31,6 +31,7 @@ function createEditor(doc: string) {
lspConfig: {},
}),
cellConfigExtension({
+ cellId: "cell1" as CellId,
completionConfig: {
activate_on_typing: true,
signature_hint_on_typing: false,
diff --git a/frontend/src/core/codemirror/language/extension.ts b/frontend/src/core/codemirror/language/extension.ts
index e804babf53..8c556186a2 100644
--- a/frontend/src/core/codemirror/language/extension.ts
+++ b/frontend/src/core/codemirror/language/extension.ts
@@ -15,6 +15,7 @@ import type {
LSPConfig,
} from "@/core/config/config-schema";
import type { HotkeyProvider } from "@/core/hotkeys/hotkeys";
+import { Logger } from "@/utils/Logger";
import { clamp } from "@/utils/math";
import {
cellIdState,
@@ -310,6 +311,17 @@ export function reconfigureLanguageEffect(
const language = view.state.field(languageAdapterState);
const placeholderType = view.state.facet(placeholderState);
const cellId = view.state.facet(cellIdState);
+
+ if (cellId === undefined) {
+ Logger.error("Cell ID is undefined in reconfigureLanguageEffect");
+ }
+ if (placeholderType === undefined) {
+ Logger.error("Placeholder type is undefined in reconfigureLanguageEffect");
+ }
+ if (completionConfig === undefined) {
+ Logger.error("Completion config is undefined in reconfigureLanguageEffect");
+ }
+
return languageCompartment.reconfigure(
language.getExtension(
cellId,