muffinmad / anakin-language-server

Yet another Jedi Python language server
GNU General Public License v3.0
37 stars 3 forks source link

Mypy diagnostics #2

Closed rwols closed 4 years ago

rwols commented 4 years ago

It would be nice to see mypy diagnostics enabled. I am using a lot of type hinting in my code and the extra diagnostics about type mismatches helps.

rwols commented 4 years ago

This would also show syntax errors. It would be nice to see syntax errors as diagnostics. For instance:

Screenshot from 2020-05-02 21-14-38

Here on line 201 there's obviously a syntax error.

Mypy indeed reports a syntax error if I run tox:

plugin/core/transports.py:201: error: invalid syntax
muffinmad commented 4 years ago

Jedi itself report invalid syntax in similar code for me.

def foo():
    bar = 1
    baz = 2
    bar aasdf baz
client-notification Sat May  2 22:18:56 2020:
(:jsonrpc "2.0" :method "textDocument/didSave" :params
          (:text "def foo():\n    bar = 1\n    baz = 2\n    bar aasdf baz\n" :textDocument
                 (:uri "file:///Users/mad/test.py")))

server-notification Sat May  2 22:18:56 2020:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
          (:uri "file:///Users/mad/test.py" :diagnostics
                [(:range
                  (:start
                   (:line 3 :character 8)
                   :end
                   (:line 3 :character 13))
                  :message "Invalid syntax" :severity 1 :code nil :source "jedi" :relatedInformation nil)]))

Is that marker on line 201 means that file is not saved yet? I found reporting errors on file change annoying so anakinls report errors on open and save only.

rwols commented 4 years ago

I found reporting errors on file change annoying so anakinls report errors on open and save only.

The response to the initialize request does not contain save:

:: <<< anakin 1: {'capabilities': {'referencesProvider': True, 'renameProvider': False, 'documentSymbolProvider': False, 'workspaceSymbolProvider': False, 'codeActionProvider': False, 'hoverProvider': True, 'documentFormattingProvider': False, 'executeCommandProvider': {'commands': []}, 'documentRangeFormattingProvider': False, 'textDocumentSync': 2, 'documentHighlightProvider': False, 'definitionProvider': True, 'signatureHelpProvider': {'triggerCharacters': []}, 'workspace': {'workspaceFolders': {'changeNotifications': True, 'supported': True}}, 'completionProvider': {'triggerCharacters': ['.'], 'resolveProvider': False}}}

Here, we have

'textDocumentSync': 2

This means an editor should not notify textDocument/didSave. The didSave notification is only sent when the server specifies something like this:


'textDocumentSync`: {
  'save': {}  # an empty dict is sufficient to make editors send didSave
  'change': 2  # this is your old `textDocument': 2
}
rwols commented 4 years ago

See also https://microsoft.github.io/language-server-protocol/specification#textDocument_didSave

muffinmad commented 4 years ago

Wrong issue number in commit message

rwols commented 4 years ago

I've enabled mypy and it seems to be working. Thanks.