From 91261cb1ff5a67d380d8a7ed889903f11bdc7c23 Mon Sep 17 00:00:00 2001 From: Guoqiang Jin Date: Fri, 28 Jun 2019 16:28:31 +0800 Subject: [PATCH 1/3] add typeshed support --- lsp-python-ms.el | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lsp-python-ms.el b/lsp-python-ms.el index d98a709..0beb8da 100644 --- a/lsp-python-ms.el +++ b/lsp-python-ms.el @@ -44,12 +44,14 @@ This is the directory containing Microsoft.Python.LanguageServer.dll.") -(defvar lsp-python-ms-cache-dir - (directory-file-name (locate-user-emacs-file ".lsp-python/")) - "Path to directory where the server will write cache files. +;; not used since ms-pyls 0.2.92+ +;; see https://github.com/microsoft/vscode-python/blob/master/src/client/activation/languageServer/analysisOptions.ts#L93 +;; (defvar lsp-python-ms-cache-dir +;; (directory-file-name (locate-user-emacs-file ".lsp-python/")) +;; "Path to directory where the server will write cache files. -If this is nil, the language server will write cache files in a directory -sibling to the root of every project you visit") +;; If this is nil, the language server will write cache files in a directory +;; sibling to the root of every project you visit") (defun lsp-python-ms--find-dotnet () "Get the path to dotnet, or return `lsp-python-ms-dotnet'." @@ -66,7 +68,7 @@ sibling to the root of every project you visit") You only need to set this if dotnet is not on your path.") (defvar lsp-python-ms-extra-paths '() - "A list of additional paths to search for python packages + "A list of additional paths to search for python packages. This should be a list of paths corresponding to additional python library directories you want to search for completions. Paths @@ -74,6 +76,15 @@ should be as they are (or would appear) in sys.path. Paths will be prepended to the search path, and so will shadow duplicate names in search paths returned by the interpreter.") +(defvar lsp-python-executable-cmd "python" + "Command to specify the python command for ms-pyls. + +Similar to the `python-shell-interpreter', but used only with `ms-pyls'. +Useful when there are multiple python versions in system. +e.g, there are `python2' and `python3', both in system PATH, +and the default `python' links to python2, +set as `python3' to let ms-pyls use python 3 environments.") + (defun lsp-python-ms--find-server-executable () "Get path to the python language server executable." (cond @@ -95,7 +106,7 @@ names in search paths returned by the interpreter.") The WORKSPACE-ROOT will be prepended to the list of python search paths and then the entire list will be json-encoded." - (let ((python (executable-find "python")) + (let ((python (executable-find lsp-python-executable-cmd)) (init "from __future__ import print_function; import sys; import json;") (ver "print(\"%s.%s\" % (sys.version_info[0], sys.version_info[1]));") (sp (concat "sys.path.insert(0, '" workspace-root "'); print(json.dumps(sys.path))"))) @@ -130,19 +141,22 @@ directory" (lsp-python-ms--get-python-ver-and-syspath workspace-root) `(:interpreter (:properties (:InterpreterPath - ,(executable-find "python") + ,(executable-find lsp-python-executable-cmd) ;; this database dir will be created if required - :DatabasePath ,(expand-file-name (directory-file-name lsp-python-ms-cache-dir)) + ;; :DatabasePath ,(expand-file-name (directory-file-name lsp-python-ms-cache-dir)) :Version ,pyver)) ;; preferredFormat "markdown" or "plaintext" ;; experiment to find what works best -- over here mostly plaintext :displayOptions ( - :preferredFormat "plaintext" + :preferredFormat "markdown" :trimDocumentationLines :json-false :maxDocumentationLineLength 0 :trimDocumentationText :json-false :maxDocumentationTextLength 0) - :searchPaths ,(vconcat lsp-python-ms-extra-paths (json-read-from-string pysyspath)))))) + ;;:searchPaths ,(vconcat lsp-python-ms-extra-paths (json-read-from-string pysyspath)) + :analysisUpdates t + :asyncStartup t + :typeStubSearchPaths ,(list (concat lsp-python-ms-dir "Typeshed")))))) (defun lsp-python-ms--filter-nbsp (str) From 9622d0411aabeab4c782898cda6921fcf5670eef Mon Sep 17 00:00:00 2001 From: Guoqiang Jin Date: Fri, 28 Jun 2019 18:27:59 +0800 Subject: [PATCH 2/3] fix searchPath problem --- lsp-python-ms.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsp-python-ms.el b/lsp-python-ms.el index 0beb8da..20167fb 100644 --- a/lsp-python-ms.el +++ b/lsp-python-ms.el @@ -153,7 +153,7 @@ directory" :maxDocumentationLineLength 0 :trimDocumentationText :json-false :maxDocumentationTextLength 0) - ;;:searchPaths ,(vconcat lsp-python-ms-extra-paths (json-read-from-string pysyspath)) + :searchPaths ,(or lsp-python-ms-extra-paths (list "")) :analysisUpdates t :asyncStartup t :typeStubSearchPaths ,(list (concat lsp-python-ms-dir "Typeshed")))))) From bfb809b6d2cbeabf222c8a3b728216787c715067 Mon Sep 17 00:00:00 2001 From: Guoqiang Jin Date: Sat, 29 Jun 2019 01:24:15 +0800 Subject: [PATCH 3/3] parameters as vector to compatible with emacs27. --- lsp-python-ms.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lsp-python-ms.el b/lsp-python-ms.el index 20167fb..f46395b 100644 --- a/lsp-python-ms.el +++ b/lsp-python-ms.el @@ -153,10 +153,12 @@ directory" :maxDocumentationLineLength 0 :trimDocumentationText :json-false :maxDocumentationTextLength 0) - :searchPaths ,(or lsp-python-ms-extra-paths (list "")) + :searchPaths ,(if lsp-python-ms-extra-paths + (vconcat lsp-python-ms-extra-paths nil) + []) :analysisUpdates t :asyncStartup t - :typeStubSearchPaths ,(list (concat lsp-python-ms-dir "Typeshed")))))) + :typeStubSearchPaths ,(vector (concat lsp-python-ms-dir "Typeshed")))))) (defun lsp-python-ms--filter-nbsp (str)