microsoft / python-language-server

Microsoft Language Server for Python
Apache License 2.0
913 stars 133 forks source link

Autocomplete ignores indentation settings #2034

Open MatejVitek opened 4 years ago

MatejVitek commented 4 years ago

Environment data

Expected behaviour

Autocomplete respects the indentation settings of the file/project/user settings.

Actual behaviour

Autocompletion of double double underscore methods inserts only a single space in the second line.

Steps to reproduce:

  1. Install VS Code with the Python extension
  2. Open a python file.
  3. Type __ini and press CTRL + Space if the autocomplete dropdown doesn't automatically appear.
  4. Press ENTER on the __init__ option.

Other info

This is an issue I've been having for a long time. I've posted several questions about it on SO, and also received answers from at least one person actually working on this extension. However, the problem has not been resolved, so I recently decided to look into it further and it's starting to look more and more like a bug.

The gist of the problem is described in this question and the two linked questions. Basically the __xxx__ autocomplete templates (snippets?) are ignoring the indentation of the file and inserting a single space indentation in their second line. The latest question highlights several things (in response to Brett Cannon's comments in the linked question):

  1. These autocompletes are indeed a part of the Python extension. Using a completely clean installation of VS Code they did not appear. After installing the Python extension (and nothing else), they appeared. rioV8 also confirmed this in his answer.
  2. They appear on two different computers I'm using, one running Ubuntu 18.04 and the other Windows 10. On both systems the issue is present.
  3. rioV8 also had them, however in his case they resulted in the correct indentation. I am not clear as to why. One difference I see is that he uses an indentation of 2 spaces, while I use tabs (usually with tab size 4).
  4. They may have something to do with scrape_module.py in the languageServer.x.x.x directory, although after looking at it, it's unclear where the actual autocompletion body would be defined.

Is there a way to make these autocomplete templates respect the indentation of the file or the user settings or override them?

brettcannon commented 4 years ago

As this is a request to basically expand the functionality of snippets which are actually functionality controlled by VS Code, we have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

MatejVitek commented 4 years ago

Brett,

My question, rather than requesting further functionality, is related more to why these specific snippets (the __xxx__ ones) behave differently to the conventional snippets defined in .../snippets/python.json. The snippets in python.json contain tabular indentation (which I'm guessing gets changed by VS Code depending on your settings) and work correctly for me. The __xxx__ ones (ostensibly defined in scrape_module.py) for me insert a single space, but get different results for other people (see the linked SO thread).

For instance, correctly autocompletes to

But autocompletes to the single-spaced

Additionally, I haven't been able to override the __xxx__ snippets using User snippets (since they don't seem to be defined in the conventional way).

jakebailey commented 4 years ago

These are the LS completions; it's likely we're not using the indention amount we're parsing out of the file (there's no other place for us to get the user's configured setting).

CatNofishing commented 4 years ago

😂Why not support Jedi? At least now it works better than MPLS.

MikhailArkhipov commented 4 years ago

Jedi supported by the Python extension. It is not LS since it is only a completion engine. Completions is just one of the features of language servers.