Skip to content

Handle "untitled" files in Neovim #15392

@dhruvmanila

Description

@dhruvmanila

Currently, the language server crashes with the following panic:

   0.000076625s  INFO main ruff_server::server: No workspace settings found for file:///Users/dhruv/playground/ruff, using default settings
   0.016819875s DEBUG ThreadId(15) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Users/dhruv/playground/ruff/.vscode
   0.025011584s  INFO main ruff_server::session::index: Registering workspace: /Users/dhruv/playground/ruff
   0.025738917s TRACE ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter
   0.026116917s TRACE ruff:worker:0 request{id=2 method="textDocument/diagnostic"}: ruff_server::server::api: enter
   0.026236834s DEBUG ruff:worker:0 request{id=2 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via `include`: /Users/dhruv/playground/ruff/type_inference/definition_vs_declaration.py
   0.027171209s  INFO     ruff:main ruff_server::server: Configuration file watcher successfully registered
  24.044284625s TRACE     ruff:main notification{method="workspace/didChangeWorkspaceFolders"}: ruff_server::server::api: enter
  24.044426375s ERROR     ruff:main notification{method="workspace/didChangeWorkspaceFolders"}: ruff_server::server::api: An error occurred while running workspace/didChangeWorkspaceFolders: Failed to convert workspace URL to file path: file://./
  24.044570667s TRACE     ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter
  24.100126375s  WARN     ruff:main ruff_server::session::index: No settings available for file:/// - falling back to default settings
  24.101414459s TRACE ruff:worker:2 request{id=3 method="textDocument/diagnostic"}: ruff_server::server::api: enter
  24.101510542s DEBUG ruff:worker:2 request{id=3 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via Python language ID: /
  24.101617792s ERROR ruff:worker:2 request{id=3 method="textDocument/diagnostic"}: ruff_server::server: panicked at crates/ruff_server/src/lint.rs:89:18:
a path to a document should have a parent path

At 24.044284625s, the unnamed buffer has been assigned the filetype as Python in Neovim which triggers the following notifications from the client to the server:

didChangeWorkspaceFolders:

[DEBUG][2025-01-10 13:32:36] .../vim/lsp/rpc.lua:286	"rpc.send"	{
  jsonrpc = "2.0",
  method = "workspace/didChangeWorkspaceFolders",
  params = {
    event = {
      added = { {
          name = ".",
          uri = "file://."
        } },
      removed = {}
    }
  }
}

which fails with the following error:

  24.044426375s ERROR     ruff:main notification{method="workspace/didChangeWorkspaceFolders"}: ruff_server::server::api: An error occurred while running workspace/didChangeWorkspaceFolders: Failed to convert workspace URL to file path: file://./

textDocument/didOpen:

[DEBUG][2025-01-10 13:32:36] .../vim/lsp/rpc.lua:286	"rpc.send"	{
  jsonrpc = "2.0",
  method = "textDocument/didOpen",
  params = {
    textDocument = {
      languageId = "python",
      text = "\n",
      uri = "file://",
      version = 0
    }
  }
}

textDocument/diagnostic:

[DEBUG][2025-01-10 13:32:36] .../vim/lsp/rpc.lua:286	"rpc.send"	{
  id = 2,
  jsonrpc = "2.0",
  method = "textDocument/diagnostic",
  params = {
    range = {
      ["end"] = {
        character = 0,
        line = 1
      },
      start = {
        character = 0,
        line = 0
      }
    },
    textDocument = {
      uri = "file://"
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions