Closed algoterranean closed 4 years ago
Can you post a screenshot about the identation issues?
I pushed a fix about the duplicate name.
Using this Python code:
import os
import sys
class Example:
def __init__(self):
self.x = 1
I would expect lsp-treemacs-symbols-list to display the symbols like, say:
os
sys
Example
__init__
x
What I get is (with your 2nd defun):
What I get (with the 1st defun):
It looks like (seq-empty-p children)
is always true.
FWIW, evaluating
(lsp-request "textDocument/documentSymbol" `(:textDocument ,(lsp--text-document-identifier)))
in my code buffer gives me:
(#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name os containerName nil location #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (uri file:///mnt/projects/t.py range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 0)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 9)))))) kind 2)) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name sys containerName nil location #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (uri file:///mnt/projects/t.py range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 0)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 10)))))) kind 2)) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name Example containerName nil location #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (uri file:///mnt/projects/t.py range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 3 character 0)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 6 character 0)))))) kind 5)) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name __init__ containerName Example location #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (uri file:///mnt/projects/t.py range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 4)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 6 character 0)))))) kind 12)) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name x containerName __init__ location #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (uri file:///mnt/projects/t.py range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 5 character 8)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 5 character 18)))))) kind 13)))
Not sure if children
is supposed to be included in this return value, but it does include a containerName
reference.
I am using Palantir's python language server for this (https://github.com/palantir/python-language-server) not the MS one, if that makes a difference.
Ah, I see - the offset is the expected behaviour here it is the explanation:
Note that in order to have the nodes without children aligned to the nodes with children aligned we have to indent then in the same way.
VScode works in the same way:
Shouldn't the expected behavior though be to have, for example, __init__
indented as a child of Example
, since it is a method?
Yes, please ignore the previous comment, apparently, there is pyls specific an issue. I will investigate.
Using the MS python language server seems to fix the indentation issue:
And this backend does return a children
node:
(#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name os kind 2 deprecated nil range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 7)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 9)))) selectionRange #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 7)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 0 character 9)))) children [])) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name sys kind 2 deprecated nil range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 7)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 10)))) selectionRange #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 7)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 1 character 10)))) children [])) #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name Example kind 5 deprecated nil range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 3 character 0)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 5 character 18)))) selectionRange #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 3 character 6)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 3 character 13)))) children [#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name __init__ kind 9 deprecated nil range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 4)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 5 character 18)))) selectionRange #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 8)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 16)))) children [#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (name self kind 13 deprecated nil range #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 17)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 21)))) selectionRange #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (start #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 17)) end #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (line 4 character 21)))) children []))]))])))
Note though that self.x
doesn't show up in the symbols list, but it's also not being returned from the backend as far as I can tell. So maybe I need to fool around with the config options for this LSP server.
No, it is an issue in lsp-treemacs-symbols , I will fix it. It is caused by pyls not returning hierarchical elements. This was the old documentSymbols format.
Proposed fix at https://github.com/emacs-lsp/lsp-treemacs/pull/27
I will test it for some time before before merging.
Thanks. The patch is working well for me so far!
Actually, I noticed the symbols list is being truncated after the first class or defun. For example:
def test():
x = 20
class Something:
def __init__(self):
x = 20
def what(self):
y = 90
Shows
and
class Something:
def __init__(self):
x = 20
def what(self):
y = 90
def test():
x = 20
Shows
Note that there looks to be a partial problem with indentation.
@algoterranean pushed a fix, I was using the wrong function -split-with instead of -separate.
Did you mean to redefine
lsp-treemacs--symbol-icon
inlsp-treemacs.el
?The second
defun
does not display icons for me, but the first one works fine (at least, it displays the icons properly, but indentation seems to be lacking for child nodes... not sure if this is related).