Skip to content

Commit 19d830a

Browse files
authored
fix: LSP reconfiguration missing cell-id (#8050)
1 parent 984b0ab commit 19d830a

File tree

8 files changed

+24
-1
lines changed

8 files changed

+24
-1
lines changed

‎frontend/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function createMockEditorView(code: string): EditorView {
4444
lspConfig: {},
4545
}),
4646
cellConfigExtension({
47+
cellId: "cell1" as CellId,
4748
completionConfig: {
4849
copilot: false,
4950
activate_on_typing: true,

‎frontend/src/core/codemirror/cm.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const setupCodeMirror = (opts: CodeMirrorSetupOpts): Extension[] => {
115115
jupyterHelpExtension(),
116116
// Cell editing
117117
cellConfigExtension({
118+
cellId,
118119
completionConfig,
119120
hotkeys,
120121
placeholderType,

‎frontend/src/core/codemirror/config/extension.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ export const lspConfigState = singleFacet<
4141
* Extension for cell config
4242
*/
4343
export function cellConfigExtension({
44+
cellId,
4445
completionConfig,
4546
hotkeys,
4647
placeholderType,
4748
lspConfig,
4849
diagnosticsConfig,
4950
}: {
51+
cellId: CellId;
5052
completionConfig: CompletionConfig;
5153
hotkeys: HotkeyProvider;
5254
placeholderType: PlaceholderType;
@@ -55,6 +57,7 @@ export function cellConfigExtension({
5557
}) {
5658
return [
5759
// Store state
60+
cellIdState.of(cellId),
5861
completionConfigState.of(completionConfig),
5962
hotkeysProviderState.of(hotkeys),
6063
placeholderState.of(placeholderType),

‎frontend/src/core/codemirror/copilot/__tests__/getCodes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function createMockEditorView(code: string) {
4545
lspConfig: {},
4646
}),
4747
cellConfigExtension({
48+
cellId: "cell1" as CellId,
4849
completionConfig: {
4950
copilot: false,
5051
activate_on_typing: true,

‎frontend/src/core/codemirror/facet.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { Facet } from "@codemirror/state";
1414
*/
1515
export function singleFacet<T>() {
1616
return Facet.define<T, T>({
17-
combine: (values) => values[0],
17+
combine: (values) => {
18+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19+
return values.find((v) => v !== undefined)!;
20+
},
1821
});
1922
}

‎frontend/src/core/codemirror/language/__tests__/extension.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function createState(content: string, selection?: { anchor: number }) {
4949
placeholderType: "marimo-import",
5050
}),
5151
cellConfigExtension({
52+
cellId: "cell1" as CellId,
5253
completionConfig: {
5354
copilot: false,
5455
activate_on_typing: true,

‎frontend/src/core/codemirror/language/__tests__/utils.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function createEditor(doc: string) {
3131
lspConfig: {},
3232
}),
3333
cellConfigExtension({
34+
cellId: "cell1" as CellId,
3435
completionConfig: {
3536
activate_on_typing: true,
3637
signature_hint_on_typing: false,

‎frontend/src/core/codemirror/language/extension.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
LSPConfig,
1616
} from "@/core/config/config-schema";
1717
import type { HotkeyProvider } from "@/core/hotkeys/hotkeys";
18+
import { Logger } from "@/utils/Logger";
1819
import { clamp } from "@/utils/math";
1920
import {
2021
cellIdState,
@@ -310,6 +311,17 @@ export function reconfigureLanguageEffect(
310311
const language = view.state.field(languageAdapterState);
311312
const placeholderType = view.state.facet(placeholderState);
312313
const cellId = view.state.facet(cellIdState);
314+
315+
if (cellId === undefined) {
316+
Logger.error("Cell ID is undefined in reconfigureLanguageEffect");
317+
}
318+
if (placeholderType === undefined) {
319+
Logger.error("Placeholder type is undefined in reconfigureLanguageEffect");
320+
}
321+
if (completionConfig === undefined) {
322+
Logger.error("Completion config is undefined in reconfigureLanguageEffect");
323+
}
324+
313325
return languageCompartment.reconfigure(
314326
language.getExtension(
315327
cellId,

0 commit comments

Comments
 (0)