emacs-lsp / lsp-pyright Goto Github PK
View Code? Open in Web Editor NEWlsp-mode :heart: pyright
Home Page: https://emacs-lsp.github.io/lsp-pyright
License: GNU General Public License v3.0
lsp-mode :heart: pyright
Home Page: https://emacs-lsp.github.io/lsp-pyright
License: GNU General Public License v3.0
Attempting to do lsp-goto-implementation
I get this:
lsp--send-request-async: The connected server(s) does not support method textDocument/implementation.
To find out what capabilities support your server use ‘M-x lsp-describe-session’
and expand the capabilities section
That shows:
[-] /home/luke/devel/clients/MAT/rpr
`-[-] pyright:192087
|-[-] Buffers
| `-[X] models.py
`-[-] Capabilities
|-[X] callHierarchyProvider: t
|-[-] executeCommandProvider:
| |-[X] workDoneProgress: t
| `-[X] commands: []
|-[-] codeActionProvider:
| |-[X] workDoneProgress: t
| `-[X] codeActionKinds: [quickfix source.organizeImports]
|-[-] signatureHelpProvider:
| |-[X] workDoneProgress: t
| `-[X] triggerCharacters: [( , )]
|-[-] completionProvider:
| |-[X] workDoneProgress: t
| |-[X] resolveProvider: t
| `-[X] triggerCharacters: [. []
|-[-] renameProvider:
| `-[X] workDoneProgress: t
|-[-] documentHighlightProvider:
| `-[X] workDoneProgress: t
|-[-] hoverProvider:
| `-[X] workDoneProgress: t
|-[-] workspaceSymbolProvider:
| `-[X] workDoneProgress: t
|-[-] documentSymbolProvider:
| `-[X] workDoneProgress: t
|-[-] referencesProvider:
| `-[X] workDoneProgress: t
|-[-] declarationProvider:
| `-[X] workDoneProgress: t
|-[-] definitionProvider:
| `-[X] workDoneProgress: t
`-[X] textDocumentSync: 2
Is it indeed the case that this is not supported yet? If it is, is there any guidance on what I might be doing wrong? In VSCode, the pyright extension says it supports: "Find Definitions to quickly go to the location of a symbol’s definition" so I thought this feature would be present.
(use-package) shows that lip-pyright isn't available...
Hi, the docstring of lsp-pyright-log-level is same as above variable, just wanted to let you know.
I'm trying to integrate lsp-pyright with PDM python package manager and doom-emacs. But I fails to make pyright to use my PDM python interpreter. It still use my system interpreter.
I have tried to use lsp-pyright-auto-search-paths
and lsp-pyright-venv-path
to specify python interpreter, but that doesn't work
(defun pdm-get-python-executable (&optional dir)
(let ((pdm-get-python-cmd "pdm info --python"))
(string-trim
(shell-command-to-string
(if dir
(concat "cd "
dir
" && "
pdm-get-python-cmd)
pdm-get-python-cmd)))))
(defun pdm-get-packages-path (&optional dir)
(let ((pdm-get-packages-cmd "pdm run bash -c 'printenv PEP582_PACKAGES'"))
(concat (string-trim
(shell-command-to-string
(if dir
(concat "cd "
dir
" && "
pdm-get-packages-cmd)
pdm-get-packages-cmd)))
"/lib")))
(add-hook! python-mode
(setq lsp-pyright-extra-paths (vector (pdm-get-packages-path)))
(setq lsp-pyright-auto-search-paths (pdm-get-python-executable))
(setq lsp-pyright-venv-path (pdm-get-python-executable))
(require 'lsp-pyright)
(lsp)) ; or lsp-deferred
Currently, when using Poetry with a local venv, you have to create a .dir-locals.el
file containing something like:
((python-mode . ((lsp-pyright-venv-path . "/home/user/project/.venv")))))
It would be great if we were able to configure the Pyright command, or at least set an option to run it through Poetry. I tried this (somewhat hacky) solution:
(eval-after-load 'lsp-clients
'(progn
(lsp-dependency 'pyright (:system ,(executable-find "poetry")))
))
(after! lsp-pyright
(setq lsp-pyright-langserver-command-args "run pyright-langserver --stdio"))
But it didn't work ("Unable to find installed server...").
This issue is to track submission to Melpa.
PR: melpa/melpa#7045
From what I can tell, lsp-pyright currently looks for the venv
and .venv
directories in default-directory
and up (via locate-dominating-file
):
Lines 153 to 159 in 65fb141
I have used a convention of using env
as the directory for virtualenvs in all my projects. Can you please provide a way (either via a lambda or by specifying folder names it looks for) to give a custom folder name to lsp-pyright
which it searches for in order to find the virtualenv directory?
Note that lsp-pyright-venv-path
doesn't work, because the env
folders are project-local.
I am running emacs 27.2 on a Mac running Big Sur. I am unable to install lsp-pyright from melpa. I cannot get it to show up in the package list package-list-packages
and I cannot install it directly via package-install
. Is this because it depends on emacs 26? Is the dependency on emacs 26 a hard dependency?
Pyright is having trouble resolving pip3 installed packages like numpy or matplotlib. I checked numpy's installation location and it's under /home/ianpan/.local/lib/python3.8/site-packages
, and when I ran pyright --verbose
I do see this exact same path being found both under "Search paths found for configured python interpreter" and "Received 5 paths from interpreter".
In this case, is the pyrightconfig.json file still needed? If it is, what exactly should I put in the configuration file? All I need is for pyright to recognize my pip3 packages that installed "globally". Thanks in advance!
I am using a very basic configuration of this package.
So the package initializes client settings via:
(lsp-register-custom-settings
`(("pyright.disableLanguageServices" lsp-pyright-disable-language-services)
("pyright.disableOrganizeImports" lsp-pyright-disable-organize-imports)
("python.analysis.useLibraryCodeForTypes" lsp-pyright-use-library-code-for-types)
("python.analysis.diagnosticMode" lsp-pyright-diagnostic-mode)
("python.analysis.typeCheckingMode" lsp-pyright-typechecking-mode)
("python.analysis.logLevel" lsp-pyright-log-level)
("python.analysis.autoSearchPaths" lsp-pyright-auto-search-paths)
("python.pythonPath" lsp-pyright-locate-python)))
These are written into lsp-client-settings
:
lsp-client-settings is a variable defined in ‘lsp-mode.el’.
Its value is
(("pyright.disableLanguageServices" lsp-pyright-disable-language-services)
("pyright.disableOrganizeImports" lsp-pyright-disable-organize-imports)
("python.analysis.useLibraryCodeForTypes" lsp-pyright-use-library-code-for-types)
("python.analysis.diagnosticMode" lsp-pyright-diagnostic-mode)
("python.analysis.typeCheckingMode" lsp-pyright-typechecking-mode)
("python.analysis.logLevel" lsp-pyright-log-level)
("python.analysis.autoSearchPaths" lsp-pyright-auto-search-paths)
("python.pythonPath" lsp-pyright-locate-python))
However, when I inspect the calls to get the individual configuration settings "pyright" vs "python", it looks as though the "python" section is retrieved:
(lsp-configuration-section "python")
evaluates to:
#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("python" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("analysis" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("diagnosticMode" "openFilesOnly" "typeCheckingMode" "basic" "logLevel" "info" "autoSearchPaths" t)) "pythonPath" "/Users/johnnysigman/anaconda3/bin/python"))))
while
(lsp-configuration-section "pyright")
evaluates to:
#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ())
Which doesnt have any of the configuration settings stored previously. This is the function used to initialize the package.
Thanks for the package!
I got some error popping up when I try to use the conda env. Jump to definition doesn't work on packages installed in the conda env.
Here is my pyrightconfig.json
file.
{
"venvPath": "/Users/ztlevi/.conda/envs/test/"
}
This is the error
Pyright language server 1.1.58 starting
Server root directory: /Users/ztlevi/.local/share/nodenv/versions/12.10.0/lib/node_modules/pyright/dist/
Error reading settings: TypeError: Cannot read property 'replace' of undefined
Loading configuration file at /Users/ztlevi/Developer/python-test/pyrightconfig.json
Assuming Python version 3.7
Assuming Python platform Darwin
No include entries specified; assuming /Users/ztlevi/Developer/python-test
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding .git
Setting pythonPath for service "python-test": "/usr/local/bin/python3"
stubPath /Users/ztlevi/Developer/python-test/typings is not a valid directory.
Searching for source files
Found 5 source files
Error reading settings: TypeError: Cannot read property 'replace' of undefined
No configuration file found.
Setting pythonPath for service "numpy": "/usr/local/bin/python3"
stubPath /usr/local/lib/python3.7/site-packages/numpy/typings is not a valid directory.
Assuming Python version 3.7
Assuming Python platform Darwin
Searching for source files
Found 371 source files
Error reading settings: TypeError: Cannot read property 'replace' of undefined
No configuration file found.
Setting pythonPath for service "numpy": "/usr/local/bin/python3"
stubPath /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/typings is not a valid directory.
Assuming Python version 3.7
Assuming Python platform Darwin
Searching for source files
Found 356 source files
BTW, I'm seeing this error even if I use the system python interpreter.
As titled, pyright can't seem to find my pip3-installed packages like numpy or matplotlib. How can I go about letting pyright recognize where these pip3 packages are installed?
Thanks in advance!
Hello. Is there a way to use this with LSP Mode's Remote capabilities?
I was attempting to install lsp-pyright on a centos7 machine without root privileges. For me the default versions were:
When attempting to build pyright in doom emacs I kept getting
Syntax Error: Unexpected Token *
Updating the node version to 14 fixed this as I looked #35 which mentioned downgrading to node 14 was required on mac.
I am quite new to contributing so my question is would you be open to adding a quick section in the readme about node requirements as they are not obvious on microsofts documentation either?
I would be happy to investigate what versions work and don't.
Hi, I'm trying to decide between using this language server or the ms-python server, when I realized that vscode seems to be using both simultaneously to complement each other, since pyright as I understand it's just type checker.
Is this possible in emacs as well? How would someone set it up?
I'm on Spacemacs and just switched from pyls to pyright . One thing I noticed is that auto-completion does not insert parens after completing a function name.
As an example (the pipe character is where he cursor would be): if I type pri|
, company completes it to print|
. I would expect it to expand to print(|)
and drop the cursor inside the parens.
It works on pyls, is this an upstream issue on Pyright's end? I did try to update it as well, but no dice.
I'm trying to adapt this to work over tramp, and tried the following:
(make-lsp-client
:new-connection (lsp-tramp-connection "pyright-langserver")
:major-modes '(python-mode)
:server-id 'pyright-remote
:remote? t
...
which does get recognized as a legitimate client for a tramp-opened file, but then fails with Server pyright-remote:84540/starting exited with status exit(check corresponding stderr buffer for details). Do you want to restart it? (y or n) n
.
By default lsp-pyright
seems to be trying to run npm locally to find out where pyright-langserver
is, but that obviously won't work over a tramp/SSH connection. I had already installed pyright
, and npm
on my remote host helpfully added a /usr/local/bin/pyright-langserver
link. Any suggestions?
Hello,
I am using lsp-pyright in the following environment
When lsp-mode is starting the pyright server I get the following error
LSP :: pyright:10456 initialized successfully in folders: (c:/Software/license-queue c:/Software/admin-scripts c:/Software/user-admin-scripts c:/Software/PyTest c:/Webb/TPCloner c:/Software/vault-audit-sink c:/Users/anste c:/Software/dog-lameness)
Error processing message (file-error "Opening directory" "Permission denied" "c:/Users/anste/AppData/Local/Application Data").
Furthermore, my Emacs is unresponsive quite a while after opening the first Python buffer.
I do not know if this is a problem with the pyright server itself, or lsp-mode.
Many modules use docstring, which makes the code easier to read
I noticed that python-lsp-server is a Python 3.6+ implementation of the Language Server Protocol. I want to know if lsp-pyright
can use python-lsp-server
as an alternative backend?
Regards,
HZ
I edit my python code with tabs instead of spaces, I know that PEP 8 says to use spaces, but I honestly hate using them and I want my tab key to input... well tabs.
Anyway I keep getting errors using pyright saying indentation contains tabs
and I can't seem to get rid of them, has anyone else solved this issue?
Sometimes I see the pyright session is stale, and doesn't pick up changes like newly added dependencies. Typically this happens when I'm changing/enabling virtual environments for some reason (in the same file). Presently I do it by manually editing venvPath
and venv
in pyrightconfig.json
.
It would be great if we could have a command to restart the pyright session to pickup these changes. At the moment I have to restart emacs.
Just a question on if we are able to get organize import and auto import working?
If we are then would you mind to give me a hint.
s = socket.socket()
lsp-organize-imports
, it also does not help.LSP :: source.organizeImports action not available
[-]/home/xtaidin/workspace/dev/lsp-pyright
-[-]pyright:31970
|-[-]Buffers
| -[+]test.py
-[-]Capabilities
|-[X]callHierarchyProvider: t
|-[-]executeCommandProvider:
| |-[X]workDoneProgress: t
| -[X]commands: []
|-[-]codeActionProvider:
| |-[X]workDoneProgress: t
| -[X]codeActionKinds: [quickfix source.organizeImports]
|-[-]signatureHelpProvider:
| |-[X]workDoneProgress: t
| -[X]triggerCharacters: [( , )]
|-[-]completionProvider:
| |-[X]workDoneProgress: t
| |-[X]resolveProvider: t
| -[X]triggerCharacters: [. []
|-[-]renameProvider:
| -[X]workDoneProgress: t
|-[-]documentHighlightProvider:
| -[X]workDoneProgress: t
|-[-]hoverProvider:
| -[X]workDoneProgress: t
|-[-]workspaceSymbolProvider:
| -[X]workDoneProgress: t
|-[-]documentSymbolProvider:
| -[X]workDoneProgress: t
|-[-]referencesProvider:
| -[X]workDoneProgress: t
|-[-]definitionProvider:
| -[X]workDoneProgress: t
-[X]textDocumentSync: 1
[Trace - 09:33:23 ] Sending request 'textDocument/codeAction - (259)'.
Params: {
"textDocument": {
"uri": "file:///home/xtaidin/workspace/dev/lsp-pyright/testpython/test.py"
},
"range": {
"start": {
"line": 1,
"character": 11
},
"end": {
"line": 1,
"character": 11
}
},
"context": {
"diagnostics": [
{
"source": "Pyright (reportUndefinedVariable)",
"severity": 1,
"message": ""socket" is not defined",
"range": {
"end": {
"character": 16,
"line": 1
},
"start": {
"character": 10,
"line": 1
}
}
}
],
"only": [
"source.organizeImports"
]
}
}
[Trace - 09:33:23 ] Received response 'textDocument/codeAction - (259)' in 2ms.
Result: []
Pyright
VSCode extension, however it is not enabled for us.
pyright-langserver
(https://github.com/microsoft/pyright/blob/master/server/src/server.ts#L151)Hello,
I have the problem that lsp-ui-show-doc
is very short and company-show-doc-buffer
just opens an empty buffer for many functions (bultins and numpy for example). I tried many things and I also manually installed type stubs that are found by pyright but nothing helps.
Is anyone having this problems as well? Looking for any pointers on how to fix this.
When I show the doc buffer with anaconda-mode
I get correct results, so I doubt it is my Python installation.
Not sure if this is a language server issue or lsp-pyright issue.
lsp-rename
works with pylsp
language server but not pyright
pyright version 1.1.187
lsp-mode 20211115.807
update - tested it with eglot aswell but I had the same issue there, eglot think the rename is successful but it was not.
my lsp-pyright setting in vanila emacs.
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))))
(setq lsp-log-io t)
(setq lsp-pyright-use-library-code-for-types t)
(setq lsp-pyright-diagnostic-mode "workspace")
(lsp-register-client
(make-lsp-client
:new-connection (lsp-tramp-connection (lambda ()
(cons "pyright-langserver"
lsp-pyright-langserver-command-args)))
:major-modes '(python-mode)
:remote? t
:server-id 'pyright-remote
:multi-root nil
:priority 3
:initialization-options (lambda () (ht-merge (lsp-configuration-section "pyright")
(lsp-configuration-section "python")))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration
(ht-merge (lsp-configuration-section "pyright")
(lsp-configuration-section "python")))))
:download-server-fn (lambda (_client callback error-callback _update?)
(lsp-package-ensure 'pyright callback error-callback))
:notification-handlers (lsp-ht ("pyright/beginProgress" 'lsp-pyright--begin-progress-callback)
("pyright/reportProgress" 'lsp-pyright--report-progress-callback)
("pyright/endProgress" 'lsp-pyright--end-progress-callback))))
My tramp version is 2.5.0 and emacs 27.2. Error logs are empty in \tmp
directory. The pyright is in the system path and python path is from conda environment. Please help.
this is the lsp-log:pyright-remote
[Trace - 10:51:30 am] Sending request 'initialize - (1)'.
Params: {
"processId": null,
"rootPath": "/home/tripathy/current_project",
"clientInfo": {
"name": "emacs",
"version": "GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.32)\n of 2021-03-30"
},
"rootUri": "file:///home/tripathy/current_project",
"capabilities": {
"workspace": {
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
]
},
"applyEdit": true,
"symbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
}
},
"executeCommand": {
"dynamicRegistration": false
},
"didChangeWatchedFiles": {
"dynamicRegistration": true
},
"workspaceFolders": true,
"configuration": true
},
"textDocument": {
"declaration": {
"linkSupport": true
},
"definition": {
"linkSupport": true
},
"implementation": {
"linkSupport": true
},
"typeDefinition": {
"linkSupport": true
},
"synchronization": {
"willSave": true,
"didSave": true,
"willSaveWaitUntil": true
},
"documentSymbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"hierarchicalDocumentSymbolSupport": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true
},
"rename": {
"dynamicRegistration": true,
"prepareSupport": true
},
"codeAction": {
"dynamicRegistration": true,
"isPreferredSupport": true,
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
]
}
},
"resolveSupport": {
"properties": [
"edit",
"command"
]
},
"dataSupport": true
},
"completion": {
"completionItem": {
"snippetSupport": false,
"documentationFormat": [
"markdown"
],
"resolveAdditionalTextEditsSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"details",
"additionalTextEdits",
"command"
]
}
},
"contextSupport": true
},
"signatureHelp": {
"signatureInformation": {
"parameterInformation": {
"labelOffsetSupport": true
}
}
},
"documentLink": {
"dynamicRegistration": true,
"tooltipSupport": true
},
"hover": {
"contentFormat": [
"markdown",
"plaintext"
]
},
"foldingRange": {
"dynamicRegistration": true
},
"callHierarchy": {
"dynamicRegistration": false
},
"publishDiagnostics": {
"relatedInformation": true,
"tagSupport": {
"valueSet": [
1,
2
]
},
"versionSupport": true
}
},
"window": {
"workDoneProgress": true
}
},
"initializationOptions": {
"python": {
"venvPath": "",
"pythonPath": "/home/tripathy/miniconda3/bin/python",
"analysis": {
"extraPaths": [],
"autoSearchPaths": true,
"logLevel": "info",
"typeCheckingMode": "basic",
"diagnosticMode": "workspace",
"useLibraryCodeForTypes": true,
"stubPath": "",
"typeshedPaths": [],
"autoImportCompletions": true
}
},
"pyright": {
"disableOrganizeImports": false,
"disableLanguageServices": false
}
},
"workDoneToken": "1"
}
[Trace - 10:51:31 am] Received notification 'window/logMessage'.
Params: {
"message": "Pyright language server 1.1.126 starting",
"type": 3
}
[Trace - 10:51:31 am] Received notification 'window/logMessage'.
Params: {
"message": "Server root directory: /home/tripathy/applications/node-v14.16.0-linux-x64/lib/node_modules/pyright/dist/",
"type": 3
}
I have multiple python projects with different virtual environments in <project_root>/venv
directory.
With a help of .dir-locals.el
and projectile-project-root
, whenever I open a file it will run pyvenv-activate
to the right venv
.
I have pyrightproject.json
with "venv": "venv"
inside.
However, pyright
is kinda "sticks" to the environment of the project that was first opened after emacs restart, e.g. if I open a file from project A and then open a file from project B: project B files will have unresolved library imports error because these libraries are not installed in the environment A.
What am I missing? Not sure if it is a bug or I just need to tweak lsp-pyright
/ pyrightproject.json
more (I have tried using executionEnvironments
there but behaviour was the same).
When I start up a new project with pyright, the log shows that "workspaceFolders" in the log has many entries. I'm not sure how these are being set but it slows down the project with file watchers.
Any thoughts? It looks like these are every paths to every python project I've ever run this in. Could it be reading my projectile bookmarks?
For the next code (which runs without errors):
import numpy as np
print (np.sign(-1))
I got the error with pyright in emacs:
"sign" is not a known member of module (lsp)
But if I run pyright in the shell, it doesn't report any errors:
$ pyright pyr.py
No configuration file found.
stubPath /home/sd/pyr/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
0 errors, 0 warnings, 0 infos
Completed in 0.551sec
So, I get a some mystic error report. This is also in other cases, for example, when work with pandas
, when no pyright itself, no vscode doesn't reports any errors.
The value of lsp-pyright-typechecking-mode
is basic
for all cases.
I am setting up a fresh instance of macOS Big Sur. I think I am running into this upstream npm issue: npm/cli#2277
0 verbose cli [
0 verbose cli '/opt/brew/Cellar/node/15.5.1/bin/node',
0 verbose cli '/opt/brew/bin/npm',
0 verbose cli '-g',
0 verbose cli '--prefix',
0 verbose cli '/Users/nw_henderson/github.com/nwh/emacs.d/.cache/lsp/npm/pyright',
0 verbose cli 'install',
0 verbose cli 'pyright'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/opt/brew/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/nw_henderson/github.com/nwh/emacs.d/.cache/lsp/npm/pyright/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/nw_henderson/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/Users/nw_henderson/github.com/nwh/emacs.d/.cache/lsp/npm/pyright/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 5ms
19 verbose npm-session 20464621194c937e
20 timing npm:load Completed in 9ms
21 timing arborist:ctor Completed in 1ms
22 timing idealTree:init Completed in 5ms
23 timing idealTree:userRequests Completed in 1ms
24 silly idealTree buildDeps
25 silly fetch manifest pyright@*
26 http fetch GET 304 https://registry.npmjs.org/pyright 125ms (from cache)
27 silly placeDep ROOT [email protected] OK for: want: *
28 timing idealTree:#root Completed in 132ms
29 timing idealTree:node_modules/pyright Completed in 0ms
30 timing idealTree:buildDeps Completed in 133ms
31 timing idealTree:fixDepFlags Completed in 0ms
32 timing idealTree Completed in 140ms
33 timing command:install Completed in 142ms
34 verbose stack Error: ENOENT: no such file or directory, lstat '/Users/nw_henderson/github.com/nwh/emacs.d/.cache'
35 verbose cwd /Users/nw_henderson/.npm/_logs
36 verbose Darwin 20.2.0
37 verbose argv "/opt/brew/Cellar/node/15.5.1/bin/node" "/opt/brew/bin/npm" "-g" "--prefix" "/Users/nw_henderson/github.com/nwh/emacs.d/.cache/lsp/npm/pyright" "install" "pyright"
38 verbose node v15.5.1
39 verbose npm v7.3.0
40 error code ENOENT
41 error syscall lstat
42 error path /Users/nw_henderson/github.com/nwh/emacs.d/.cache
43 error errno -2
44 error enoent ENOENT: no such file or directory, lstat '/Users/nw_henderson/github.com/nwh/emacs.d/.cache'
45 error enoent This is related to npm not being able to find a file.
46 verbose exit -2
Hi,
Is it possible to custom python.analysis.diagnosticSeverityOverrides
?
https://github.com/microsoft/pyright/blob/master/docs/settings.md
I have tried to add one in lsp-register-custom-settings
like:
("python.analysis.diagnosticSeverityOverrides.reportUnusedFunction" "warning")
but not work as expected.
I've seen several comments on the github issues asking about tramp, python virtual environments and lsp-mode for python. It's currently possible-ish with a couple hacks. For pyright (for example), the following launches uses the standard python interpreter /usr/bin/python
(setq lsp-log-io t)
(setq lsp-pyright-use-library-code-for-types t)
(setq lsp-pyright-diagnostic-mode "workspace")
(lsp-register-client
(make-lsp-client
:new-connection (lsp-tramp-connection (lambda ()
(cons "pyright-langserver"
lsp-pyright-langserver-command-args)))
:major-modes '(python-mode)
:remote? t
:server-id 'pyright-remote
:multi-root t
:priority 3
:initialization-options (lambda () (ht-merge (lsp-configuration-section "pyright")
(lsp-configuration-section "python")))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration
(ht-merge (lsp-configuration-section "pyright")
(lsp-configuration-section "python")))))
:download-server-fn (lambda (_client callback error-callback _update?)
(lsp-package-ensure 'pyright callback error-callback))
:notification-handlers (lsp-ht ("pyright/beginProgress" 'lsp-pyright--begin-progress-callback)
("pyright/reportProgress" 'lsp-pyright--report-progress-callback)
("pyright/endProgress" 'lsp-pyright--end-progress-callback))))
To accomodate virtualenvs, I added some additional initialization code to read the virtualenvironment off of pyvenv, prune the tramp path, and pass it to the server.
:initialization-options (lambda () (let* ((pyright_hash (lsp-configuration-section "pyright"))
(python_hash (lsp-configuration-section "python"))
(_ (puthash "pythonPath" (concat (replace-regexp-in-string (file-remote-p default-directory) "" pyvenv-virtual-env) "bin/python") (gethash "python" python_hash))))
(ht-merge pyright_hash
python_hash)))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration
(let* ((pyright_hash (lsp-configuration-section "pyright"))
(python_hash (lsp-configuration-section "python"))
(_ (puthash "pythonPath" (concat (replace-regexp-in-string (file-remote-p default-directory) "" pyvenv-virtual-env) "bin/python") (gethash "python" python_hash))))
(ht-merge pyright_hash
python_hash)))))
This could be cleaner, and there isn't a unified way with pyenv-mode and poetry.el not officially supporting virtualenvs over TRAMP. I have a version of virtualenv support for pyvenv/poetry.el, but maybe it would make sense to coordinate with them upstream.
On MacOS, python
links to the bundled Python 2.7. Since lsp-pyright
searches for and configures pyright with the interpreter, this leads to real problems. There was a bug in pyright that now correctly first searches python3
in all cases, but since lsp-pyright
specifically searches for and configures /usr/bin/python
, it isn't solved in Emacs. See microsoft/pyright#2562.
The best solution is likely not to set the pythonPath
at all. Since pyright itself expends some significant energy finding the correct interpreter on various platforms, this is duplicated effort anyway.
I have some pretty big projects, with a lot of dependencies. Right now I just let file watches happen on everything, which causes the LSP bootup to be pretty slow.
But is there a way to just indicate to the plugin to just look at the "main" project directory? I don't really need the server to be responsive to dependency changes, but I do want it to respond quickly to main project file changes.
(aside: do I even need file watching in general if nothing outside of Emacs is touching the files? Like does saving already "refresh the data" so to speak?)
Thanks for the effort put into this plugin!
In the docstring for
Line 58 in 72fd576
Yesterday's commit 3fd23f1 added the option lsp-pyright-venv-directory
, but there was already an option lsp-pyright-venv-path
, which, judging by the description, has the same function.
BTW, both options have an incomplete :type
spec. Since they can also be nil
, the type should be something like this:
(defcustom lsp-pyright-venv-path nil
"Path to folder with subdirectories that contain virtual environments.
Virtual Envs specified in pyrightconfig.json will be looked up in this path."
:type '(choice (string :tag "Venv path")
(const :tag "No venv path" nil))
:group 'lsp-pyright)
That way, they are displayed correctly in the Customize buffer and can be properly type-checked.
Hi, I use doom-emacs and pyright.
I encountered the following error today:
Error runnint timer 'lsp--on-idle': (error "The connected server(s) does not support method textDocument/documentHighlight.
Any help ? Thanks : D
This is my pyrightconfig.json
{
"exclude": ["images/**", "**/__pycache__"],
"ignore": ["images/**", "**/__pycache__"],
"venvPath": "/home/sreenivas/anaconda3/envs",
"venv": "colorize",
"reportMissingImports": true,
"reportMissingTypeStubs": false,
"pythonVersion": "3.7",
"pythonPlatform": "Linux"
}
With doom emacs (lsp, pyright, conda, direnv), I'm running into issues getting my pyright path to work.
I think I traced this down to https://github.com/emacs-lsp/lsp-pyright/blob/master/lsp-pyright.el#L159-L176 these two functions. I don't have a venv
in my path, I'm using anaconda3. It's on a separate partition from my project. (Project is on /media/data/....
while virtualenv is on /home/sreenivas/anaconda3
)
I can override the two functions to do the job, but I would like some advice on how to do it in a neater manner.
(defun lsp-pyright-locate-venv ()
"Look for virtual environments local to the workspace."
(concat "/home/sreenivas/anaconda3/" "envs"))
(defun lsp-pyright-locate-python ()
"Look for python executable cmd to the workspace."
(or (executable-find (f-expand "bin/python" (concat (lsp-pyright-locate-venv) "/colorize")))
(with-no-warnings
(if (>= emacs-major-version 27)
(executable-find lsp-pyright-python-executable-cmd lsp-pyright-prefer-remote-env)
(executable-find lsp-pyright-python-executable-cmd)))))
Now it gives:
Setting pythonPath for service "CH": "/home/sreenivas/anaconda3/envs/colorize/bin/python"
If a venv is located inside a project directory then it can cause a long startup time for pyright due to it analyzing all of the contents of the third party packages. The configuration documentation for pyright shows that there is support for an exclude
option to specify paths that should not be scanned for type information unless imports are made that trigger it. https://github.com/microsoft/pyright/blob/master/docs/configuration.md
Looking at the code for lsp-pyright it seems that it should be possible to expose a variable that gets added to lsp-register-custom-settings
to manage that setting. https://github.com/emacs-lsp/lsp-pyright/blob/master/lsp-pyright.el#L199-L213
The documentation that lsp-pyright
returns appears to be minimal (e.g., only function signatures rather than signatures and docstrings). However, the VSCode pyright
client can show docstrings too. Is it possible to show docstrings in addition to the minimal hover info currently provided?
EDIT: It appears I was using Pylance and not Pyright in VS Code, which I just realized is not open source. Closing this issue.
Emacs lsp-pyright is not able to resolve my project's modules.
The issue is not present when I'm running it manually from the shell.
This is my project's structure
.
├── ep
│ ├── api
│ ├── metrics
├── ...
├── pyrightconfig.json
├── ...
This is my pyrightconfig.json
{
"include":["ep"],
"pythonPlatform": "Darwin",
}
On every module starting with path ep.xxx I get:
Import "ep.xxx" could not be resolved.
When using Emacs for python development, I use the following configuration:
(use-package lsp-mode
:hook (python-mode . lsp-deferred))
(use-package dap-mode
:after lsp-mode
:config
(setq dap-python-debugger 'debugpy)
(require 'dap-python))
;# To install pyright globally:
;$ proxychains-ng-socks5 sudo npm install -g npm@latest
;#or
;$ proxychains-ng-socks5 sudo npm install -g pyright
;#To update to the latest version:
;$ proxychains-ng-socks5 sudo npm update -g pyright
(use-package lsp-pyright
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp-deferred))))
But when I open a python file with Emacs, I always noticed a very long initialization time with the above configuration, and furthermore, Emacs often loses response even during use. Any hints for this problem?
Also see the relevant issue here.
Regards,
HZ
Hi, thanks for pyright integration first of all. It is super fast but does not autocomplete inherited class fields and function arguments.
For example:
# in some file which imported
class Emacs:
version = 26
# in current file
class Emacs27(Emacs):
ver*
it does not suggest "version" here.
Is it about pyright or lsp-pyright?
I just switched to lsp-pyright using spacemacs develop branch, but emacs will hang there if open an python file.
below is the result of profile-report, it seems to me this is related with lsp--all-watchable-directories
, any idea where is wrong?
- #<compiled 0x15952ca777e1> 310,227,249 78%
- lsp--parser-on-message 310,175,050 78%
- lsp--on-request 308,480,245 77%
- mapc 308,480,001 77%
- lsp--server-register-capability 308,410,830 77%
- lsp-watch-root-folder 308,214,112 77%
- lsp--all-watchable-directories 307,914,305 77%
- -map 306,885,645 77%
- mapcar 306,885,645 77%
- #<compiled 0x15952ca916b5> 306,885,645 77%
- lsp--all-watchable-directories 306,884,597 77%
- -map 303,637,919 76%
- mapcar 303,637,919 76%
- #<compiled 0x15952cc12e31> 303,637,919 76%
- lsp--all-watchable-directories 303,613,035 76%
- -map 201,231,987 50%
- mapcar 201,231,987 50%
- #<compiled 0x15952cc12ee5> 201,231,987 50%
- lsp--all-watchable-directories 201,211,307 50%
- -map 195,664,223 49%
- mapcar 195,661,055 49%
- #<compiled 0x15952cc12ee5> 195,661,055 49%
+ lsp--all-watchable-directories 195,661,055 49%
f-symlink? 380,334 0%
I solved this issue by remove some 3rd part library root from workspace by command treemacs-edit-workspaces
, maybe it is due to these library all too large.
Cannot start pyright server from lsp-mode. In pyright::stderr buffer I am seeing "cannot find module 'worker_threads'" error. Found a few posts online where people had similar error when using older versions of node (<12). I had old node but updated it with nvm to 14.15.2. I can start pyright just from bash (Ubuntu 20.04 in WSL2), but from emacs I always get the error. How do I troubleshoot it?
Tried emacs 26.3 and 27.1 with Spacemacs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.