liushihao456 / symbols-outline.el

Display symbols (functions, variables, etc) in a side window.
GNU General Public License v3.0
56 stars 3 forks source link

Doesn't work with lsp-use-plists #1

Closed noobieebot closed 1 year ago

noobieebot commented 1 year ago

When using this package with lsp-use-plists enabled (https://emacs-lsp.github.io/lsp-mode/page/performance/#use-plists-for-deserialization), I get an error:

(wrong-type-argument hash-table-p (:children [(:detail ....

liushihao456 commented 1 year ago

I've pushed a fix. Could you try again after sync to melpa?

noobieebot commented 1 year ago

I've pushed a fix. Could you try again after sync to melpa?

I think you are using plist-get incorrectly, by default it uses eq to compare instead of equal so keys that are strings won't work.

;; wrong
(plist-get '("name" v) "name") => nil
;; correct
(lax-plist-get '("name" v) "name") => v
;; Emacs 29+ only
(plist-get '("name" v) "name" #'equal) => v

But even after modifying symbols-outline-lsp--get-item to one the latter two form so that getting from the plist works, I still get errors

For a sample file:

#include <iostream>

int main(int argc, char *argv[]) {
    return 0;
}

Error backtrace:


Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  1+(nil)
  (make-symbols-outline-node :name (symbols-outline-lsp--get-item "name" symbol) :kind (symbols-outline-lsp--kind-name (symbols-outline-lsp--get-item "kind" symbol)) :line (1+ (symbols-outline-lsp--get-item "line" (symbols-outline-lsp--get-item "start" (symbols-outline-lsp--get-item "range" symbol)))) :signature (symbols-outline-lsp--get-item "detail" symbol) :parent tree)
  (let ((node (make-symbols-outline-node :name (symbols-outline-lsp--get-item "name" symbol) :kind (symbols-outline-lsp--kind-name (symbols-outline-lsp--get-item "kind" symbol)) :line (1+ (symbols-outline-lsp--get-item "line" (symbols-outline-lsp--get-item "start" (symbols-outline-lsp--get-item "range" symbol)))) :signature (symbols-outline-lsp--get-item "detail" symbol) :parent tree)) (ht-children (symbols-outline-lsp--get-item "children" symbol))) (progn (or (progn (and (memq (type-of tree) cl-struct-symbols-outline-node-tags) t)) (signal 'wrong-type-argument (list 'symbols-outline-node tree))) (let* ((v tree)) (aset v 6 (cons node (aref v 6))))) (if (length> ht-children 0) (progn (symbols-outline-lsp--convert-internal ht-children node))))
  (closure ((tree . #s(symbols-outline-node :name nil :kind nil :line nil :signature nil :parent nil :children nil :collapsed nil :ov nil))) (symbol) (let ((node (make-symbols-outline-node :name (symbols-outline-lsp--get-item "name" symbol) :kind (symbols-outline-lsp--kind-name (symbols-outline-lsp--get-item "kind" symbol)) :line (1+ (symbols-outline-lsp--get-item "line" (symbols-outline-lsp--get-item "start" (symbols-outline-lsp--get-item "range" symbol)))) :signature (symbols-outline-lsp--get-item "detail" symbol) :parent tree)) (ht-children (symbols-outline-lsp--get-item "children" symbol))) (progn (or (progn (and (memq (type-of tree) cl-struct-symbols-outline-node-tags) t)) (signal 'wrong-type-argument (list 'symbols-outline-node tree))) (let* ((v tree)) (aset v 6 (cons node (aref v 6))))) (if (length> ht-children 0) (progn (symbols-outline-lsp--convert-internal ht-children node)))))((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2))))
  mapc((closure ((tree . #s(symbols-outline-node :name nil :kind nil :line nil :signature nil :parent nil :children nil :collapsed nil :ov nil))) (symbol) (let ((node (make-symbols-outline-node :name (symbols-outline-lsp--get-item "name" symbol) :kind (symbols-outline-lsp--kind-name (symbols-outline-lsp--get-item "kind" symbol)) :line (1+ (symbols-outline-lsp--get-item "line" (symbols-outline-lsp--get-item "start" (symbols-outline-lsp--get-item "range" symbol)))) :signature (symbols-outline-lsp--get-item "detail" symbol) :parent tree)) (ht-children (symbols-outline-lsp--get-item "children" symbol))) (progn (or (progn (and (memq (type-of tree) cl-struct-symbols-outline-node-tags) t)) (signal 'wrong-type-argument (list 'symbols-outline-node tree))) (let* ((v tree)) (aset v 6 (cons node (aref v 6))))) (if (length> ht-children 0) (progn (symbols-outline-lsp--convert-internal ht-children node))))) ((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))))
  symbols-outline-lsp--convert-internal(((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))) #s(symbols-outline-node :name nil :kind nil :line nil :signature nil :parent nil :children nil :collapsed nil :ov nil))
  (let ((root (record 'symbols-outline-node nil nil nil nil nil nil nil nil))) (symbols-outline-lsp--convert-internal ht-symbols root) (symbols-outline-node--sort-children root) root)
  symbols-outline-lsp--convert(((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))))
  (funcall refresh-fn (symbols-outline-lsp--convert document-symbols))
  (closure ((refresh-fn . symbols-outline--refresh-tree)) (document-symbols) (funcall refresh-fn (symbols-outline-lsp--convert document-symbols)))(((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))))
  apply((closure ((refresh-fn . symbols-outline--refresh-tree)) (document-symbols) (funcall refresh-fn (symbols-outline-lsp--convert document-symbols))) ((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))))
  #f(compiled-function (&rest args) #<bytecode 0xa309040f1f53d68>)(((:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))))
  #f(compiled-function (result) #<bytecode -0x1a04989e935cb65e>)([(:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))])
  #f(compiled-function (result) #<bytecode 0xaec9a21e9600065>)([(:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))])
  lsp--parser-on-message((:id 20 :jsonrpc "2.0" :result [(:detail "int (int, char **)" :kind 12 :name "main" :range (:end (:character 1 :line 4) :start (:character 0 :line 2)) :selectionRange (:end (:character 8 :line 2) :start (:character 4 :line 2)))]) #s(lsp--workspace :ewoc nil :server-capabilities (:astProvider t :callHierarchyProvider t :clangdInlayHintsProvider t :codeActionProvider (:codeActionKinds ["quickfix" "refactor" "info"]) :compilationDatabase (:automaticReload t) :completionProvider (:resolveProvider nil :triggerCharacters ["." "<" ">" ":" "\"" "/" "*"]) :declarationProvider t :definitionProvider t :documentFormattingProvider t :documentHighlightProvider t :documentLinkProvider (:resolveProvider nil) :documentOnTypeFormattingProvider (:firstTriggerCharacter "\n" :moreTriggerCharacter []) :documentRangeFormattingProvider t :documentSymbolProvider t :executeCommandProvider (:commands ["clangd.applyFix" "clangd.applyTweak"]) :hoverProvider t :implementationProvider t :inlayHintProvider t :memoryUsageProvider t :referencesProvider t :renameProvider (:prepareProvider t) :selectionRangeProvider t :semanticTokensProvider (:full (:delta t) :legend (:tokenModifiers ["declaration" "deprecated" "deduced" "readonly" "static" "abstract" "virtual" "dependentName" "defaultLibrary" "usedAsMutableReference" "functionScope" "classScope" "fileScope" "globalScope"] :tokenTypes ["variable" "variable" "parameter" "function" "method" "function" "property" "variable" "class" "interface" "enum" "enumMember" "type" "type" "unknown" "namespace" "typeParameter" "concept" "type" "macro" "comment"]) :range nil) :signatureHelpProvider (:triggerCharacters ["(" ")" "{" "}" "<" ">" ","]) :standardTypeHierarchyProvider t :textDocumentSync (:change 2 :openClose t :save t) :typeDefinitionProvider t :typeHierarchyProvider t :workspaceSymbolProvider t) :registered-server-capabilities nil :root "/tmp" :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode -0x2f4f5849b946063>) :test? #f(compiled-function () #<bytecode 0x19ab3fd655b3>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x1586336cfe97> :request-handlers #<hash-table equal 0/65 0x1586336cffbd> :response-handlers #<hash-table eql 0/65 0x1586336d03b7> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x1586336d03d7> :action-handlers #<hash-table equal 0/65 0x1586336d0a33> :major-modes nil :activation-fn #f(compiled-function (file-name mode) #<bytecode 0x9fc0d5e88af29cd>) :priority -1 :server-id clangd :multi-root nil :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn #f(compiled-function (workspace) #<bytecode -0x47e1d77e7203378>) :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x1586336d0d31> :download-server-fn #f(compiled-function (client callback error-callback update?) #<bytecode -0x15a151c4e6d160c7>) :download-in-progress? nil :buffers nil :synchronize-sections nil) :host-root nil :proc #<user-ptr ptr=0x5618d1c43a00 finalizer=0x5618ca0c0c80> :cmd-proc #<user-ptr ptr=0x5618d1c43a00 finalizer=0x5618ca0c0c80> :buffers (#<buffer sample.c>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x1586335f232d> :watches #<hash-table equal 0/65 0x158633c6f443> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x158633c6f463> :work-done-tokens #<hash-table equal 0/65 0x158633ff354f>))
  #f(compiled-function () #<bytecode 0x48ae690239d98ee>)()
  apply(#f(compiled-function () #<bytecode 0x48ae690239d98ee>) nil)
  timer-event-handler([t 25829 53996 675138 nil #f(compiled-function () #<bytecode 0x48ae690239d98ee>) nil nil 807000 nil])
liushihao456 commented 1 year ago

Thanks for your feedback. Sorry about the rash commit. Your issue is due to the fact that in the plist version the entries are accessed with for example :range instead of "range". Could you try the latest update? I've tested on my machine.

noobieebot commented 1 year ago

Thank you, it's working 🚀.