neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

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

Open Dissonant-Tech opened 4 years ago

Dissonant-Tech commented 4 years ago

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                                                                                                                                                                                      
            }                                                                                                                                                                                                       
        }                                                                                                                                                                                                           
    }                                                                                                                                                                                                               
]
zachliu commented 4 years ago

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

Dissonant-Tech commented 4 years ago

@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.

zachliu commented 4 years ago

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

emarbo commented 4 years ago

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

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

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 commented 4 years ago

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 commented 4 years ago

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.

wookayin commented 4 years ago

@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.

emarbo commented 4 years ago

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:

nacknime-official commented 4 years ago

Hi, I have the same problem.

GustavoKatel commented 3 years ago

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