Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to disable .ropeproject directory on Lua and Neovim #622

Open
mamekoro opened this issue Mar 2, 2025 · 4 comments
Open

No way to disable .ropeproject directory on Lua and Neovim #622

mamekoro opened this issue Mar 2, 2025 · 4 comments

Comments

@mamekoro
Copy link

mamekoro commented Mar 2, 2025

A user must set pylsp.rope.ropeFolder to null if they do not want to create a .ropeproject directory. However, this is not possible in Neovim because Lua 5.1, which is used for setting up LSPs in Neovim, does not allow nil values to be stored in tables. This issue can also arise in TOML, which lacks support for null values.

I have come up with two solutions.

  • Pass ropefolder=None to the constructor of Project on line 83 below.

    if "ropeFolder" in rope_config:
    self.__rope = Project(self._root_path, ropefolder=rope_folder)
    else:
    self.__rope = Project(self._root_path)

    This method changes the default behavior when pylsp.rope.ropeFolder is unspecified. That is, the .ropeproject directory will no longer be created by default, and if you wish to create it with the old default value, pass ".ropeproject" to the pylsp.rope.ropeFolder.

  • Create a new configuration key, e.g. pylsp.rope.disableRopeFolder.
    If its value is true, the .ropeproject directory will no longer be created. Most file formats that are used for LSP configuration (including Lua and TOML) should support boolean values, so this should work.

@HugoForrat
Copy link

Can't you just use vim.NIL?

@mamekoro
Copy link
Author

mamekoro commented Mar 5, 2025

I tried to test vim.NIL, but I'm not sure if pylsp.rope.ropeFolder is working correctly in the first place.

Here is a Dockerfile for reproduction. Please refer to the comment at the end for the test procedure.

# syntax=docker/dockerfile:1

FROM ubuntu:24.04

# Install apt packages.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
<<EOF
set -eu
rm /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache
apt-get update
apt-get install -y --no-install-recommends curl git python3 python3-venv
EOF

# Create a Python3 virtual environment and install pip packages.
RUN --mount=type=cache,target=/root/.cache/pip <<EOF
python3 -m venv /venv
. /venv/bin/activate
pip install pylsp-rope "python-lsp-server[all]"
echo '. /venv/bin/activate' >>~/.bashrc
EOF

# Install NeoVim.
RUN curl -sLS https://github.com/neovim/neovim/releases/download/v0.10.4/nvim-linux-x86_64.tar.gz | tar -xz -C /opt
ENV PATH="/opt/nvim-linux-x86_64/bin:$PATH"

# Install nvim-lspconfig.
RUN git clone --depth=1 --branch=v1.7.0 \
    https://github.com/neovim/nvim-lspconfig \
    ~/.config/nvim/pack/nvim/start/nvim-lspconfig

COPY <<EOF /app/main.py
print("hello")
EOF

# Configure pylsp.
RUN mkdir -p ~/.config/nvim
COPY <<EOF /root/.config/nvim/init.lua
require("lspconfig").pylsp.setup {
    settings = {
        pylsp = {
            rope = {
                -- I'm not sure if this line is working correctly.
                -- I can't test vim.NIL without confirming that this works.
                ropeFolder = "my_rope_folder",
            },
        },
    },
    on_attach = function(client, buf)
        -- Run code_action() to have pylsp-rope create a rope folder.
        vim.lsp.buf.code_action()
    end,
}
EOF

WORKDIR /app

# Test procedure:
# 1. Build and run this Docker image.
# 2. The entrypoint will run the `vim.lsp.buf.code_action()` function on the `/app/main.py` file.
#    Close NeoVim afterward.
# 3. The entrypoint will run `ls --almost-all`.
#    Check if it prints `my_rope_folder`.
#    If it does, the configuration `ropeFolder = "my_rope_folder"` is working as expected.
ENTRYPOINT ["/bin/bash", "-ic", "nvim main.py; ls --almost-all"]

If it works correctly, a directory named my_rope_folder should be created because the configuration has the line ropeFolder = "my_rope_folder".
However, the ls command prints .ropeproject main.py. Is this another bug?

@HugoForrat
Copy link

CONFIGURATION.md specifies that pylsp.rope.ropeFolder is an "array of unique string items", so I assume it should be

pylsp = {
    rope = {
        ropeFolder = { "my_rope_folder" },
    },
},

@mamekoro
Copy link
Author

mamekoro commented Mar 5, 2025

I tried it, but I still get the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants