[
  {
    "path": ".github/workflows/docs.yml",
    "content": "name: Docs\n\non:\n  push:\n    branches:\n      - master\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v2\n\n      - uses: purcell/setup-emacs@master\n        with:\n          version: 27.1\n\n      - uses: conao3/setup-cask@master\n        with:\n          version: 0.8.4\n\n      - name: README.org -> README.md\n        uses: docker://pandoc/core:2.9\n        with:\n          args: -s README.org -t gfm -o docs/README.md\n\n      - name: MkDocs\n        run: |\n          cp -rf images docs\n          docker login docker.pkg.github.com --username $GITHUB_ACTOR --password ${{ secrets.GITHUB_TOKEN }}\n          docker run --rm -v ${PWD}:/docs docker.pkg.github.com/emacs-lsp/docs-image/docs-image -- build\n\n      - name: Deploy\n        uses: peaceiris/actions-gh-pages@v3\n        with:\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n          publish_dir: ./site\n"
  },
  {
    "path": ".github/workflows/test.yml",
    "content": "name: CI\n\non: [push, pull_request]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    continue-on-error: ${{ matrix.experimental }}\n    strategy:\n      fail-fast: false\n      matrix:\n        emacs-version: [26.3, 27.2, 28.2, 29.1]\n        experimental: [false]\n        include:\n          - emacs-version: snapshot\n            experimental: true\n\n    steps:\n      - name: setenv\n        run: echo \"ACTIONS_ALLOW_UNSECURE_COMMANDS=true\" >> $GITHUB_ENV\n\n      - uses: actions/checkout@v1\n\n      - uses: purcell/setup-emacs@master\n        with:\n          version: ${{ matrix.emacs-version }}\n\n      - uses: conao3/setup-cask@master\n        with:\n          version: 0.8.6\n\n      - name: install\n        run: 'cask install'\n\n      - name: build\n        run: 'cask build'\n\n      - name: package\n        run: 'cask package'\n"
  },
  {
    "path": ".gitignore",
    "content": ".DS_Store\n*.elc\n"
  },
  {
    "path": "Cask",
    "content": "(source gnu)\n(source melpa)\n\n(package-file \"lsp-python-ms.el\")\n\n(files \"*.el\")\n\n(development\n (depends-on \"lsp-mode\")\n (depends-on \"projectile\"))\n"
  },
  {
    "path": "LICENSE",
    "content": "BSD 3-Clause License\n\nCopyright (c) 2018-2019, Charl Botha\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\n* Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products derived from\n  this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "Makefile",
    "content": "SHELL := /usr/bin/env bash\n\nEMACS ?= emacs\nCASK ?= cask\n\nwindows-ci: CASK=\nwindows-ci: clean windows-compile\n\nwindows-compile:\n\t@echo \"Compiling...\"\n\t@$(CASK) $(EMACS) -Q --batch \\\n\t\t-l test/windows-bootstrap.el \\\n\t\t-L . \\\n\t\t--eval '(setq byte-compile-error-on-warn t)' \\\n\t\t-f batch-byte-compile *.el\n\nclean:\n\trm -rf .cask *.elc\n\n.PHONY: clean windows-compile\n"
  },
  {
    "path": "README.org",
    "content": "[[https://github.com/emacs-lsp/lsp-python-ms/actions][https://github.com/emacs-lsp/lsp-python-ms/workflows/CI/badge.svg?branch=master]]\n[[http://img.shields.io/:License-BSD3-blue.svg]]\n[[https://melpa.org/#/lsp-python-ms][https://melpa.org/packages/lsp-python-ms-badge.svg]]\n[[https://stable.melpa.org/#/lsp-python-ms][https://stable.melpa.org/packages/lsp-python-ms-badge.svg]]\n\n=lsp-mode= client leveraging Microsoft's [[https://github.com/Microsoft/python-language-server][python-language-server]].\n\nThis project is marked as DEPRECATED, since [Microsoft's Python Lang Server](https://github.com/microsoft/python-language-server) has already been archived and is replaced by [pyright](https://github.com/microsoft/pyright). The successor is [lsp-pyright](https://github.com/emacs-lsp/lsp-pyright).\n\n* Installation\n\nInclude ~lsp-python-ms~ in the configuration file:\n#+BEGIN_SRC emacs-lisp\n(require 'lsp-python-ms)\n(setq lsp-python-ms-auto-install-server t)\n(add-hook 'python-mode-hook #'lsp) ; or lsp-deferred\n#+END_SRC\n\nA minimal ~use-package~ initialization might be:\n#+BEGIN_SRC elisp\n  (use-package lsp-python-ms\n    :ensure t\n    :init (setq lsp-python-ms-auto-install-server t)\n    :hook (python-mode . (lambda ()\n                            (require 'lsp-python-ms)\n                            (lsp))))  ; or lsp-deferred\n#+END_SRC\n\n** Installing the executable\n\n*** NixOS\n\nBuilding the executable manually is difficult on NixOS, but it can be easily installed via the package manager.\nAt the time of writing (May 2020), it is not available on the 20.03 release, but can be acquired on the unstable branch.\n\n#+begin_src bash\n    nix-channel --add https://nixos.org/channels/nixos-unstable nixos\n    nix-channel --update nixos\n#+end_src\n\nYou can then install the executable by running ~nix-env -iA nixpkgs.python-language-server~\nor by adding ~nixpkgs.python-language-server~ to your ~configuration.nix~ and creating a new generation.\nNote that ~python37Packages.python-language-server~ refers to Palintir's language server, not Microsoft's.\n\nFinally, ensure that Emacs knows where to find the executable by setting ~lsp-python-ms-executable~.\n\n#+begin_src elisp\n  (use-package lsp-python-ms\n    :ensure t\n    :hook (python-mode . (lambda ()\n                           (require 'lsp-python-ms)\n                           (lsp)))\n    :init\n    (setq lsp-python-ms-executable (executable-find \"python-language-server\")))\n\n#+end_src\n\n*** Most other distros\n\nNormally the [[https://github.com/Microsoft/python-language-server][python-language-server]] will be downloaded automatically if it doesn't\nexist while opening the python scripts.\n\nIf you have troubles to download the package, you can also build the server yourselves.\n\n1. Install [[https://www.microsoft.com/net/download][dotnet-sdk]]\n2. Clone and build [[https://github.com/Microsoft/python-language-server][python-language-server]]:\n   #+BEGIN_SRC bash\n   git clone https://github.com/Microsoft/python-language-server.git\n   cd python-language-server/src/LanguageServer/Impl\n   dotnet publish -c Release -r osx-x64   # mac\n   #+END_SRC\n\n   Change the ~-r~ flag according to your architecture and operating system.\n   See Microsoft's [[https://docs.microsoft.com/en-us/dotnet/core/rid-catalog][Runtime ID Catalog]] for the right value for your system.\n\n   Then make the binary executable.\n   #+BEGIN_SRC bash\n   chmod a+x $(git rev-parse --show-toplevel)/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer\n   #+END_SRC\n\n   NOTE: on some systems (for example, Fedora), the executable comes out as\n         ~Microsoft.Python.LanguageServer.LanguageServer~.\n\n3. Set executable to ~lsp-python-ms-executable~.\n\n   #+BEGIN_SRC elisp\n   ;; for executable of language server, if it's not symlinked on your PATH\n   (setq lsp-python-ms-executable\n         \"~/python-language-server/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer\")\n   #+END_SRC\n\nFor development, you might find it useful to run =cask install=.\n\n* FAQ\n\n1. Unresolved import warnings\n\n   Set workspace root of `lsp-mode` properly, and add the extra directories to =lsp-python-ms-extra-paths= or =PYTHONPATH=. \n   Refer to [[https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings][Troubleshooting - Unresolved import warnings]] and [[https://github.com/emacs-lsp/lsp-python-ms/issues/96][#96]].\n\n2. Autocompletion doesn't work\n\n   The folder may have huge folders and files, and  the server takes a long time to index them. So please DO NOT put huge files in the project/workspace folder.\n\n3. Set path of the Python executable for each project/workspace\n\n   Set the variable =lsp-python-ms-python-executable= before the `lsp-mode` being loaded.\n\n   First, add =hack-local-variables-hook= in `init.el` to achieve loading `lsp-mode` after the `.dir-locals.el` file of each project/workspace being loaded.\n\n   #+BEGIN_SRC emacs-lisp\n     (add-hook 'hack-local-variables-hook\n\t       (lambda ()\n\t\t (when (derived-mode-p 'python-mode)\n\t\t   (require 'lsp-python-ms)\n\t\t   (lsp)))) ; or lsp-deferred\n   #+END_SRC\n\n   Second, create `.dir-locals.el` file in the root directory of project to specify the varibale =lsp-python-ms-python-executable= for the project/workspace.\n\n   #+BEGIN_SRC emacs-lisp\n     ((python-mode . ((lsp-python-ms-python-executable . \"/.../bin/python\"))))\n   #+END_SRC\n\n* Credit\n\nAll credit to [[https://cpbotha.net][cpbotha]] on [[https://vxlabs.com/2018/11/19/configuring-emacs-lsp-mode-and-microsofts-visual-studio-code-python-language-server/][vxlabs]]! This just tidies and packages his work there.\n"
  },
  {
    "path": "docs/stylesheets/extra.css",
    "content": ":root {\n  --md-primary-fg-color: #234C6D;\n  --md-accent-fg-color: #F7DD73;\n  --md-default-fg-color--light: #3776AB;\n}\n\n.md-footer {\n  --md-default-fg-color: #234C6D;\n}\n\n.md-grid {\n  max-width: 70rem;\n}\n\n.md-typeset a {\n    color: #3776AB;\n}\n"
  },
  {
    "path": "lsp-python-ms.el",
    "content": ";;; lsp-python-ms.el --- The lsp-mode client for Microsoft python-language-server -*- lexical-binding: t -*-\n\n;; Author: Charl Botha\n;; Maintainer: Andrew Christianson, Vincent Zhang\n;; Version: 0.7.2\n;; Package-Requires: ((emacs \"25.1\") (lsp-mode \"6.1\"))\n;; Homepage: https://github.com/emacs-lsp/lsp-python-ms\n;; Keywords: languages tools\n\n\n;; This file is not part of GNU Emacs\n\n;; This file is free software; you can redistribute it and/or modify\n;; it under the terms of the GNU General Public License as published by\n;; the Free Software Foundation; either version 3, or (at your option)\n;; any later version.\n\n;; This program is distributed in the hope that it will be useful,\n;; but WITHOUT ANY WARRANTY; without even the implied warranty of\n;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n;; GNU General Public License for more details.\n\n;; For a full copy of the GNU General Public License\n;; see <http://www.gnu.org/licenses/>.\n\n\n;;; Commentary:\n\n;; from https://vxlabs.com/2018/11/19/configuring-emacs-lsp-mode-and-microsofts-visual-studio-code-python-language-server/\n\n;;; Code:\n(require 'cl-lib)\n(require 'conda nil 'noerror)\n(require 'find-file-in-project nil 'noerror)\n(require 'json)\n(require 'lsp-mode)\n(require 'projectile nil 'noerror)\n(require 'project nil 'noerror)\n\n\n;; Forward declare functions\n(declare-function conda-env-name-to-dir \"ext:conda\")\n(declare-function ffip-get-project-root-directory \"ext:find-file-in-project\")\n\n;; Forward declare variable\n(defvar conda-env-executables-dir)\n(defvar lsp-render-markdown-markup-content)\n\n;; Group declaration\n(defgroup lsp-python-ms nil\n  \"LSP support for python using the Microsoft Python Language Server.\"\n  :group 'lsp-mode\n  :link '(url-link \"https://github.com/Microsoft/python-language-server\"))\n\n(defcustom lsp-python-ms-dir (f-join lsp-server-install-dir \"mspyls/\")\n  \"The directory of the Microsoft Python Language Server.\"\n  :type 'directory\n  :group 'lsp-python-ms)\n\n;; not used since ms-pyls 0.2.92+\n;; see https://github.com/microsoft/vscode-python/blob/master/src/client/activation/languageServer/analysisOptions.ts#L93\n;; (defcustom lsp-python-ms-cache-dir\n;;   (directory-file-name (locate-user-emacs-file \".lsp-python/\"))\n;;   \"Path to directory where the server will write cache files.\n\n;; If this is nil, the language server will write cache files in a directory\n;; sibling to the root of every project you visit\")\n\n(defcustom lsp-python-ms-guess-env t\n  \"Should the language server guess the paths.\n\nIf true, check for pyenv environment/version files, then conda\nenvironment files, then project-local virtual environments, then\nfall back to the python on the head of PATH.  Otherwise, just use\nthe python on the head of PATH.\"\n  :type 'boolean\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-python-executable nil\n  \"Path to specify the Python executable for the Microsoft Python Language Server.\"\n  :type '(choice (const :tag \"None\" nil) file)\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-extra-paths []\n  \"A list of additional paths to search for python packages.\n\nThis should be a list of paths corresponding to additional python\nlibrary directories you want to search for completions.  Paths\nshould be as they are (or would appear) in sys.path.  Paths will\nbe prepended to the search path, and so will shadow duplicate\nnames in search paths returned by the interpreter.\"\n  :type 'lsp-string-vector\n  :group 'lsp-python-ms)\n(make-variable-buffer-local 'lsp-python-ms-extra-paths)\n\n(defcustom lsp-python-ms-python-executable-cmd \"python\"\n  \"Command to specify the Python command for the Microsoft Python Language Server.\n\nSimilar to the `python-shell-interpreter', but used only with mspyls.\nUseful when there are multiple python versions in system.\ne.g, there are `python2' and `python3', both in system PATH,\nand the default `python' links to python2,\nset as `python3' to let ms-pyls use python 3 environments.\"\n  :type 'string\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-prefer-remote-env t\n  \"If Non-nil, will prefer remote python environment.\nOnly available in Emacs 27 and above.\"\n  :type 'boolean\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-executable (concat lsp-python-ms-dir\n                                            \"Microsoft.Python.LanguageServer\"\n                                            (if (eq system-type 'windows-nt) \".exe\" \"\"))\n  \"Path to the Microsoft Python LanguageServer binary.\"\n  :type '(file :must-match t)\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-auto-install-server t\n  \"Install Microsoft Python Language Server automatically.\"\n  :type 'boolean\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-nupkg-channel \"stable\"\n  \"The channel of nupkg for the Microsoft Python Language Server:\nstable, beta or daily.\"\n  :type 'string\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-completion-add-brackets t\n  \"Whether to add brackets after completion of functions.\"\n  :type 'boolean\n  :group 'lsp-python-ms)\n\n;; See https://github.com/microsoft/python-language-server/blob/master/src/Analysis/Ast/Impl/Definitions/AnalysisOptions.cs\n(defcustom lsp-python-ms-cache \"None\"\n  \"The cache level of analysis for Microsoft Python Language Server.\"\n  :type '(choice\n          (const \"None\")\n          (const \"System\")\n          (const \"Library\"))\n  :group 'lsp-python-ms)\n\n;; See https://github.com/microsoft/python-language-server for more diagnostics\n(defcustom lsp-python-ms-errors [\"unknown-parameter-name\"\n                                 \"undefined-variable\"\n                                 \"parameter-missing\"\n                                 \"positional-argument-after-keyword\"\n                                 \"too-many-function-arguments\"]\n  \"Microsoft Python Language Server Error types.\"\n  :type 'lsp-string-vector\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-warnings [\"unresolved-import\"\n                                   \"parameter-already-specified\"\n                                   \"too-many-positional-arguments-before-star\"]\n  \"Microsoft Python Language Server Warning types.\"\n  :type 'lsp-string-vector\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-information []\n  \"Microsoft Python Language Server Information types.\"\n  :type 'lsp-string-vector\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-disabled []\n  \"Microsoft Python Language Server Disabled types.\"\n  :type 'lsp-string-vector\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-parse-dot-env-enabled t\n  \"Automatically parse .env file in the project root if non-nil.\"\n  :type 'boolean\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-base-url \"https://pvsc.blob.core.windows.net\"\n  \"The base url to get nupkg package.\nThe alternative is `https://pvsc.azureedge.net'.\"\n  :type 'string\n  :group 'lsp-python-ms)\n\n(defcustom lsp-python-ms-log-level \"Error\"\n  \"Log Level definition.\"\n  :type 'string\n  :group 'lsp-python-ms\n  :options (list \"Trace\"\n                 \"Info\"\n                 \"Information\"\n                 \"Error\"\n                 \"Warning\"))\n\n(defcustom lsp-python-ms-extra-major-modes '()\n  \"A list of additional major modes in which to activate.\n\nIn addition to the `python-mode', you may wish the Microsoft Python\nLanguage Server to activate in other major modes.  If so, list them\nhere.\"\n  :type 'list\n  :group 'lsp-python-ms)\n\n(defun lsp-python-ms-latest-nupkg-url (&optional channel)\n  \"Get the nupkg url through CHANNEL from Microsoft Python Language Server.\"\n  (let ((channel (or channel \"stable\")))\n    (unless (member channel '(\"stable\" \"beta\" \"daily\"))\n      (user-error \"Unknown channel: %s\" channel))\n    (with-current-buffer\n        (url-retrieve-synchronously\n         (format \"%s/python-language-server-%s?restype=container&comp=list&prefix=Python-Language-Server-%s-x64\"\n                 lsp-python-ms-base-url\n                 channel\n                 (cond ((eq system-type 'darwin)  \"osx\")\n                       ((eq system-type 'gnu/linux) \"linux\")\n                       ((eq system-type 'windows-nt) \"win\")\n                       (t (user-error \"Unsupported system: %s\" system-type)))))\n      (goto-char (point-min))\n      (re-search-forward \"\\n\\n\")\n      (pcase (xml-parse-region (point) (point-max))\n        (`((EnumerationResults\n            ((ContainerName . ,_))\n            (Prefix nil ,_)\n            (Blobs nil . ,blobs)\n            (NextMarker nil)))\n         (cdar\n          (sort\n           (mapcar (lambda (blob)\n                     (pcase blob\n                       (`(Blob\n                          nil\n                          (Name nil ,_)\n                          (Url nil ,url)\n                          (Properties nil (Last-Modified nil ,last-modified) . ,_))\n                        (cons (apply #'encode-time (parse-time-string last-modified)) url))))\n                   blobs)\n           (lambda (t1 t2)\n             (time-less-p (car t2) (car t1))))))))))\n\n(defun lsp-python-ms--install-server (_client callback error-callback update?)\n  \"Downloading Microsoft Python Language Server to the specified path.\"\n  (unless (and (not update?)\n               (f-exists? lsp-python-ms-executable))\n    (let* ((temp-file (make-temp-file \"mspyls\" nil \".zip\"))\n           (install-dir (expand-file-name lsp-python-ms-dir))\n           (unzip-script (cond ((executable-find \"unzip\")\n                                (format \"mkdir -p %s && unzip -qq %s -d %s\"\n                                        install-dir temp-file install-dir))\n                               ((executable-find \"powershell\")\n                                (format \"powershell -noprofile -noninteractive \\\n  -nologo -ex bypass Expand-Archive -path '%s' -dest '%s'\" temp-file install-dir))\n                               (t (lsp--info \"Unable to extract '%s' to '%s'! \\\n  Please extract manually.\" temp-file install-dir)))))\n\n      (lsp--info \"Downloading Microsoft Python Language Server...\")\n\n      (url-retrieve\n       (lsp-python-ms-latest-nupkg-url lsp-python-ms-nupkg-channel)\n       (lambda (_data)\n         ;; Skip http header\n         (re-search-forward \"\\r?\\n\\r?\\n\")\n\n         ;; Save to the temp file\n         (let ((coding-system-for-write 'binary))\n           (write-region (point) (point-max) temp-file))\n\n         (lsp--info \"Downloading Microsoft Python Language Server...done\")\n\n         ;; Extract the archive\n         (f-delete install-dir t)\n\n         (lsp-async-start-process\n          (lambda ()\n            (when (f-exists? lsp-python-ms-executable)\n              (lsp--info \"Extracted Microsoft Python Language Server\")\n              ;; Make the binary executable\n              (chmod lsp-python-ms-executable #o755)\n              ;; Start LSP if need\n              (and lsp-mode (lsp)))\n            (funcall callback))\n          error-callback\n          (if (executable-find \"unzip\") \"sh\" \"cmd\")\n          (if (executable-find \"unzip\") \"-c\" \"/c\")\n          unzip-script))))))\n\n;;;###autoload\n(defun lsp-python-ms-update-server ()\n  \"Update Microsoft Python Language Server.\n\nOn Windows, if the server is running, the updating will fail.\nAfter stopping or killing the process, retry to update.\"\n  (interactive)\n  (lsp-python-ms--install-server nil #'ignore #'lsp--error t))\n\n(defun lsp-python-ms--venv-dir (dir)\n  \"Check if the directory contains a virtualenv.\"\n  (let ((dirs (and dir (f-directories dir))))\n    (car (seq-filter #'lsp-python-ms--venv-python dirs))))\n\n(defun lsp-python-ms--venv-python (dir)\n  \"Check if a directory is a virtualenv.\"\n  (let* ((python? (and t (f-expand \"bin/python\" dir)))\n         (python3? (and python? (f-expand \"bin/python3\" dir)))\n         (python (and python3?\n                      (cond ((f-executable? python?) python?)\n                            ((f-executable? python3?) python3?)\n                            (t nil))))\n         (not-system (and python\n                          (let ((dir-parent (f-parent dir)))\n                            (not (or (string-equal dir-parent (expand-file-name \"~\"))\n                                     (string-equal dir-parent \"/\")))))))\n    (and not-system python)))\n\n(defun lsp-python-ms--dominating-venv-python (&optional dir)\n  \"Look for directories that look like venvs.\"\n  (when-let ((dominating-venv\n              (or (locate-dominating-file (or dir default-directory) #'lsp-python-ms--venv-python)\n                  (lsp-python-ms--venv-dir (locate-dominating-file (or dir default-directory) #'lsp-python-ms--venv-dir)))))\n    (lsp-python-ms--venv-python dominating-venv)))\n\n(defun lsp-python-ms--dominating-conda-python (&optional dir)\n  \"Locate dominating conda environment.\"\n  (let* ((path (or dir default-directory))\n         (yamls (and path\n                     '(\"environment.yml\" \"environment.yaml\"\n                       \"env.yml\" \"env.yaml\" \"dev-environment.yml\"\n                       \"dev-environment.yaml\")))\n         (dominating-yaml (and yamls\n                               (seq-map (lambda (file)\n                                          (when (locate-dominating-file path file)\n                                            (expand-file-name file\n                                                              (locate-dominating-file path file))))\n                                        yamls)))\n         (dominating-yaml-file (and dominating-yaml\n                                    (car (seq-filter\n                                          (lambda (file) file) dominating-yaml))))\n         (dominating-conda-name (and dominating-yaml-file\n                                     (fboundp 'conda--get-name-from-env-yml)\n                                     (or (bound-and-true-p conda-env-current-name)\n                                         (conda--get-name-from-env-yml dominating-yaml-file)))))\n    (when dominating-conda-name\n      (expand-file-name\n       (file-name-nondirectory lsp-python-ms-python-executable-cmd)\n       (expand-file-name conda-env-executables-dir\n                         (conda-env-name-to-dir dominating-conda-name))))))\n\n(defun lsp-python-ms--dominating-pyenv-python (&optional dir)\n  \"Locate dominating pyenv-managed python.\"\n  (let ((dir (or dir default-directory)))\n    (when (locate-dominating-file dir \".python-version\")\n      (string-trim (shell-command-to-string \"pyenv which python\")))))\n\n(defun lsp-python-ms--dominating-asdf-python (&optional dir)\n  \"Locate dominating asdf-managed python\"\n  (let ((dir (or dir default-directory)))\n    (when (locate-dominating-file dir \".tool-versions\")\n      (string-trim (shell-command-to-string \"asdf which python\")))))\n\n(defun lsp-python-ms--valid-python (path)\n  (and path (f-executable? path) path))\n\n(defun lsp-python-ms-locate-python (&optional dir)\n  \"Look for virtual environments local to the workspace.\"\n  (let* ((pyenv-python (lsp-python-ms--dominating-pyenv-python dir))\n         (asdf-python (lsp-python-ms--dominating-asdf-python dir))\n         (venv-python (lsp-python-ms--dominating-venv-python dir))\n         (conda-python (lsp-python-ms--dominating-conda-python dir))\n         (sys-python\n          (with-no-warnings\n            (if (>= emacs-major-version 27)\n                (executable-find lsp-python-ms-python-executable-cmd lsp-python-ms-prefer-remote-env)\n              ;; This complains in Windows' Emacs 26.1, see #141\n              (executable-find lsp-python-ms-python-executable-cmd)))))\n    ;; pythons by preference: local pyenv version, local conda version\n\n    (if lsp-python-ms-guess-env\n        (cond ((lsp-python-ms--valid-python lsp-python-ms-python-executable))\n              ((lsp-python-ms--valid-python venv-python))\n              ((lsp-python-ms--valid-python asdf-python))\n              ((lsp-python-ms--valid-python pyenv-python))\n              ((lsp-python-ms--valid-python conda-python))\n              ((lsp-python-ms--valid-python sys-python)))\n      (cond ((lsp-python-ms--valid-python sys-python))))))\n\n;; it's crucial that we send the correct Python version to MS PYLS,\n;; else it returns no docs in many cases furthermore, we send the\n;; current Python's (can be virtualenv) sys.path as searchPaths\n(defun lsp-python-ms--get-python-ver-and-syspath (&optional workspace-root)\n  \"Return list with pyver-string and list of python search paths.\n\nThe WORKSPACE-ROOT will be prepended to the list of python search\npaths and then the entire list will be json-encoded.\"\n  (let* ((python (and t (lsp-python-ms-locate-python)))\n         (workspace-root (and python (or workspace-root \".\")))\n         (default-directory (and workspace-root workspace-root))\n         (init (and default-directory\n                    \"from __future__ import print_function; import sys; sys.path = list(filter(lambda p: p != '', sys.path)); import json;\"))\n         (ver (and init \"v=(\\\"%s.%s\\\" % (sys.version_info[0], sys.version_info[1]));\"))\n         (sp (and ver (concat \"sys.path.insert(0, '\" workspace-root \"'); p=sys.path;\")))\n         (ex (and sp \"e=sys.executable;\"))\n         (val (and ex \"print(json.dumps({\\\"version\\\":v,\\\"paths\\\":p,\\\"executable\\\":e}))\")))\n    (when val\n      (with-temp-buffer\n        (call-process python nil t nil \"-c\"\n                      (concat init ver sp ex val))\n        (let* ((json-array-type 'vector)\n               (json-key-type 'string)\n               (json-object-type 'hash-table)\n               (json-string (buffer-string))\n               (json-hash (json-read-from-string json-string)))\n          (list\n           (gethash \"version\" json-hash)\n           (gethash \"paths\" json-hash)\n           (gethash \"executable\" json-hash)))))))\n\n(defun lsp-python-ms--workspace-root ()\n  \"Get the path of the root of the current workspace.\n\nUse `lsp-workspace-root', which is pressent in the \\\"new\\\"\nlsp-mode and works when there's an active session.  Next try ffip\nor projectile, or just return `default-directory'.\"\n  (cond\n   ((fboundp #'lsp-workspace-root) (lsp-workspace-root))\n   ((fboundp #'ffip-get-project-root-directory) (ffip-get-project-root-directory))\n   ((fboundp #'projectile-project-root) (projectile-project-root))\n   ((fboundp #'project-current) (when-let ((project (project-current)))\n                                  (car (or (and (fboundp 'project-root) (project-root project))\n                                           ;; Function `project-roots' is obsolete, by having\n                                           ;; just to make compatible to older `project.el' package.\n                                           (with-no-warnings (project-roots project))))))\n   (t default-directory)))\n\n;; I based most of this on the vs.code implementation:\n;; https://github.com/microsoft/vscode-python/blob/master/src/client/activation/languageServer/analysisOptions.ts\n;; (it still took quite a while to get right, but here we are!)\n(defun lsp-python-ms--extra-init-params (&optional workspace)\n  \"Return form describing parameters for language server.\n\nOld lsp will pass in a WORKSPACE, new lsp has a global\nlsp-workspace-root function that finds the current buffer's\nworkspace root.  If nothing works, default to the current file's\ndirectory\"\n  (let ((workspace-root (or (if workspace\n                                (lsp--workspace-root workspace)\n                              (lsp-python-ms--workspace-root))\n                            default-directory)))\n    (when lsp-python-ms-parse-dot-env-enabled\n      (lsp-python-ms--parse-dot-env workspace-root))\n    (cl-destructuring-bind (pyver pysyspath pyintpath)\n      (lsp-python-ms--get-python-ver-and-syspath workspace-root)\n      `(:interpreter\n        (:properties\n         (:InterpreterPath ,pyintpath :UseDefaultDatabase t :Version ,pyver))\n        ;; preferredFormat \"markdown\" or \"plaintext\"\n        ;; experiment to find what works best -- over here mostly plaintext\n        :displayOptions (:preferredFormat\n                         \"markdown\"\n                         :trimDocumentationLines :json-false\n                         :maxDocumentationLineLength 0\n                         :trimDocumentationText :json-false\n                         :maxDocumentationTextLength 0)\n        :searchPaths ,(vconcat lsp-python-ms-extra-paths pysyspath)\n        :analysisUpdates t\n        :asyncStartup t\n        :logLevel ,lsp-python-ms-log-level\n        :typeStubSearchPaths ,(vector (expand-file-name (f-join lsp-python-ms-dir \"Typeshed\")))))))\n\n(defun lsp-python-ms--filter-nbsp (str)\n  \"Filter nbsp entities from STR.\"\n  (let ((rx \"&nbsp;\"))\n    (when (eq system-type 'windows-nt)\n      (setq rx (concat rx \"\\\\|\\r\")))\n    (when str\n      (replace-regexp-in-string rx \" \" str))))\n\n(defun lsp-python-ms--parse-dot-env (root &optional envvar)\n  \"Set environment variable (default PYTHONPATH) from .env file if this file exists in the project root.\"\n  (let* ((envvar (or envvar \"PYTHONPATH\"))\n         (file (f-join (file-name-as-directory root) \".env\"))\n         (rx (concat \"^[:blank:]*\" envvar \"[:blank:]*=[:blank:]*\"))\n         val)\n    (when (and (f-exists? file) (f-file? file) (f-readable? file))\n      (with-temp-buffer\n        (insert-file-contents file)\n        (keep-lines rx (point-min) (point-max))\n        (when (string-match (concat rx \"\\\\(.*\\\\)\") (buffer-string))\n          (setq val (match-string 1 (buffer-string)))\n          (unless (string-empty-p val)\n            (setenv envvar val)))))))\n\n(defun lsp-python-ms--language-server-started-callback (_workspace _params)\n  \"Handle the python/languageServerStarted message.\n\nWORKSPACE is just used for logging and _PARAMS is unused.\"\n   (lsp--info \"Microsoft Python language server started\"))\n\n;; this gets called when we do lsp-describe-thing-at-point\n;; see lsp-methods.el. As always, remove Microsoft's unwanted entities :(\n(setq lsp-render-markdown-markup-content #'lsp-python-ms--filter-nbsp)\n\n;; lsp-ui-doc--extract gets called when hover docs are requested\n;; as always, we have to remove Microsoft's unnecessary &nbsp; entities\n(advice-add 'lsp-ui-doc--extract\n            :filter-return #'lsp-python-ms--filter-nbsp)\n\n;; lsp-ui-sideline--format-info gets called when lsp-ui wants to show\n;; hover info in the sideline again &nbsp; has to be removed\n(advice-add 'lsp-ui-sideline--format-info\n            :filter-return #'lsp-python-ms--filter-nbsp)\n\n(defun lsp-python-ms--report-progress-callback (_workspace params)\n  \"Log progress information.\"\n  (when (and (arrayp params) (> (length params) 0))\n    (lsp-log (aref params 0))))\n\n(defun lsp-python-ms--begin-progress-callback (workspace &rest _)\n  (with-lsp-workspace workspace\n    (--each (lsp--workspace-buffers workspace)\n      (when (buffer-live-p it)\n        (with-current-buffer it\n          (lsp--spinner-start)))))\n  (lsp--info \"Microsoft Python language server is analyzing...\"))\n\n(defun lsp-python-ms--end-progress-callback (workspace &rest _)\n  (with-lsp-workspace workspace\n    (--each (lsp--workspace-buffers workspace)\n      (when (buffer-live-p it)\n        (with-current-buffer it\n          (lsp--spinner-stop))))\n    (lsp--info \"Microsoft Python language server is analyzing...done\")))\n\n(lsp-register-custom-settings\n `((\"python.autoComplete.addBrackets\" lsp-python-ms-completion-add-brackets t)\n   (\"python.analysis.cachingLevel\" lsp-python-ms-cache)\n   (\"python.analysis.errors\" lsp-python-ms-errors)\n   (\"python.analysis.warnings\" lsp-python-ms-warnings)\n   (\"python.analysis.information\" lsp-python-ms-information)\n   (\"python.analysis.disabled\" lsp-python-ms-disabled)\n   (\"python.analysis.autoSearchPaths\" (lambda () (<= (length lsp-python-ms-extra-paths) 0)) t)\n   (\"python.autoComplete.extraPaths\" lsp-python-ms-extra-paths)))\n\n(dolist (mode lsp-python-ms-extra-major-modes)\n  (add-to-list 'lsp-language-id-configuration `(,mode . \"python\")))\n\n(lsp-register-client\n (make-lsp-client\n  :new-connection (lsp-stdio-connection (lambda () lsp-python-ms-executable)\n                                        (lambda () (f-exists? lsp-python-ms-executable)))\n  :major-modes (append '(python-mode) lsp-python-ms-extra-major-modes)\n  :server-id 'mspyls\n  :priority 1\n  :initialization-options 'lsp-python-ms--extra-init-params\n  :notification-handlers (lsp-ht (\"python/languageServerStarted\" 'lsp-python-ms--language-server-started-callback)\n                                 (\"telemetry/event\" 'ignore)\n                                 (\"python/reportProgress\" 'lsp-python-ms--report-progress-callback)\n                                 (\"python/beginProgress\" 'lsp-python-ms--begin-progress-callback)\n                                 (\"python/endProgress\" 'lsp-python-ms--end-progress-callback))\n  :initialized-fn (lambda (workspace)\n                    (with-lsp-workspace workspace\n                      (lsp--set-configuration (lsp-configuration-section \"python\"))))\n  :download-server-fn (lambda (client callback error-callback update?)\n                        (when lsp-python-ms-auto-install-server\n                          (lsp-python-ms--install-server client callback error-callback update?)))))\n\n(provide 'lsp-python-ms)\n\n;;; lsp-python-ms.el ends here\n"
  },
  {
    "path": "mkdocs.yml",
    "content": "site_name: LSP Python MS\n\nextra_css:\n  - stylesheets/extra.css\n\ntheme:\n  name: material\n  logo: images/logo.png\n  favicon: images/logo.png\n  icon:\n    repo: fontawesome/brands/github\n\nextra:\n  social:\n    - icon: fontawesome/brands/github-alt\n      link: https://github.com/emacs-lsp\n    - icon: fontawesome/brands/twitter\n      link: https://twitter.com/yonchovski\n    - icon: fontawesome/brands/gitter\n      link: https://gitter.im/emacs-lsp/lsp-mode\n\nrepo_name: emacs-lsp/lsp-python-ms\nrepo_url: https://github.com/emacs-lsp/lsp-python-ms\n\nmarkdown_extensions:\n  - pymdownx.superfences\n  - pymdownx.emoji:\n      emoji_index: !!python/name:materialx.emoji.twemoji\n      emoji_generator: !!python/name:materialx.emoji.to_svg\n  - codehilite\n  - toc:\n      permalink: '#'\n\nplugins:\n  - search\n  - awesome-pages\n  - git-revision-date-localized\n"
  },
  {
    "path": "test/windows-bootstrap.el",
    "content": ";;; windows-bootstrap.el --- Windows test bootstrap -*- lexical-binding: t; -*-\n;;\n;; Copyright (C) 2020-2021 emacs-lsp maintainers\n;;\n;; This program is free software; you can redistribute it and/or modify\n;; it under the terms of the GNU General Public License as published by\n;; the Free Software Foundation, either version 3 of the License, or\n;; (at your option) any later version.\n\n;; This program is distributed in the hope that it will be useful,\n;; but WITHOUT ANY WARRANTY; without even the implied warranty of\n;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n;; GNU General Public License for more details.\n\n;; You should have received a copy of the GNU General Public License\n;; along with this program.  If not, see <https://www.gnu.org/licenses/>.\n;;\n;;; Commentary:\n;;\n;;  Windows test bootstrap\n;;\n;;; Code:\n\n(require 'package)\n\n(let* ((package-archives '((\"melpa\" . \"https://melpa.org/packages/\")\n                           (\"gnu\" . \"http://elpa.gnu.org/packages/\")))\n       (pkgs '(lsp-mode projectile project)))\n  (package-initialize)\n  (package-refresh-contents)\n\n  (mapc (lambda (pkg)\n          (unless (package-installed-p pkg)\n            (package-install pkg)))\n        pkgs)\n\n  (add-hook 'kill-emacs-hook\n            `(lambda () (delete-directory ,user-emacs-directory t))))\n\n;;; windows-bootstrap.el ends here\n"
  }
]