Completions response contains duplicates
I'm using version 0.14.0 of Python Language Server while I cannot install the newest versions from the same reason as #270.
Initialize request is following:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"rootUri":"PROJECT_PATH","capabilities":{"workspace":{"applyEdit":true},"textDocument":{"completion":{"completionItem":{"snippetSupport":true}},"synchronization":{"didSave":true}}}}}
I have very simple test file ls_test1.py with one line:
pr
I am requesting for completions at the end of this line. I except to have for example print in the list of results.
My request looks like following:
{"jsonrpc":"2.0","id":12,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:PATH_TO_FILE/ls_test1.py"},"position":{"line":0,"character":2}}}
Language server response looks like following:
{"id":12,"result":{"isIncomplete":false,"items":[{"detail":"builtin print","label":"print","kind":3,"sortText":"yprint","documentation":"print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile: a file-like object (stream); defaults to the current sys.stdout.\nsep: string inserted between values, default a space.\nend: string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream."},{"detail":"builtin property","label":"property","kind":3,"sortText":"yproperty","documentation":"property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n\nfget is a function to be used for getting an attribute value, and likewise\nfset is a function for setting, and fdel a function for del'ing, an\nattribute. Typical use is to define a managed attribute x:\n\nclass C(object):\n def getx(self): return self._x\n def setx(self, value): self._x = value\n def delx(self): del self._x\n x = property(getx, setx, delx, \"I'm the 'x' property.\")\n\nDecorators make defining new properties or modifying existing ones easy:\n\nclass C(object):\n @property\n def x(self):\n \"I am the 'x' property.\"\n return self._x\n @x.setter\n def x(self, value):\n self._x = value\n @x.deleter\n def x(self):\n del self._x\n"},{"documentation":"The \"pass\" statement\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\n\u00a0\u00a0 pass_stmt ::= \"pass\"\n\n\"pass\" is a null operation --- when it is executed, nothing happens.\nIt is useful as a placeholder when a statement is required\nsyntactically, but no code needs to be executed, for example:\n\n\u00a0\u00a0 def f(arg): pass\u00a0\u00a0\u00a0\u00a0# a function that does nothing (yet)\n\n\u00a0\u00a0 class C: pass\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # a class with no methods (yet)","label":"pass","kind":14,"sortText":"apass","detail":"","insertText":"pass"},{"documentation":"Base class for warnings about features which will be deprecated\nin the future.","label":"PendingDeprecationWarning","kind":7,"sortText":"aPendingDeprecationWarning","detail":"","insertText":"PendingDeprecationWarning"},{"documentation":"Not enough permissions.","label":"PermissionError","kind":7,"sortText":"aPermissionError","detail":"","insertText":"PermissionError"},{"documentation":"pow(x, y[, z]) -> number\n\nWith two arguments, equivalent to x\\*\\*y.\u00a0\u00a0With three arguments,\nequivalent to (x\\*\\*y) % z, but may be more efficient (e.g. for ints).","label":"pow(x, y, z)","kind":3,"sortText":"apow","detail":"","insertText":"pow"},{"documentation":"print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile:\u00a0\u00a0a file-like object (stream); defaults to the current sys.stdout.\nsep:\u00a0\u00a0 string inserted between values, default a space.\nend:\u00a0\u00a0 string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream.","label":"print(value, ..., sep, end, file, flush)","kind":3,"sortText":"aprint","detail":"","insertText":"print"},{"documentation":"Process not found.","label":"ProcessLookupError","kind":7,"sortText":"aProcessLookupError","detail":"","insertText":"ProcessLookupError"},{"documentation":"property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n\nfget is a function to be used for getting an attribute value, and likewise\nfset is a function for setting, and fdel a function for del'ing, an\nattribute.\u00a0\u00a0Typical use is to define a managed attribute x:\n\nclass C(object):\n\u00a0\u00a0\u00a0\u00a0def getx(self): return self._x\n\u00a0\u00a0\u00a0\u00a0def setx(self, value): self._x = value\n\u00a0\u00a0\u00a0\u00a0def delx(self): del self._x\n\u00a0\u00a0\u00a0\u00a0x = property(getx, setx, delx, \"I'm the 'x' property.\")\n\nDecorators make defining new properties or modifying existing ones easy:\n\nclass C(object):\n\u00a0\u00a0\u00a0\u00a0@property\n\u00a0\u00a0\u00a0\u00a0def x(self):\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"I am the 'x' property.\"\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return self._x\n\u00a0\u00a0\u00a0\[email protected]\n\u00a0\u00a0\u00a0\u00a0def x(self, value):\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self._x = value\n\u00a0\u00a0\u00a0\[email protected]\n\u00a0\u00a0\u00a0\u00a0def x(self):\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0del self._x","label":"property","kind":7,"sortText":"aproperty","detail":"","insertText":"property"}]},"jsonrpc":"2.0"}
You can notice that print and property are twice on the list. I checked that Jedi completions are:
<Completion: pass>
<Completion: PendingDeprecationWarning>
<Completion: PermissionError>
<Completion: pow>
<Completion: print>
<Completion: ProcessLookupError>
<Completion: property>
and Rope completions are: print (builtin, function) property (builtin, function)
After receiving result, I am using information from the protocol documentation to display appropriate texts to the user. Then, user sees print and property twice.
I think it should be checked by Python Language Server and response should not contain duplicates.
This issue is sort of addressed in 0.15.1 where the rope completions plugin is disabled by default. Rope and Jedi completions serve the same purpose and therefore shouldn't be enabled concurrently. However, we don't want to enforce a single plugin for completions because there are cases where we might want to provide completions for different sorts of things (perhaps smarter content-aware completions).
We can't really de-dupe these results since the same name isn't a sufficient key to dedupe on, and the detail strings from Jedi / Rope are too different.