python language server_lyg/python-language-server

Microsoft Python Language Server

Microsoft Python Language Server implements the Language Server Protocol.

Feel free to file issues or ask questions on our issue tracker, and we welcome code contributions.

Build/contributing instructions

Troubleshooting and known issues

Linting options (diagnostics)

The language server implements diagnostics (or linting), which runs on user code.

The following diagnostics are supported:

Code

Description

inherit-non-class

Attempted to inherit something that is not a class.

too-many-function-arguments

Too many arguments have been provided to a function call.

too-many-positional-arguments-before-star

Too many arguments have been provided before a starred argument.

no-cls-argument

First parameter in a class method must be cls

no-method-argument

Method has no arguments

no-self-argument

First parameter in a method must be self

parameter-already-specified

A argument with this name has already been specified.

parameter-missing

A required positional argument is missing.

positional-argument-after-keyword

A positional argument has been provided after a keyword argument.

positional-only-named

A positional-only argument (3.8+) has been named in a function call.

return-in-init

Encountered an explicit return in __init__ function.

typing-generic-arguments

An error occurred while constructing Generic.

typing-newtype-arguments

An error occurred while constructing NewType.

typing-typevar-arguments

An error occurred while constructing TypeVar.

unknown-parameter-name

The keyword argument name provided is unknown.

unresolved-import

An import cannot be resolved, and may be missing.

undefined-variable

A variable has been used that has not yet been defined.

variable-not-defined-globally

A variable is not defined in the global scope.

variable-not-defined-nonlocal

A variable is not defined in non-local scopes.

Linting can be controlled via the user configuration. In VS Code, this is settings.json, but other

clients would send this via workspace/didChangeConfiguration.

If python.linting.enabled is set to false in the user configuration, then no diagnostics

will be collected other than syntax errors and unresolved imports.

To control the visibility and severity of the diagnotics, there are a number of lists

that can be set in the user configuration which make use of each diagnostic's error code.

Setting

Description

python.analysis.errors

Diagnostics which should be shown as errors.

python.analysis.warnings

Diagnostics which should be shown as warnings.

python.analysis.information

Diagnostics which should be shown as informational.

python.analysis.disabled

Diagnotics which should not be shown at all.

An example of a user configuration which sets these options:

{

"python.analysis.errors":["undefined-variable"],

"python.analysis.warnings":["unknown-parameter-name"],

"python.analysis.information":["unresolved-import"],

"python.analysis.disabled":["too-many-function-arguments","parameter-missing"],

}

Linting can also be controlled on an invidual line basis with a generalized #noqa. Lines with #noqa will have their diagnostic output suppressed.

An example usage:

from python import language_server # noqa will suppress the linting message for this line

Cache location

During analysis language server produces Python code from compiled modules and builtins which is similar to Python module stubs.

It may also produce database files holding module analysis for faster retrieval later. Cache location is at

Windows

"%LOCALAPPDATA%\Microsoft\Python Language Server" (which is Environment.SpecialFolder.LocalApplicationData). Typically "C:\Users\\%USER_NAME%\AppData\Local\Microsoft\Python Language Server"

Linux

"$XDG_CACHE_HOME/Microsoft/Python Language Server", or if XDG_CACHE_HOME is not set, "$HOME/.cache/Microsoft/Python Language Server"

macOS

"$HOME/Library/Caches/Microsoft/Python Language Server"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值