palantir / python-language-server

An implementation of the Language Server Protocol for Python
MIT License
2.61k stars 285 forks source link

goToDefinition do not honor the client rootPath #755

Open jion opened 4 years ago

jion commented 4 years ago

Scenario:

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?

rwols commented 4 years ago

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.