Skip to content

LSP diagnostics (Ruff) persist after fixing code #8687

@daizutabi

Description

@daizutabi

Describe the bug

LSP diagnostics (such as Ruff's "Undefined name") are not cleared and remain visible in the cell editor even after the code is fixed (e.g., changing a to a = 1).

This has been observed on Windows (Native, WSL2, devcontainer). I am not sure if this issue persists on other platforms.

1. Enter a (Error appears) 2. Change to a = 1 (Error remains)
Image Image

I experimented with the code in frontend/src/core/codemirror/lsp/notebook-lsp.ts and found that the publishDiagnostics notification for clearing errors was missing the version field.

After I manually added the version field to the "clear" loop in the patchProcessNotification method, the diagnostics started clearing correctly.

However, I am not certain if this is the correct way to fix the issue.

(Update: This fix also resolved persistent diagnostics in basedpyright.)

// frontend/src/core/codemirror/lsp/notebook-lsp.ts

// ... inside patchProcessNotification's clear loop
for (const cellDocumentUri of cellsToClear) {
  previousProcessNotification({
    method: "textDocument/publishDiagnostics",
    params: {
      uri: cellDocumentUri,
      version: cellVersion, // <--- Adding this line fixed the issue
      diagnostics: [],
    },
  });
}

Will you submit a PR?

  • Yes

Environment

Details
{
  "marimo": "0.20.4",
  "editable": true,
  "location": "/workspaces/marimo/marimo",
  "OS": "Linux",
  "OS Version": "6.6.87.2-microsoft-standard-WSL2",
  "Processor": "x86_64",
  "Python Version": "3.12.13",
  "Locale": "--",
  "Binaries": {
    "Browser": "--",
    "Node": "v22.22.0",
    "uv": "0.6.17"
  },
  "Dependencies": {
    "click": "8.3.1",
    "docutils": "0.22.4",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.10.2",
    "narwhals": "2.17.0",
    "packaging": "26.0",
    "psutil": "7.2.2",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.21",
    "pyyaml": "6.0.3",
    "starlette": "0.52.1",
    "tomlkit": "0.14.0",
    "typing-extensions": "4.15.0",
    "uvicorn": "0.41.0",
    "websockets": "16.0"
  },
  "Optional Dependencies": {
    "basedpyright": "1.38.2",
    "duckdb": "1.4.4",
    "loro": "1.10.3",
    "openai": "2.26.0",
    "pyarrow": "23.0.1",
    "pytest": "9.0.2",
    "python-lsp-ruff": "2.3.0",
    "python-lsp-server": "1.14.0",
    "ruff": "0.15.1",
    "sqlglot": "29.0.1"
  },
  "Experimental Flags": {
    "multi_column": true,
    "cache_panel": true
  }
}

Code to reproduce

  1. Create a new notebook.
  2. In a cell, type a.
  3. Wait for the LSP (Ruff) to show an error: Undefined name 'a'.
  4. Change the code to a = 1.
  5. Observed Behavior: The red underline and error message for Undefined name 'a' remain in the editor.
  6. Expected Behavior: The error should disappear immediately after the code becomes valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions