python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

goToDefinition do not honor the client rootPath

Open jion opened this issue 5 years ago • 1 comments

Scenario:

  • Using a docker container to encapsulate Python environment for my project.
  • There is a directory in my local machine, let's say /home/me/dev/my_project, where my source code lives. I edit python files inside that directory.
  • Inside the docker container, my dev directory is mounted as a volume into another location, lets say /app/my_project

When my editor initializes, it communicates to the language server which is my rootUri:

{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "textDocument": {
        "codeLens": {
          "dynamicRegistration": true
        },
        "colorProvider": null,
        "completion": {
          "completionItem": {
            "snippetSupport": false
          }
        },
        "declaration": {
          "linkSupport": true
        },
        "definition": {
          "linkSupport": true
        },
        "implementation": {
          "linkSupport": true
        },
        "publishDiagnostics": {
          "relatedInformation": true
        },
        "signatureHelp": {
          "signatureInformation": {
            "parameterInformation": {
              "labelOffsetSupport": true
            }
          }
        },
        "typeDefinition": {
          "linkSupport": true
        }
      },
      "workspace": {
        "applyEdit": true,
        "didChangeWatchedFiles": {
          "dynamicRegistration": true
        }
      }
    },
    "processId": 4361,
    "rootPath": "/home/me/dev/my_project",
    "rootUri": "file:///home/me/dev/my_project",
    "trace": "off"
  },
  "id": 1
}

But when calling textDocument/definition to jump into a definition that is inside my workspace, even when it understands in which file I'm executing the command (given that the request specifies the filename with the base URI of my local filesystem, i.e. file:///home/me/dev/my_project/some_python_file.py), the language server returns a reference to his own filesystem: Editor request:

{
  "jsonrpc": "2.0",
  "method": "textDocument/definition",
  "params": {
    "bufnr": 1,
    "filename": "/home/me/dev/my_project/main.py",
    "gotoCmd": null,
    "handle": true,
    "languageId": "python",
    "method": "textDocument/definition",
    "position": {
      "character": 35,
      "line": 30
    },
    "textDocument": {
      "uri": "file:///home/me/dev/my_project/main.py"
    }
  },
  "id": 3
}

Python Language Server response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": [
    {
      "range": {
        "start": {
          "line": 3,
          "character": 6
        },
        "end": {
          "line": 3,
          "character": 21
        }
      },
      "uri": "file:///app/my_project/placement/plugins/base.py"
    }
  ]
}

so my editor can't find the file in the filesystem. I'm not sure what the specification says about these not-in-the-same-filesystem environments, but shouldn't the language server respond with the adapted base URI?

jion avatar Feb 25 '20 20:02 jion

I think the editor is supposed to do the path translations. There's an old issue here https://github.com/sublimelsp/LSP/issues/535 that might be relevant.

rwols avatar Jun 15 '20 14:06 rwols