emacs-lsp / lsp-python-ms

lsp-mode :heart: Microsoft's python language server
https://emacs-lsp.github.io/lsp-python-ms
BSD 3-Clause "New" or "Revised" License
190 stars 41 forks source link

[help] Can lsp give warning if the object's function does not exist? #145

Closed avatar-lavventura closed 3 years ago

avatar-lavventura commented 3 years ago

I am using lsp for Python. I was wondering for an object's function, if there is no definition for it, can lsp give an error/warning or underline it like flycheck does?

example python code:

class World():
    def hello():
        print("hello")

obj = World()
obj.hello()()
obj.foo()   # <=== hoping to see: No definitions found for: foo and underline foo()

Since foo() is not an object under World; I want lsp to give me a warning message letting me know that that function does not exist.


Example configuration could be seen here: https://github.com/rksm/emacs-rust-config

Comment out the lines 9..35 and 48 and add the following (use-package python :ensure nil) save and install packages. Then open a python file, and M-x lsp to start lsp,

seagle0128 commented 3 years ago

If you are using lsp-mode and enable flycheck or flymake, the warnings/errors will be displayed. It's not related to lsp-python-ms.

avatar-lavventura commented 3 years ago

@seagle0128 I am using lsp-mode along with flycheck but the warning for No definitions found for: foo does not show up. Not sure how should I make a setting for this or not?

Sorry I will close the issue here than and will ask on flycheck since it is not related to lsp-mode

seagle0128 commented 3 years ago

Are you using lsp-python-ms and installed mspyls correctly?

avatar-lavventura commented 3 years ago

I have installed it using which is added to my init.el file:

(use-package lsp-python-ms
  :ensure t
  :init (setq lsp-python-ms-auto-install-server t)
  :hook (python-mode . (lambda ()
                          (require 'lsp-python-ms)
                          (lsp))))  ; or lsp-deferred

The way I am using python-language-server as explained as on my question, but I believe its not microsoft's.

Please see my init.el file: https://github.com/avatar-lavventura/dotfiles/blob/main/.emacs

init.el file contains only (use-package python :ensure nil) line.

seagle0128 commented 3 years ago

Try reinstalling mspyls with M-x lsp-python-ms-update-server.

avatar-lavventura commented 3 years ago

I couldn't find any package called lsp-python-ms-update-server in the M-x : package-reinstall or package-install

seagle0128 commented 3 years ago

I mean installing lsp server with the command M-x lsp-python-ms-update-server. Please read the README.

avatar-lavventura commented 3 years ago

@seagle0128 Thanks after installation would it show the warning messages that I asked on my question, please note that it does not?

I have been told that its not possible from many different sources: https://stackoverflow.com/q/66735243/2402577

Python really is not easy to statically analyze. I would be pretty surprised if a linter could do this for anything but the simplest cases.

seagle0128 commented 3 years ago

So your question is for mspyls, while not for lsp-python-ms, if it works well.

avatar-lavventura commented 3 years ago

Sorry I just get lost. For both lsp-python-ms and mspyls I was not able to find a solution.

seagle0128 commented 3 years ago

Quick question, are you able to use mypyls for vscode to get this warning? If yes, it's an issue of lsp-python-ms, otherwise it's for mypyls itself.