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

Code analysis and completion don't work in devcontainers #4547

Closed
julianofp opened this issue Jun 27, 2023 · 6 comments
Closed

Code analysis and completion don't work in devcontainers #4547

julianofp opened this issue Jun 27, 2023 · 6 comments
Assignees

Comments

@julianofp
Copy link

Environment data

  • Language Server version: 2023.6.30
  • OS and version: Windows 10 docker(19045.2965)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.12

Code Snippet

devcontainer.json:

{
  "name": "Test - Pylance",
  "build": {
    "dockerfile": "Dockerfile",
    "context": ".."
  },
  "customizations": {
    "vscode": {
      "settings": {
        "files.exclude": {
          "**/__pycache__": true,
          "**/.pytest_cache": true
        },
        "files.autoSave": "onFocusChange",
        "git.autorefresh": true,
        "extensions.ignoreRecommendations": true,        
        "isort.args": [
          "--profile",
          "black"
        ],        
        "python.analysis.diagnosticMode": "workspace",
        "python.analysis.typeCheckingMode": "strict",
        "python.analysis.logLevel": "Trace",
        "python.analysis.disableSemanticOnNoPython": false,
        "python.analysis.enableSyncServer": true,
        "python.analysis.userFileIndexingLimit": -1,
        "python.formatting.provider": "none",
        "python.languageServer": "Pylance",
        "python.linting.enabled": false,
        "python.linting.lintOnSave": false,
        "python.testing.autoTestDiscoverOnSaveEnabled": false,
        "python.testing.pytestArgs": [
          "tests"
        ],
        "python.testing.pytestEnabled": true,
        "python.testing.unittestEnabled": false,
        "[python]": {
          "editor.defaultFormatter": "ms-python.black-formatter",
          "editor.formatOnSave": true,
          "editor.formatOnPaste": false,
          "editor.formatOnSaveMode": "file",
          "editor.codeActionsOnSave": {
            "source.organizeImports": true
          }
        }
      },      
      "extensions": [
        "eamodio.gitlens",
        "ms-python.black-formatter",
        "ms-python.isort",
        "ms-python.python",
        "ms-python.vscode-pylance",
        "ms-vscode.makefile-tools"
      ]
    }
  },
  // "forwardPorts": [],
  "postCreateCommand": "pip3 install --disable-pip-version-check --no-cache-dir -r requirements.txt ",
  "postAttachCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
  "remoteUser": "vscode"
}

Repro Steps

  1. Create project using the specified devcontainer.json
  2. Install Dev Containers (ms-vscode-remote.remote-containers) extension
  3. Open folder in Container
  4. Attempt to use code completion with ctrl+space" or '.'

Expected behavior

Code completion options should appear.

Actual behavior

"No suggestions." message is displayed.
Logs don't contain traces, even with "python.analysis.logLevel": "Trace".
I have no issues when working locally with the latest version. Previous versions work as expected.

Logs

2023-06-27 11:34:20.952 [info] [Info  - 11:34:20 AM] (784) Pylance language server 4.17.21 (pyright ae795f5b) starting
2023-06-27 11:34:20.952 [info] [Info  - 11:34:20 AM] (784) Server root directory: /home/vscode/.vscode-server/extensions/ms-python.vscode-pylance-2023.6.30/dist
2023-06-27 11:34:20.952 [info] [Info  - 11:34:20 AM] (784) Starting service instance "inventory"
2023-06-27 11:34:21.323 [info] [Info  - 11:34:21 AM] (784) Found 42 source files
@julianofp julianofp changed the title Code analysis and completion doesn't work in devcontainers Code analysis and completion don't work in devcontainers Jun 27, 2023
@rchiodo
Copy link
Contributor

rchiodo commented Jun 27, 2023

Thanks for the issue.

The root cause of the problem is this setting here:

        "python.analysis.enableSyncServer": true,

Did you set that yourself? That's an experimental way to run Pylance that isn't ready to be used yet. In 2023.6.30 it would cause completions to not work.

@rchiodo rchiodo closed this as completed Jun 27, 2023
@julianofp
Copy link
Author

I set it myself because I was having trouble with a previous version inside the devcontainer and this setting fixed it. I will try to disable it to see if it works for the latest one. Thanks!

@julianofp
Copy link
Author

The problem is still there without the setting. Could you please reopen the issue @rchiodo?

@julianofp
Copy link
Author

I could actually make it work by closing and reopening VSCode after build the devcontainer, so maybe the language server is not being started on postAttach.

@debonte debonte reopened this Jun 28, 2023
@rchiodo
Copy link
Contributor

rchiodo commented Jun 28, 2023

If you look in the log and this line says the same thing:

2023-06-27 11:34:20.952 [info] [Info  - 11:34:20 AM] (784) Pylance language server 4.17.21 (pyright ae795f5b) starting

With the important part being the 4.17.21, then the setting is still there.

@rchiodo
Copy link
Contributor

rchiodo commented Jun 28, 2023

I believe you have to restart VS code for the devcontainer changes to take effect.

I get this if I change that setting in the Devcontainer.json:

image

@rchiodo rchiodo closed this as completed Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants