### Marimo App Initialization and Setup Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_setup.txt Initializes a Marimo app and imports necessary modules within the setup context. This code should be placed at the beginning of your Marimo application file. ```python import marimo __generated_with = "0.19.8" app = marimo.App() with app.setup: import marimo as mo import numpy as np ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Install pre-commit hooks to automate linting and formatting checks before each commit. ```sh uvx pre-commit install ``` -------------------------------- ### Setup Marimo Version Dependency Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Ensure the Marimo LSP extension is built against the correct Marimo version by cloning repositories side-by-side and checking out the matching version. ```sh cd ../marimo git checkout $(cat ../marimo-lsp/.marimo-version) ``` -------------------------------- ### Initialize Marimo App with Width Option Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_options.txt Initializes a Marimo app instance, setting the display width to 'medium'. This is a common starting point for Marimo applications. ```python import marimo __generated_with = "0.19.8" app = marimo.App(width="medium") ``` -------------------------------- ### Marimo App Setup and Cells Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_header_info.txt This snippet shows the basic structure of a Marimo application, including header directives, imports, app initialization, and defining two cells. The first cell generates random data, and the second calculates its mean and standard deviation. ```python # /// script # requires-python = ">=3.11" # dependencies = [ # "marimo", # ] # /// import marimo __generated_with = "0.16.2" app = marimo.App() with app.setup: import marimo as mo import numpy as np @app.cell def _(): data = np.random.randn(100) mo.md(f"Generated {len(data)} random numbers") return (data,) @app.cell def _(data): mean = data.mean() std = data.std() return if __name__ == "__main__": app.run() ``` -------------------------------- ### Marimo Cell for Data Generation Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_setup.txt Defines a Marimo cell that generates 100 random numbers using NumPy and displays a markdown string indicating the count. This cell depends on the 'numpy' and 'marimo' imports from the setup. ```python @app.cell def _(): data = np.random.randn(100) mo.md(f"Generated {len(data)} random numbers") return (data,) ``` -------------------------------- ### Navigate and Run Marimo LSP Extension Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Steps to clone the Marimo LSP project and launch the extension in VS Code for development. ```sh cd marimo-lsp code . # Press `F5` in VS Code (or "Run and Debug" > "Run Extension" in the UI). ``` -------------------------------- ### Run Common Development Commands with Just Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Execute common development tasks like linting, fixing, and testing using the 'just' command runner. ```sh just lint ``` ```sh just fix ``` ```sh just test ``` ```sh just test-vscode ``` ```sh just build ``` -------------------------------- ### Create an Interactive Slider Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/walkthroughs/create-notebook.md Import the marimo library and create an interactive slider UI element. This is a fundamental step for building interactive notebooks. ```python import marimo as mo # Create an interactive slider slider = mo.ui.slider(1, 100, value=50) ``` -------------------------------- ### Define Marimo App with Protocols Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_ellipsis.txt Sets up a Marimo application and defines two protocols, one with a standard property and another using ellipsis for its property. ```python import marimo __generated_with = "0.19.8" app = marimo.App(width="medium") with app.setup: from typing import Protocol @app.class_definition class GoodProtocol(Protocol): @property def prop(self) -> float: pass @app.class_definition class BadProtocol(Protocol): @property def prop(self) -> float: ... if __name__ == "__main__": app.run() ``` -------------------------------- ### Initialize Marimo App Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_names.txt Boilerplate code to initialize a Marimo application. This is typically placed at the beginning of your Marimo script. ```python import marimo __generated_with = "0.19.8" app = marimo.App() ``` -------------------------------- ### Run Marimo App Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_names.txt The standard Python entry point to run a Marimo application. This should be placed at the end of your script. ```python if __name__ == "__main__": app.run() ``` -------------------------------- ### Run Vitest Tests for LSP Services Source: https://github.com/marimo-team/marimo-lsp/blob/main/CLAUDE.md Utilize vitest for high-leverage testing of individual LSP services in partial isolation. This allows feeding services events and asserting on their behavior without booting the entire runtime. ```bash just test-ts ``` -------------------------------- ### Run VS Code Extension Integration Tests Source: https://github.com/marimo-team/marimo-lsp/blob/main/CLAUDE.md Use this command to run integration tests for the VS Code extension within a real VS Code instance. This provides high confidence in user-facing functionality. ```bash just test-vscode ``` -------------------------------- ### Run Pytest Integration Tests for LSP Source: https://github.com/marimo-team/marimo-lsp/blob/main/CLAUDE.md Execute integration tests using pytest and pytest-lsp, which spins up a real marimo-lsp subprocess over stdio. This is suitable for testing LSP request/response shapes. ```bash just test-py ``` -------------------------------- ### Pass Arguments to Test Commands Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Forward trailing arguments to underlying test runners like pytest or vitest when using 'just' recipes. ```sh just test-py -v # pytest with verbose output ``` ```sh just test-py tests/test_foo.py # specific test file ``` ```sh just test-ts --watch # vitest in watch mode ``` -------------------------------- ### Display Markdown in Marimo Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_names.txt Renders markdown content within a Marimo application. Use this to add rich text, headings, and formatting to your app. ```python mo.md(""" # Hello World """) ``` -------------------------------- ### Logging with Annotations Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Place variable data in log annotations rather than directly in the message string for better log analysis. ```typescript // Do yield * Effect.logInfo("Created notebook").pipe( Effect.annotateLogs({ uri: notebook.uri.toString() }), ); // Don't yield * Effect.logDebug(`Processing ${count} items`); ``` -------------------------------- ### Calculate and Append Output Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_names.txt Performs a calculation and appends the result to the Marimo output stream. This is useful for displaying intermediate or final results. ```python result = 42 * 2 mo.output.append(result) ``` -------------------------------- ### Create/Fix Inline Snapshots with Pytest Source: https://github.com/marimo-team/marimo-lsp/blob/main/CLAUDE.md Use this command to create or fix inline snapshots for pytest, useful for testing the expected shape of protocol messages or serialized output. Pair with dirty-equals matchers for non-deterministic fields. ```bash uv run pytest --inline-snapshot=create ``` ```bash uv run pytest --inline-snapshot=fix ``` -------------------------------- ### Named Effect Functions for Logging Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Use named Effect functions for entry points to enable automatic span creation. Use Effect.fnUntraced for inner callback functions to avoid unnecessary span overhead. ```typescript // Do: Named function at entry points export const myCommand = Effect.fn("command.myCommand")(function* () { // Do: Untraced for callbacks (avoids extra span overhead) yield* SynchronizedRef.updateEffect(ref, Effect.fnUntraced(function* (value) { ... })); }); // Don't: Anonymous at entry points export const myCommand = Effect.fn(function* () { ... }); ``` -------------------------------- ### Import Marimo in a Cell Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_names.txt Imports the marimo library within a specific cell of the application. This allows subsequent cells to use marimo functionalities. ```python import marimo as mo ``` -------------------------------- ### Display Slider Value with Markdown Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/walkthroughs/create-notebook.md Use marimo's markdown functionality to display the current value of an interactive element. This demonstrates marimo's reactivity. ```python # Display the slider and show its value mo.md(f"The slider value is: {slider.value}") ``` -------------------------------- ### Define a Simple Variable Cell Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/simple.txt A basic Marimo cell that defines a variable. This demonstrates a simple cell's functionality. ```python @app.cell def _(): x = 1 return ``` -------------------------------- ### Create and Process DataFrame in Marimo Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/multiline.txt Generates a pandas DataFrame with random data and performs operations like calculating row sums and means. This snippet demonstrates data manipulation within a Marimo cell. ```python # Create a dataframe with multiple operations df = pd.DataFrame({ 'A': np.random.randn(100), 'B': np.random.randn(100), 'C': np.random.randn(100) }) # Process the data df['sum'] = df.sum(axis=1) df['mean'] = df.mean(axis=1) return (df,) ``` -------------------------------- ### Import Data Science Libraries in Marimo Cell Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/multiline.txt Imports pandas, numpy, and matplotlib within a Marimo cell. These libraries are commonly used for data analysis and visualization. ```python import pandas as pd import numpy as np import matplotlib.pyplot as plt return np, pd, plt ``` -------------------------------- ### Plot DataFrame Columns in Marimo Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/multiline.txt Visualizes two columns ('A' and 'B') of a pandas DataFrame using matplotlib within a Marimo cell. Ensures the plot is displayed. ```python plt.figure(figsize=(10, 6)) plt.plot(df['A'], label='A') plt.plot(df['B'], label='B') plt.legend() plt.show() ``` -------------------------------- ### Marimo Cell with UI Element Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_options.txt Defines a Marimo cell that creates and displays a UI slider. The slider's value can be interacted with in the Marimo UI. ```python @app.cell def _(mo): value = mo.ui.slider(0, 100) value return ``` -------------------------------- ### Define a Marimo Cell Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/simple.txt Defines a cell within a Marimo application. Cells are the basic units of code and output in Marimo. ```python @app.cell def _(): import marimo as mo return ``` -------------------------------- ### Span Annotations for Context Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Utilize Effect.annotateCurrentSpan to add contextual information, such as counts or identifiers, to the current tracing span. ```typescript const refresh = Effect.fn("ControllerRegistry.refresh")(function* () { yield* Effect.annotateCurrentSpan("environmentCount", envs.length); // ... }); ``` -------------------------------- ### Marimo Cell for Data Analysis Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_setup.txt Defines a Marimo cell that calculates the mean and standard deviation of the 'data' generated in a previous cell. This cell takes 'data' as an argument, indicating a dependency. ```python @app.cell def _(data): mean = data.mean() std = data.std() return ``` -------------------------------- ### Disabled Marimo Cell Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_options.txt Creates a Marimo cell that is explicitly disabled using the `disabled=True` argument. Disabled cells will not execute their code and are visually indicated as inactive. ```python @app.cell(disabled=True) def _(mo): # This cell is disabled mo.md(""" This won't run """) return ``` -------------------------------- ### Marimo Cell with Hidden Code Source: https://github.com/marimo-team/marimo-lsp/blob/main/extension/src/__mocks__/notebooks/with_options.txt Defines a Marimo cell that imports the marimo library. The `hide_code=True` argument ensures that the code for this cell is not displayed in the Marimo UI. ```python @app.cell(hide_code=True) def _(): import marimo as mo return (mo,) ``` -------------------------------- ### Type Assertion with Safety Comment Source: https://github.com/marimo-team/marimo-lsp/blob/main/CLAUDE.md When a type assertion is necessary, a '// SAFETY:' comment must precede it, explaining the invariant being asserted. This ensures clarity and allows for verification of the reasoning. ```typescript // SAFETY: routeOperation only forwards cell-op messages whose cellId // is present in `executions`; we guard the lookup on line 84. const execution = executions.get(cellId) as NotebookCellExecution; ``` -------------------------------- ### Explicit Spans for Important Operations Source: https://github.com/marimo-team/marimo-lsp/blob/main/CONTRIBUTING.md Use Effect.withSpan to explicitly define spans for critical operations, allowing for detailed tracing with custom attributes. ```typescript yield * client .executeCommand(cmd) .pipe( Effect.withSpan("lsp.executeCommand", { attributes: { command: cmd.command }, }), ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.