coc-python icon indicating copy to clipboard operation
coc-python copied to clipboard

Jump To Definition does not work for modules inside site-packages

Open Dissonant-Tech opened this issue 5 years ago • 10 comments
trafficstars

When calling using jump to definition inside of a file in any of the site-packages directories I get: Definition provider not found for current document.

Jumping to/from modules inside of the project works fine, but once I go to any definition outside of the project I get the above error.

The following MPLS output shows the request and response for the initial jump that sends me into the Django site-packages, following requests are not sent to the MPLS server at all and just result in Definition provider not found for current document

[Trace - 12:11:16 PM] Sending request 'textDocument/definition - (1)'.                                                                                                                                              
Params: {                                                                                                                                                                                                           
    "textDocument": {                                                                                                                                                                                               
        "uri": "file:///[REDACTED]/user_auth/models.py"                                                                                                                    
    },                                                                                                                                                                                                              
    "position": {                                                                                                                                                                                                   
        "line": 4,                                                                                                                                                                                                  
        "character": 22                                                                                                                                                                                             
    }                                                                                                                                                                                                               
}                                                                                                                                                                                                                   
                                                                                                                                                                                                                    
                                                                                                                                                                                                                    
[Trace - 12:11:16 PM] Received notification 'python/reportProgress'.                                                                                                                                                
Params: [                                                                                                                                                                                                           
    "Analyzing in background, 130 items left..."                                                                                                                                                                    
]                                                                                                                                                                                                                   
                                                                                                                                                                                                                    
                                                                                                                                                                                                                    
[Trace - 12:11:17 PM] Received notification 'telemetry/event'.                                                                                                                                                      
Params: {                                                                                                                                                                                                           
    "EventName": "python_language_server/rpc.request",                                                                                                                                                              
    "Properties": {                                                                                                                                                                                                 
        "method": "textDocument/definition",                                                                                                                                                                        
        "plsVersion": "0.5.30.0"                                                                                                                                                                                    
    },                                                                                                                                                                                                              
    "Measurements": {                                                                                                                                                                                               
        "elapsedMs": 338.8661                                                                                                                                                                                       
    }                                                                                                                                                                                                               
}                                                                                                                                                                                                                   
                                                                                                                                                                                                                    
                                                                                                                                                                                                                    
[Trace - 12:11:17 PM] Received response 'textDocument/definition - (1)' in 392ms.                                                                                                                                   
Result: [                                                                                                                                                                                                           
    {                                                                                                                                                                                                               
        "uri": "file:///home/dissonance/.local/lib/python3.8/site-packages/django/db/models/__init__.py",                                                                                                           
        "range": {                                                                                                                                                                                                  
            "start": {                                                                                                                                                                                              
                "line": 0,                                                                                                                                                                                          
                "character": 0                                                                                                                                                                                      
            },                                                                                                                                                                                                      
            "end": {                                                                                                                                                                                                
                "line": 0,                                                                                                                                                                                          
                "character": 0                                                                                                                                                                                      
            }                                                                                                                                                                                                       
        }                                                                                                                                                                                                           
    }                                                                                                                                                                                                               
]

Dissonant-Tech avatar Feb 18 '20 17:02 Dissonant-Tech

What version (commit hash) of coc-python are you using?

  • When I tried the latest one (Feb 19th, commit 0bbda6e), the jumping to/from modules inside of the project doesn't work. I got the same error Definition provider not found for current document
  • I had to switch to an earlier version (Jan 15th, commit 3e03f98)
  • I haven't tried other commits in between

zachliu avatar Feb 19 '20 19:02 zachliu

@zachliu Just tried with both tags 1.2.9 and 1.2.7 (Jan 15th build) and both still have the same issue. Also I tried with Jedi and it works fine.

Dissonant-Tech avatar Feb 21 '20 04:02 Dissonant-Tech

right, forgot to mention i'm using jedi, but jedi+1.2.9 doesn't work on my computer :joy:

zachliu avatar Feb 24 '20 22:02 zachliu

Hi everyone, I've experienced the same issue here.

After a few hours checking the configuration and trying several things, I've found:

  • VSCode has the same problem (reproducible). Navigation is broken once you get inside the site-packages
  • There's an open issue in the MPLS pointing the problem is in the extension
  • There's an open issue in the VSCode Python extension.

According to the last issue, the files outside the workspace are not sent to the MPLS after the Multi-root workspace support was added. See the description for a good and detailed explanation :rocket:. It's likely the same issue is affecting to coc-nvim and coc-python extension someway.

Today, I also experienced an issue with coc-nvim and the workspaces. It was detecting the root workspace (CocList folders) at the repository root instead of the CWD where I'd placed the .vim/coc-settings.json file. This was making everything fail. The solution was to add .vim folder to the coc.preferences.rootPatterns (never used before). Final value: "coc.preferences.rootPatterns": [".vim", ".git", ".hg", ".projections.json"]

emarbo avatar Feb 27 '20 23:02 emarbo

Hi, the issue should be fixed in the 0.5.37 version of Python Language Server :tada: (changing parameter configuration). Here's the comment

emarbo avatar Mar 19 '20 12:03 emarbo

I have configured the coc-nvim to use the daily MPLS release and the new feature:

        "python.analysis.downloadChannel": "daily",
        "python.analysis.memory.keepLibraryAst": true,

After updating the coc-nvim (:CocUpdate) and the LS (automatic after restart?), the feature does not work and it is still complaining about the keepLibraryAst option:

[undefined] [W] Property python.analysis.memory.keepLibraryAst is not allowed.

I've checked out the repository and seen this option isn't listed in the package.json. I don't know if the solution is as simple as adding it to the options list and updating the languageServerVersion (package.json file), or there's something else to be done :thinking:.

Anyway, I suppose coc-python only updates its languageServerVersion to the latest stable after checking that all the new options are well integrated. In this case, we must wait for (1) MPLS to include this feature in the stable version, and (2) coc-python to update the integration.

emarbo avatar Mar 20 '20 09:03 emarbo

@emarbo What is the version of python language server you are using? (e.g. :CocInfo, ~/.config/coc/extensions/coc-python-data/) Did you run :CocCommand python.upgradePythonLanguageServer? With the daily channel being used, I can download languageServer.0.5.45.

wookayin avatar Mar 21 '20 07:03 wookayin

Hi @wookayin, I can download the same version as you, though I think the problem is in the extension.

As far as I understand, the coc-python is to Neovim as the vscode-python is to VSCode, and both extensions use the same language server: MPLS. Although we update the LS to the latest version, if the extension (coc-python or vscode-python) doesn't send the parameter to the LS it won't work.

That's what I think but I could be completely wrong. Does the feature work for you? I mean, can you use the go to declaration inside the virtualenv?

I didn't go deep into the extension code but I suppose the option must be declared in the package.json to be sent to the LS. Look at the package.json of both extensions:

emarbo avatar Mar 21 '20 13:03 emarbo

Hi, I have the same problem.

nacknime-official avatar Jun 01 '20 10:06 nacknime-official

Hi all, I added to the package.json and it seems to be working for me using virtualenv and MPLS. Can one of u test using my pr, please? PR is here

GustavoKatel avatar Oct 22 '20 21:10 GustavoKatel