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

Handle "untitled" files in Neovim #15392

Open
dhruvmanila opened this issue Jan 10, 2025 · 11 comments
Open

Handle "untitled" files in Neovim #15392

dhruvmanila opened this issue Jan 10, 2025 · 11 comments
Labels
bug Something isn't working server Related to the LSP server

Comments

@dhruvmanila
Copy link
Member

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://"
    }
  }
}
@dhruvmanila dhruvmanila added bug Something isn't working server Related to the LSP server labels Jan 10, 2025
@MichaReiser
Copy link
Member

Hmm this is interesting. Can you open multiple unnamed buffers? Do they get unique uris? Is this even a valid file path?

@dhruvmanila
Copy link
Member Author

Yes, you can open multiple unnamed buffers. They are using the same URIs.

@MichaReiser
Copy link
Member

MichaReiser commented Jan 10, 2025

Yes, you can open multiple unnamed buffers. They are using the same URIs.

That at least seems a bug to me in neovim because the server can now no longer distinguish between them. I think neovim should not use file::// for unnamed buffers but do the same as VS code and use some other non-file path

@MichaReiser
Copy link
Member

See #12336

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Jan 10, 2025

Yeah, I saw the Neovim issue (neovim/neovim#21276) but that seems to have concluded with continue using "file://" until using "untitled://" is actually the recommended way in the protocol.

@dhruvmanila
Copy link
Member Author

So, this was merged neovim/neovim#22407 but was quickly reverted neovim/neovim#22604

@dhruvmanila
Copy link
Member Author

Could this be a bug in the URI parsing library? The vscode-uri library is able to parse file://./:

l {
  scheme: 'file',
  authority: '.',
  path: '/',
  query: '',
  fragment: '',
  _formatted: null,
  _fsPath: null
}

@dhruvmanila
Copy link
Member Author

And, I think this is why Pyright raised "heap out of memory" error because it tried to index the entire home directory.

@MichaReiser
Copy link
Member

I think we're able to parse it but . has no parent directory

@dhruvmanila
Copy link
Member Author

I think we're able to parse it but . has no parent directory

I don't think so:

  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://./

which happens at:

let workspace_path = workspace_url.to_file_path().map_err(|()| {
anyhow!("Failed to convert workspace URL to file path: {workspace_url}")
})?;

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Jan 10, 2025

Oh so we can parse it but it's not being considered a valid file path (sorry!)

And, yes, you're correct about the parent directory part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

No branches or pull requests

2 participants