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

Add support for excluding paths #46

Open
blarghmatey opened this issue Apr 5, 2021 · 3 comments
Open

Add support for excluding paths #46

blarghmatey opened this issue Apr 5, 2021 · 3 comments

Comments

@blarghmatey
Copy link

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

@Blade6570
Copy link

Okay I have faced the similar problem and the cause of the problem is lsp-file-watcher. You can reduce the startup time by simply putting (setq lsp-enable-file-watchers 'nil) in your config file. Moreover, it is fair to say that the lsp-file-watcher is terribly initialized. It has a variable called ls-file-watch-ignored-directories which controls the list of directoiry to watch. I used the pyrightconfig.json file's exclude list to manipulate the lsp-file-watch-ignored-directories in my config file. If I add all the unwanted directories to the exclude list in the pyrightconfig.json file then my startup time is negligible even with tramp.

The related elisp in my init file to achieve this:

  (add-hook 'lsp-mode-hook
	    (lambda ()
	      (if (file-exists-p (concat (lsp--workspace-root (cl-first (lsp-workspaces))) "/pyrightconfig.json"))
		   (progn
		   (setq lsp-enable-file-watchers t)
		   (setq lsp-file-watch-ignored-directories (eval (car (get 'lsp-file-watch-ignored-directories 'standard-value))))
		   (require 'json)
		   (let* ((json-object-type 'hash-table)
			      (json-array-type 'list)
			      (json-key-type 'string)
			      (json (json-read-file (concat (lsp--workspace-root (cl-first (lsp-workspaces))) "/pyrightconfig.json")))
			      (exclude (gethash "exclude" json)))
		   (dolist (exclud exclude)
		       (push exclud lsp-file-watch-ignored))))
		(setq lsp-enable-file-watchers 'nil)
		(setq lsp-file-watch-ignored-directories (eval (car (get 'lsp-file-watch-ignored-directories 'standard-value)))))
	      ))

My sample pyrightconfig.json file

{
  "exclude": [
      "./vox_crop",
      "./vox_crop_broken",
      "./extra_files"
  ],

    "stubPath": "/home/soumya/anaconda3/lib/python3.7/site-packages",
    "reportMissingImports": true,
    "reportMissingTypeStubs": true
}

@blarghmatey
Copy link
Author

Awesome, thank you for that. I'll give it a try 😄

@hammsvietro
Copy link

Thanks for the snippet! solved my issue 😄

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

3 participants