Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finding symbols fails - (wrong-type-argument stringp) #19

Open
bahmanm opened this issue Jun 16, 2021 · 9 comments
Open

finding symbols fails - (wrong-type-argument stringp) #19

bahmanm opened this issue Jun 16, 2021 · 9 comments

Comments

@bahmanm
Copy link

bahmanm commented Jun 16, 2021

hey 👋 running helm-lsp-workspace-symbol or helm-lsp-global-workspace-symbol invariably fails with Error processing message (wrong-type-argument stringp nil). as i type the symbol name.

i'm using emacs-27.2 with helm, projectile and company. what could i be missing?

here's a sample backtrace. i didn't find a way to switch to the backtrace window w/o it being cleared by helm; hence the screenshot:

Screen Shot 2021-06-16 at 12 24 02 PM

@yyoncho
Copy link
Member

yyoncho commented Jun 16, 2021

I need the logs from client/server. Check lsp-mode's bug template for information how to obtain it.

@bahmanm
Copy link
Author

bahmanm commented Jun 17, 2021

i'm working on a not-so-tiny workspace and enabling the logs generates hundreds of entries many of which containing information about the under the hood implementation of the corporate code base 😞

so i decided to try and track it down myself. here's what i could understand:

;;;;; helm-lsp.el

(defun helm-lsp--workspace-symbol (workspaces name input)
  "Search against WORKSPACES NAME with default INPUT."
  (setq helm-lsp-symbols-result nil)
  (if workspaces
      (with-lsp-workspaces workspaces
        (helm
         :sources
         (helm-build-sync-source
             name
           :candidates (lambda () ...)  ;; [1]
;;;;; helm.el

(defun helm-fuzzy-matching-default-sort-fn-1 (candidates &optional use-real basename preserve-tie-order)
  ...
                     (data1 (or (gethash cand1 table-scr)
                                (puthash cand1
                                         (list (helm-score-candidate-for-pattern  ;; [2]
                                                cand1 helm-pattern)
                                               (length (helm-stringify cand1)))
                                         table-scr)))
...

(defun helm-score-candidate-for-pattern (candidate pattern)
  ...
  (let* ((cand (if (stringp candidate)
                   candidate (helm-stringify candidate))) ;; [3]
;;;;; helm-lib.el

(defun helm-stringify (elm)  ;; [4] 
    (string elm)
    (number (number-to-string elm))
    (symbol (symbol-name elm))))
  1. produces a list of hashtables
  2. tries to score each hashtable
  3. callls helm-stringify on each hashtable
  4. returns nil for a hashtable

later on, when helm-score-candidate-for-pattern tries to use that nil to calculate the score (bonus2) things fail.

what do you think? makes sense?

@yyoncho
Copy link
Member

yyoncho commented Jun 17, 2021

I saw that in the callstack - what I cannot figure out is what is the value that causes that behavior.

@bahmanm
Copy link
Author

bahmanm commented Jun 17, 2021

ok. i found a non-sensitive log i can share. does this help?

[Trace - 01:48:49 pm] Sending request 'workspace/symbol - (132)'.
Params: {
  "query": "BinaryLog"
}


[Trace - 01:48:49 pm] Received notification 'window/logMessage'.
Params: {
  "message": "Jun. 17, 2021, 1:48:49 p.m. >> workspace/symbol",
  "type": 3
}


[Trace - 01:48:49 pm] Received response 'workspace/symbol - (132)' in 46ms.
Result: [
  {
    "containerName": "com.github.shyiko.mysql.binlog.jmx",
    "location": {
      "range": {
        "end": {
          "character": 0,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "uri": "jdt://contents/my-project-java-0.25.1.jar/com.github.shyiko.mysql.binlog.jmx/BinaryLogClientStatisticsMXBean.class?=databus-binlog-publisher/%5C/Users%5C/myuser%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/com.zendesk%5C/my-project-java%5C/0.25.1%5C/43fbc4801a821f4d78f784e8bbfc7f9cb0ae8eaa%5C/my-project-java-0.25.1.jar=/gradle_used_by_scope=/integrationTest,main,mockServer,test,testBuilder=/%3Ccom.github.shyiko.mysql.binlog.jmx(BinaryLogClientStatisticsMXBean.class"
    },
    "kind": 11,
    "name": "BinaryLogClientStatisticsMXBean"
  },
  {
    "containerName": "com.github.shyiko.mysql.binlog.jmx",
    "location": {
      "range": {
        "end": {
          "character": 0,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "uri": "jdt://contents/my-project-java-0.25.1.jar/com.github.shyiko.mysql.binlog.jmx/BinaryLogClientMXBean.class?=databus-binlog-publisher/%5C/Users%5C/myuser%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/com.zendesk%5C/my-project-java%5C/0.25.1%5C/43fbc4801a821f4d78f784e8bbfc7f9cb0ae8eaa%5C/my-project-java-0.25.1.jar=/gradle_used_by_scope=/integrationTest,main,mockServer,test,testBuilder=/%3Ccom.github.shyiko.mysql.binlog.jmx(BinaryLogClientMXBean.class"
    },
    "kind": 11,
    "name": "BinaryLogClientMXBean"
  },
  {
    "containerName": "com.github.shyiko.mysql.binlog",
    "location": {
      "range": {
        "end": {
          "character": 0,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "uri": "jdt://contents/my-project-java-0.25.1.jar/com.github.shyiko.mysql.binlog/BinaryLogFileReader.class?=databus-binlog-publisher/%5C/Users%5C/myuser%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/com.zendesk%5C/my-project-java%5C/0.25.1%5C/43fbc4801a821f4d78f784e8bbfc7f9cb0ae8eaa%5C/my-project-java-0.25.1.jar=/gradle_used_by_scope=/integrationTest,main,mockServer,test,testBuilder=/%3Ccom.github.shyiko.mysql.binlog(BinaryLogFileReader.class"
    },
    "kind": 5,
    "name": "BinaryLogFileReader"
  },
  {
    "containerName": "com.github.shyiko.mysql.binlog.jmx",
    "location": {
      "range": {
        "end": {
          "character": 0,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "uri": "jdt://contents/my-project-java-0.25.1.jar/com.github.shyiko.mysql.binlog.jmx/BinaryLogClientStatistics.class?=databus-binlog-publisher/%5C/Users%5C/myuser%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/com.zendesk%5C/my-project-java%5C/0.25.1%5C/43fbc4801a821f4d78f784e8bbfc7f9cb0ae8eaa%5C/my-project-java-0.25.1.jar=/gradle_used_by_scope=/integrationTest,main,mockServer,test,testBuilder=/%3Ccom.github.shyiko.mysql.binlog.jmx(BinaryLogClientStatistics.class"
    },
    "kind": 5,
    "name": "BinaryLogClientStatistics"
  },
  {
    "containerName": "com.github.shyiko.mysql.binlog",
    "location": {
      "range": {
        "end": {
          "character": 0,
          "line": 0
        },
        "start": {
          "character": 0,
          "line": 0
        }
      },
      "uri": "jdt://contents/my-project-java-0.25.1.jar/com.github.shyiko.mysql.binlog/BinaryLogClient.class?=databus-binlog-publisher/%5C/Users%5C/myuser%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/com.zendesk%5C/my-project-java%5C/0.25.1%5C/43fbc4801a821f4d78f784e8bbfc7f9cb0ae8eaa%5C/my-project-java-0.25.1.jar=/gradle_used_by_scope=/integrationTest,main,mockServer,test,testBuilder=/%3Ccom.github.shyiko.mysql.binlog(BinaryLogClient.class"
    },
    "kind": 5,
    "name": "BinaryLogClient"
  }
]  

@huangfeiyu
Copy link

I encountered the same issue.

@malb
Copy link

malb commented Aug 26, 2021

FWIW, disabling fuzzy searching makes it work for me:

; :fuzzy-match t

@huangfeiyu
Copy link

@malb where to disable "fuzzy searching"? Can you please elaborate it? Thanks!

@malb
Copy link

malb commented Aug 27, 2021

I just commented out the line reading :fuzzy-match t in the function helm-lsp--workspace-symbol like this:

(defun helm-lsp--workspace-symbol (workspaces name input)
  "Search against WORKSPACES NAME with default INPUT."
  (setq helm-lsp-symbols-result nil)
  (if workspaces
      (with-lsp-workspaces workspaces
        (helm
         :sources
         (helm-build-sync-source
             name
           :candidates (lambda ()
                         (if helm-lsp-symbols-result-p
                             helm-lsp-symbols-result
                           (with-lsp-workspaces workspaces
                             (-let (((request &as &plist :id request-id) ))
                               (setq helm-lsp-symbols-request-id request-id)
                               (lsp-request-async
                                "workspace/symbol"
                                (list :query helm-pattern)
                                (lambda (candidates)
                                  (setq helm-lsp-symbols-request-id nil)
                                  (and helm-alive-p
                                       (let ((helm-lsp-symbols-result-p t))
                                         (setq helm-lsp-symbols-result candidates)
                                         (helm-update))))
                                :mode 'detached
                                :cancel-token :workspace-symbols)
                               helm-lsp-symbols-result))))
           :action 'helm-lsp-workspace-symbol-action
           :volatile t
           ;; :fuzzy-match t
           :match (-const t)
           :keymap helm-map
           :candidate-transformer
           (lambda (candidates)
             (-map
              (-lambda ((candidate &as
                                   &SymbolInformation :container-name? :name :kind :location (&Location :uri)))
                (let ((type (or (alist-get kind lsp-symbol-kinds) "Unknown")))
                  (cons
                   (if (and (featurep 'lsp-treemacs)
                            helm-lsp-treemacs-icons)
                       (concat
                        (or (helm-lsp--get-icon kind)
                            (helm-lsp--get-icon 'fallback))
                        (if (s-blank? container-name?)
                            name
                          (concat name " " (propertize container-name? 'face 'helm-lsp-container-face)))
                        (propertize " · " 'face 'success)
                        (helm-lsp--extract-file-name uri))
                     (concat (if (s-blank? container-name?)
                                 name
                               (concat name " " (propertize container-name? 'face 'helm-lsp-container-face) " -" ))
                             " "
                             (propertize (concat "(" type ")") 'face 'font-lock-type-face)
                             (propertize " · " 'face 'success)
                             (helm-lsp--extract-file-name uri)))
                   candidate)))
              (-take helm-candidate-number-limit candidates)))
           :candidate-number-limit nil
           :requires-pattern 0)
         :input input))
    (user-error "No LSP workspace active")))

Neither right nor elegant but I can use it while this is getting fixed.

@huangfeiyu
Copy link

@malb it doesn't work for me. issue still exists. Thank you anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants